From b0115ba25424f16056a7cf8eae21612efe656d80 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Mon, 18 Dec 2023 15:41:10 +0200 Subject: [PATCH] Move EVM `EVMDomainExecutorDispatch` from `subspace-node` to `evm-domain-runtime` for better reuse --- Cargo.lock | 1 + .../src/malicious_domain_instance_starter.rs | 5 ++--- crates/subspace-node/src/bin/subspace-node.rs | 5 ++--- crates/subspace-node/src/domain.rs | 19 ------------------ .../src/domain/domain_instance_starter.rs | 3 ++- domains/runtime/evm/Cargo.toml | 2 ++ domains/runtime/evm/src/lib.rs | 20 +++++++++++++++++++ 7 files changed, 29 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c5cc81039..e2ed35213f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3281,6 +3281,7 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api", "pallet-transporter", "parity-scale-codec", + "sc-executor", "scale-info", "sp-api", "sp-block-builder", diff --git a/crates/subspace-malicious-operator/src/malicious_domain_instance_starter.rs b/crates/subspace-malicious-operator/src/malicious_domain_instance_starter.rs index 501f70b82c..9fbdf9eefa 100644 --- a/crates/subspace-malicious-operator/src/malicious_domain_instance_starter.rs +++ b/crates/subspace-malicious-operator/src/malicious_domain_instance_starter.rs @@ -5,6 +5,7 @@ use domain_eth_service::provider::EthProvider; use domain_eth_service::DefaultEthConfig; use domain_runtime_primitives::opaque::Block as DomainBlock; use domain_service::{FullBackend, FullClient}; +use evm_domain_runtime::ExecutorDispatch as EVMDomainExecutorDispatch; use futures::StreamExt; use sc_cli::CliConfiguration; use sc_consensus_subspace::block_import::BlockImportingNotification; @@ -18,9 +19,7 @@ use sp_core::traits::SpawnEssentialNamed; use sp_domains::{DomainInstanceData, RuntimeType}; use sp_keystore::KeystorePtr; use std::sync::Arc; -use subspace_node::domain::{ - create_configuration, evm_chain_spec, AccountId20, DomainCli, EVMDomainExecutorDispatch, -}; +use subspace_node::domain::{create_configuration, evm_chain_spec, AccountId20, DomainCli}; use subspace_runtime::{ExecutorDispatch as CExecutorDispatch, RuntimeApi as CRuntimeApi}; use subspace_runtime_primitives::opaque::Block as CBlock; use subspace_service::FullClient as CFullClient; diff --git a/crates/subspace-node/src/bin/subspace-node.rs b/crates/subspace-node/src/bin/subspace-node.rs index 0f822a60f7..f2419d1051 100644 --- a/crates/subspace-node/src/bin/subspace-node.rs +++ b/crates/subspace-node/src/bin/subspace-node.rs @@ -22,6 +22,7 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; use cross_domain_message_gossip::GossipWorkerBuilder; use domain_client_operator::Bootstrapper; use domain_runtime_primitives::opaque::Block as DomainBlock; +use evm_domain_runtime::ExecutorDispatch as EVMDomainExecutorDispatch; use frame_benchmarking_cli::BenchmarkCmd; use futures::future::TryFutureExt; use log::warn; @@ -37,9 +38,7 @@ use sp_core::traits::SpawnEssentialNamed; use sp_io::SubstrateHostFunctions; use sp_messenger::messages::ChainId; use sp_wasm_interface::ExtendedHostFunctions; -use subspace_node::domain::{ - DomainCli, DomainInstanceStarter, DomainSubcommand, EVMDomainExecutorDispatch, -}; +use subspace_node::domain::{DomainCli, DomainInstanceStarter, DomainSubcommand}; use subspace_node::{Cli, Subcommand}; use subspace_proof_of_space::chia::ChiaTable; use subspace_runtime::{Block, ExecutorDispatch, RuntimeApi}; diff --git a/crates/subspace-node/src/domain.rs b/crates/subspace-node/src/domain.rs index 2ff56d9b83..974b128ef1 100644 --- a/crates/subspace-node/src/domain.rs +++ b/crates/subspace-node/src/domain.rs @@ -21,22 +21,3 @@ pub mod evm_chain_spec; pub use self::cli::{DomainCli, Subcommand as DomainSubcommand}; pub use self::domain_instance_starter::{create_configuration, DomainInstanceStarter}; pub use evm_domain_runtime::AccountId as AccountId20; -use sc_executor::NativeExecutionDispatch; - -/// EVM domain executor instance. -pub struct EVMDomainExecutorDispatch; - -impl NativeExecutionDispatch for EVMDomainExecutorDispatch { - #[cfg(feature = "runtime-benchmarks")] - type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; - #[cfg(not(feature = "runtime-benchmarks"))] - type ExtendHostFunctions = (); - - fn dispatch(method: &str, data: &[u8]) -> Option> { - evm_domain_runtime::api::dispatch(method, data) - } - - fn native_version() -> sc_executor::NativeVersion { - evm_domain_runtime::native_version() - } -} diff --git a/crates/subspace-node/src/domain/domain_instance_starter.rs b/crates/subspace-node/src/domain/domain_instance_starter.rs index b70e419be9..1103b497fe 100644 --- a/crates/subspace-node/src/domain/domain_instance_starter.rs +++ b/crates/subspace-node/src/domain/domain_instance_starter.rs @@ -1,11 +1,12 @@ use super::{evm_chain_spec, DomainCli}; -use crate::domain::{AccountId20, EVMDomainExecutorDispatch}; +use crate::domain::AccountId20; use cross_domain_message_gossip::{ChainTxPoolMsg, Message}; use domain_client_operator::{BootstrapResult, OperatorStreams}; use domain_eth_service::provider::EthProvider; use domain_eth_service::DefaultEthConfig; use domain_runtime_primitives::opaque::Block as DomainBlock; use domain_service::{FullBackend, FullClient}; +use evm_domain_runtime::ExecutorDispatch as EVMDomainExecutorDispatch; use futures::StreamExt; use sc_chain_spec::ChainSpec; use sc_cli::{CliConfiguration, Database, DefaultConfigurationValues, SubstrateCli}; diff --git a/domains/runtime/evm/Cargo.toml b/domains/runtime/evm/Cargo.toml index c64b7637d7..8ff2878f32 100644 --- a/domains/runtime/evm/Cargo.toml +++ b/domains/runtime/evm/Cargo.toml @@ -45,6 +45,7 @@ pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, pallet-transaction-payment-rpc-runtime-api = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "0831dfc3c54b10ab46e82acf98603b4af1a47bd5" } pallet-transporter = { version = "0.1.0", path = "../../pallets/transporter", default-features = false } scale-info = { version = "2.7.0", default-features = false, features = ["derive"] } +sc-executor = { version = "0.10.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "0831dfc3c54b10ab46e82acf98603b4af1a47bd5", optional = true } sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "0831dfc3c54b10ab46e82acf98603b4af1a47bd5" } sp-block-builder = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "0831dfc3c54b10ab46e82acf98603b4af1a47bd5" } sp-core = { version = "21.0.0", default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "0831dfc3c54b10ab46e82acf98603b4af1a47bd5" } @@ -98,6 +99,7 @@ std = [ "pallet-transaction-payment/std", "pallet-transporter/std", "scale-info/std", + "sc-executor", "sp-api/std", "sp-block-builder/std", "sp-core/std", diff --git a/domains/runtime/evm/src/lib.rs b/domains/runtime/evm/src/lib.rs index 7ed4eb84c8..5d54e09c7d 100644 --- a/domains/runtime/evm/src/lib.rs +++ b/domains/runtime/evm/src/lib.rs @@ -220,6 +220,26 @@ pub fn native_version() -> NativeVersion { } } +/// EVM domain executor instance. +#[cfg(feature = "std")] +pub struct ExecutorDispatch; + +#[cfg(feature = "std")] +impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { + #[cfg(feature = "runtime-benchmarks")] + type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; + #[cfg(not(feature = "runtime-benchmarks"))] + type ExtendHostFunctions = (); + + fn dispatch(method: &str, data: &[u8]) -> Option> { + api::dispatch(method, data) + } + + fn native_version() -> sc_executor::NativeVersion { + native_version() + } +} + parameter_types! { pub const Version: RuntimeVersion = VERSION; pub const BlockHashCount: BlockNumber = 2400;