From 005a8269ec39c5f78e153f280227e05a53e449ea Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Mon, 18 Dec 2023 14:31:37 +0200 Subject: [PATCH 1/4] Add farm locking, preventing multiple farmers from using the same farm concurrently that leads to slashing and other issues --- Cargo.lock | 15 +++++++-- crates/subspace-farmer/Cargo.toml | 1 + .../subspace-farmer/src/single_disk_farm.rs | 31 ++++++++++++++++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e0a72be32..514cb40929 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4089,6 +4089,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "fs4" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29f9df8a11882c4e3335eb2d18a0137c505d9ca927470b0cac9c6f0ae07d28f7" +dependencies = [ + "rustix 0.38.13", + "windows-sys 0.48.0", +] + [[package]] name = "funty" version = "2.0.0" @@ -9957,7 +9967,7 @@ version = "0.1.0" source = "git+https://github.com/subspace/polkadot-sdk?rev=0831dfc3c54b10ab46e82acf98603b4af1a47bd5#0831dfc3c54b10ab46e82acf98603b4af1a47bd5" dependencies = [ "clap", - "fs4", + "fs4 0.6.6", "log", "sc-client-db", "sp-core", @@ -11691,6 +11701,7 @@ dependencies = [ "derive_more", "event-listener-primitives", "fdlimit", + "fs4 0.7.0", "futures", "hex", "jsonrpsee", @@ -13014,7 +13025,7 @@ checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if", "digest 0.10.7", - "rand 0.7.3", + "rand 0.8.5", "static_assertions", ] diff --git a/crates/subspace-farmer/Cargo.toml b/crates/subspace-farmer/Cargo.toml index 4be80afb56..d9e1131ef2 100644 --- a/crates/subspace-farmer/Cargo.toml +++ b/crates/subspace-farmer/Cargo.toml @@ -25,6 +25,7 @@ criterion = { version = "0.5.1", default-features = false, features = ["rayon", derive_more = "0.99.17" event-listener-primitives = "2.0.1" fdlimit = "0.3.0" +fs4 = "0.7.0" futures = "0.3.29" hex = { version = "0.4.3", features = ["serde"] } jsonrpsee = { version = "0.16.3", features = ["client"] } diff --git a/crates/subspace-farmer/src/single_disk_farm.rs b/crates/subspace-farmer/src/single_disk_farm.rs index 0204cf5976..f629b4b6c5 100644 --- a/crates/subspace-farmer/src/single_disk_farm.rs +++ b/crates/subspace-farmer/src/single_disk_farm.rs @@ -88,6 +88,12 @@ impl SingleDiskFarmId { } } +/// Exclusive lock for single disk farm info file, ensuring no concurrent edits by cooperating processes is done +#[must_use = "Lock file must be kept around or as long as farm is used"] +pub struct SingleDiskFarmInfoLock { + _file: File, +} + /// Important information about the contents of the `SingleDiskFarm` #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -162,6 +168,15 @@ impl SingleDiskFarmInfo { ) } + /// Try to acquire exclusive lock on the single disk farm info file, ensuring no concurrent edits by cooperating + /// processes is done + pub fn try_lock(directory: &Path) -> io::Result { + let file = File::open(directory.join(Self::FILE_NAME))?; + fs4::FileExt::try_lock_exclusive(&file)?; + + Ok(SingleDiskFarmInfoLock { _file: file }) + } + // ID of the farm pub fn id(&self) -> &SingleDiskFarmId { let Self::V0 { id, .. } = self; @@ -287,6 +302,9 @@ pub enum SingleDiskFarmError { /// Failed to open or create identity #[error("Failed to open or create identity: {0}")] FailedToOpenIdentity(#[from] IdentityError), + /// Farm is likely already in use, make sure no other farmer is using it + #[error("Farm is likely already in use, make sure no other farmer is using it: {0}")] + LikelyAlreadyInUse(io::Error), // TODO: Make more variants out of this generic one /// I/O error occurred #[error("I/O error: {0}")] @@ -378,6 +396,9 @@ pub enum SingleDiskFarmError { /// Errors happening during scrubbing #[derive(Debug, Error)] pub enum SingleDiskFarmScrubError { + /// Farm is likely already in use, make sure no other farmer is using it + #[error("Farm is likely already in use, make sure no other farmer is using it: {0}")] + LikelyAlreadyInUse(io::Error), /// Failed to determine file size #[error("Failed to file size of {file}: {error}")] FailedToDetermineFileSize { @@ -559,6 +580,7 @@ pub struct SingleDiskFarm { start_sender: Option>, /// Sender that will be used to signal to background threads that they must stop stop_sender: Option>, + _single_disk_farm_info_lock: SingleDiskFarmInfoLock, } impl Drop for SingleDiskFarm { @@ -684,6 +706,9 @@ impl SingleDiskFarm { } }; + let single_disk_farm_info_lock = SingleDiskFarmInfo::try_lock(&directory) + .map_err(SingleDiskFarmError::LikelyAlreadyInUse)?; + let pieces_in_sector = single_disk_farm_info.pieces_in_sector(); let sector_size = sector_size(pieces_in_sector); let sector_metadata_size = SectorMetadataChecksummed::encoded_size(); @@ -745,7 +770,6 @@ impl SingleDiskFarm { } }; - // TODO: Consider file locking to prevent other apps from modifying it let mut metadata_file = OpenOptions::new() .read(true) .write(true) @@ -1195,6 +1219,7 @@ impl SingleDiskFarm { piece_reader, start_sender: Some(start_sender), stop_sender: Some(stop_sender), + _single_disk_farm_info_lock: single_disk_farm_info_lock, }; Ok(farm) @@ -1446,6 +1471,10 @@ impl SingleDiskFarm { } } }; + + let _single_disk_farm_info_lock = SingleDiskFarmInfo::try_lock(directory) + .map_err(SingleDiskFarmScrubError::LikelyAlreadyInUse)?; + let identity = { let file = directory.join(Identity::FILE_NAME); info!(path = %file.display(), "Checking identity file"); From 87b7a05498fb701140aa560e9bcbcb3f24f4dbe7 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Mon, 18 Dec 2023 15:36:01 +0200 Subject: [PATCH 2/4] Move consensus `ExecutorDispatch` from `subspace-node` to `subspace-runtime` for better reuse --- Cargo.lock | 1 + .../src/bin/subspace-malicious-operator.rs | 4 +-- .../src/malicious_domain_instance_starter.rs | 3 +- crates/subspace-node/src/bin/subspace-node.rs | 4 +-- .../src/domain/domain_instance_starter.rs | 3 +- crates/subspace-node/src/lib.rs | 28 ------------------ crates/subspace-runtime/Cargo.toml | 2 ++ crates/subspace-runtime/src/lib.rs | 29 +++++++++++++++++++ 8 files changed, 38 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e0a72be32..0c5cc81039 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11993,6 +11993,7 @@ dependencies = [ "pallet-transporter", "pallet-utility", "parity-scale-codec", + "sc-executor", "scale-info", "sp-api", "sp-block-builder", diff --git a/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs b/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs index 090dc56492..7715f00924 100644 --- a/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs +++ b/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs @@ -34,9 +34,9 @@ use sp_core::traits::SpawnEssentialNamed; use sp_messenger::messages::ChainId; use subspace_malicious_operator::malicious_domain_instance_starter::DomainInstanceStarter; use subspace_node::domain::DomainCli; -use subspace_node::{Cli, ExecutorDispatch}; +use subspace_node::Cli; use subspace_proof_of_space::chia::ChiaTable; -use subspace_runtime::{Block, RuntimeApi}; +use subspace_runtime::{Block, ExecutorDispatch, RuntimeApi}; use subspace_service::{DsnConfig, SubspaceConfiguration, SubspaceNetworking}; type PosTable = ChiaTable; 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 f5a363c936..501f70b82c 100644 --- a/crates/subspace-malicious-operator/src/malicious_domain_instance_starter.rs +++ b/crates/subspace-malicious-operator/src/malicious_domain_instance_starter.rs @@ -21,8 +21,7 @@ use std::sync::Arc; use subspace_node::domain::{ create_configuration, evm_chain_spec, AccountId20, DomainCli, EVMDomainExecutorDispatch, }; -use subspace_node::ExecutorDispatch as CExecutorDispatch; -use subspace_runtime::RuntimeApi as CRuntimeApi; +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 c0b3423342..0f822a60f7 100644 --- a/crates/subspace-node/src/bin/subspace-node.rs +++ b/crates/subspace-node/src/bin/subspace-node.rs @@ -40,9 +40,9 @@ use sp_wasm_interface::ExtendedHostFunctions; use subspace_node::domain::{ DomainCli, DomainInstanceStarter, DomainSubcommand, EVMDomainExecutorDispatch, }; -use subspace_node::{Cli, ExecutorDispatch, Subcommand}; +use subspace_node::{Cli, Subcommand}; use subspace_proof_of_space::chia::ChiaTable; -use subspace_runtime::{Block, RuntimeApi}; +use subspace_runtime::{Block, ExecutorDispatch, RuntimeApi}; use subspace_service::{DsnConfig, SubspaceConfiguration, SubspaceNetworking}; type PosTable = ChiaTable; diff --git a/crates/subspace-node/src/domain/domain_instance_starter.rs b/crates/subspace-node/src/domain/domain_instance_starter.rs index 42ad22d47c..b70e419be9 100644 --- a/crates/subspace-node/src/domain/domain_instance_starter.rs +++ b/crates/subspace-node/src/domain/domain_instance_starter.rs @@ -1,6 +1,5 @@ use super::{evm_chain_spec, DomainCli}; use crate::domain::{AccountId20, EVMDomainExecutorDispatch}; -use crate::ExecutorDispatch as CExecutorDispatch; use cross_domain_message_gossip::{ChainTxPoolMsg, Message}; use domain_client_operator::{BootstrapResult, OperatorStreams}; use domain_eth_service::provider::EthProvider; @@ -19,7 +18,7 @@ use sc_transaction_pool_api::OffchainTransactionPoolFactory; use sc_utils::mpsc::{TracingUnboundedReceiver, TracingUnboundedSender}; use sp_domains::{DomainInstanceData, RuntimeType}; use std::sync::Arc; -use subspace_runtime::RuntimeApi as CRuntimeApi; +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/lib.rs b/crates/subspace-node/src/lib.rs index 71b7e58c2a..e79f634b29 100644 --- a/crates/subspace-node/src/lib.rs +++ b/crates/subspace-node/src/lib.rs @@ -22,7 +22,6 @@ pub mod domain; use clap::Parser; use sc_cli::{RunCmd, SubstrateCli}; -use sc_executor::NativeExecutionDispatch; use sc_service::ChainSpec; use sc_storage_monitor::StorageMonitorParams; use sc_subspace_chain_specs::ConsensusChainSpec; @@ -33,33 +32,6 @@ use std::io::Write; use std::{fs, io}; use subspace_networking::libp2p::Multiaddr; -/// Executor dispatch for subspace runtime -pub struct ExecutorDispatch; - -impl NativeExecutionDispatch for ExecutorDispatch { - /// Only enable the benchmarking host functions when we actually want to benchmark. - #[cfg(feature = "runtime-benchmarks")] - type ExtendHostFunctions = ( - frame_benchmarking::benchmarking::HostFunctions, - sp_consensus_subspace::consensus::HostFunctions, - sp_domains_fraud_proof::HostFunctions, - ); - /// Otherwise we only use the default Substrate host functions. - #[cfg(not(feature = "runtime-benchmarks"))] - type ExtendHostFunctions = ( - sp_consensus_subspace::consensus::HostFunctions, - sp_domains_fraud_proof::HostFunctions, - ); - - fn dispatch(method: &str, data: &[u8]) -> Option> { - subspace_runtime::api::dispatch(method, data) - } - - fn native_version() -> sc_executor::NativeVersion { - subspace_runtime::native_version() - } -} - /// This `purge-chain` command used to remove both consensus chain and domain. #[derive(Debug, Clone, Parser)] #[group(skip)] diff --git a/crates/subspace-runtime/Cargo.toml b/crates/subspace-runtime/Cargo.toml index c9fd8ff07c..0174ab107c 100644 --- a/crates/subspace-runtime/Cargo.toml +++ b/crates/subspace-runtime/Cargo.toml @@ -40,6 +40,7 @@ pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-fe pallet-transporter = { version = "0.1.0", path = "../../domains/pallets/transporter", default-features = false } pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "0831dfc3c54b10ab46e82acf98603b4af1a47bd5" } 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 = { git = "https://github.com/subspace/polkadot-sdk", rev = "0831dfc3c54b10ab46e82acf98603b4af1a47bd5", default-features = false, version = "4.0.0-dev" } sp-consensus-subspace = { version = "0.1.0", default-features = false, path = "../sp-consensus-subspace" } @@ -95,6 +96,7 @@ std = [ "pallet-transporter/std", "pallet-utility/std", "scale-info/std", + "sc-executor", "sp-api/std", "sp-block-builder/std", "sp-consensus-subspace/std", diff --git a/crates/subspace-runtime/src/lib.rs b/crates/subspace-runtime/src/lib.rs index e43cf820dc..db9a18802f 100644 --- a/crates/subspace-runtime/src/lib.rs +++ b/crates/subspace-runtime/src/lib.rs @@ -119,6 +119,35 @@ pub fn native_version() -> NativeVersion { } } +/// Executor dispatch for subspace runtime +#[cfg(feature = "std")] +pub struct ExecutorDispatch; + +#[cfg(feature = "std")] +impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { + /// Only enable the benchmarking host functions when we actually want to benchmark. + #[cfg(feature = "runtime-benchmarks")] + type ExtendHostFunctions = ( + frame_benchmarking::benchmarking::HostFunctions, + sp_consensus_subspace::consensus::HostFunctions, + sp_domains_fraud_proof::HostFunctions, + ); + /// Otherwise we only use the default Substrate host functions. + #[cfg(not(feature = "runtime-benchmarks"))] + type ExtendHostFunctions = ( + sp_consensus_subspace::consensus::HostFunctions, + sp_domains_fraud_proof::HostFunctions, + ); + + fn dispatch(method: &str, data: &[u8]) -> Option> { + api::dispatch(method, data) + } + + fn native_version() -> sc_executor::NativeVersion { + native_version() + } +} + // TODO: Many of below constants should probably be updatable but currently they are not /// Since Subspace is probabilistic this is the average expected block time that From b0115ba25424f16056a7cf8eae21612efe656d80 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Mon, 18 Dec 2023 15:41:10 +0200 Subject: [PATCH 3/4] 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; From 3ada7ddc90353f1bbd7d90ca40074c720391063d Mon Sep 17 00:00:00 2001 From: Parth Desai Date: Mon, 18 Dec 2023 18:36:02 +0400 Subject: [PATCH 4/4] return `MandatoryValidation` error instead of `BadMandatory` --- domains/runtime/evm/src/lib.rs | 2 +- domains/test/runtime/evm/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/domains/runtime/evm/src/lib.rs b/domains/runtime/evm/src/lib.rs index 7ed4eb84c8..effc2e6897 100644 --- a/domains/runtime/evm/src/lib.rs +++ b/domains/runtime/evm/src/lib.rs @@ -914,7 +914,7 @@ impl_runtime_apis! { let dispatch_info = xt.get_dispatch_info(); if dispatch_info.class == DispatchClass::Mandatory { - return Err(InvalidTransaction::BadMandatory.into()); + return Err(InvalidTransaction::MandatoryValidation.into()); } let encoded_len = uxt.encoded_size(); diff --git a/domains/test/runtime/evm/src/lib.rs b/domains/test/runtime/evm/src/lib.rs index d4f6c72fa2..afd4359e0a 100644 --- a/domains/test/runtime/evm/src/lib.rs +++ b/domains/test/runtime/evm/src/lib.rs @@ -897,7 +897,7 @@ impl_runtime_apis! { let dispatch_info = xt.get_dispatch_info(); if dispatch_info.class == DispatchClass::Mandatory { - return Err(InvalidTransaction::BadMandatory.into()); + return Err(InvalidTransaction::MandatoryValidation.into()); } let encoded_len = uxt.encoded_size();