diff --git a/Cargo.lock b/Cargo.lock index 6649786d56..3494f44e65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2715,6 +2715,7 @@ dependencies = [ "sp-transaction-pool", "subspace-core-primitives", "subspace-runtime-primitives", + "subspace-service", "substrate-build-script-utils", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", @@ -12165,6 +12166,7 @@ dependencies = [ "sp-externalities", "sp-inherents", "sp-keyring", + "sp-messenger", "sp-mmr-primitives", "sp-runtime", "sp-subspace-mmr", diff --git a/crates/pallet-domains/src/lib.rs b/crates/pallet-domains/src/lib.rs index 2bbd896126..5d22d770d7 100644 --- a/crates/pallet-domains/src/lib.rs +++ b/crates/pallet-domains/src/lib.rs @@ -343,6 +343,7 @@ mod pallet { /// Starting EVM chain ID for evm runtimes. pub struct StartingEVMChainId; + impl Get for StartingEVMChainId { fn get() -> EVMChainId { // after looking at `https://chainlist.org/?testnets=false` diff --git a/crates/pallet-domains/src/tests.rs b/crates/pallet-domains/src/tests.rs index a723bf6c2d..387395cd2d 100644 --- a/crates/pallet-domains/src/tests.rs +++ b/crates/pallet-domains/src/tests.rs @@ -75,6 +75,7 @@ frame_support::construct_runtime!( type BlockNumber = u64; type Hash = H256; type AccountId = u128; + impl frame_system::Config for Test { type BaseCallFilter = frame_support::traits::Everything; type BlockWeights = (); @@ -116,6 +117,7 @@ parameter_types! { } pub struct ConfirmationDepthK; + impl Get for ConfirmationDepthK { fn get() -> BlockNumber { 10 @@ -193,6 +195,7 @@ impl frame_support::traits::Randomness for MockRandomness { } const SLOT_DURATION: u64 = 1000; + impl pallet_timestamp::Config for Test { /// A timestamp: milliseconds since the unix epoch. type Moment = Moment; @@ -202,6 +205,7 @@ impl pallet_timestamp::Config for Test { } pub struct DummyStorageFee; + impl StorageFee for DummyStorageFee { fn transaction_byte_fee() -> Balance { SSC @@ -210,6 +214,7 @@ impl StorageFee for DummyStorageFee { } pub struct DummyBlockSlot; + impl BlockSlot for DummyBlockSlot { fn current_slot() -> sp_consensus_slots::Slot { 0u64.into() @@ -253,6 +258,7 @@ impl pallet_domains::Config for Test { } pub struct ExtrinsicStorageFees; + impl domain_pallet_executive::ExtrinsicStorageFees for ExtrinsicStorageFees { fn extract_signer(_xt: MockUncheckedExtrinsic) -> (Option, DispatchInfo) { (None, DispatchInfo::default()) @@ -385,6 +391,7 @@ impl FraudProofHostFunctions for MockDomainFraudProofExtension { fn execution_proof_check( &self, + _domain_id: (u32, H256), _pre_state_root: H256, _encoded_proof: Vec, _execution_method: &str, diff --git a/crates/sp-domains-fraud-proof/src/host_functions.rs b/crates/sp-domains-fraud-proof/src/host_functions.rs index f010c09b5b..4fb333129e 100644 --- a/crates/sp-domains-fraud-proof/src/host_functions.rs +++ b/crates/sp-domains-fraud-proof/src/host_functions.rs @@ -5,18 +5,22 @@ use codec::{Decode, Encode}; use domain_block_preprocessor::inherents::extract_domain_runtime_upgrade_code; use domain_block_preprocessor::stateless_runtime::StatelessRuntime; use domain_runtime_primitives::{ - CheckExtrinsicsValidityError, CHECK_EXTRINSICS_AND_DO_PRE_DISPATCH_METHOD_NAME, + BlockNumber, CheckExtrinsicsValidityError, CHECK_EXTRINSICS_AND_DO_PRE_DISPATCH_METHOD_NAME, }; +use hash_db::Hasher; +use sc_client_api::execution_extensions::ExtensionsFactory; use sc_client_api::BlockBackend; use sc_executor::RuntimeVersionOf; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; -use sp_core::traits::{CodeExecutor, FetchRuntimeCode, RuntimeCode}; +use sp_core::traits::{CallContext, CodeExecutor, FetchRuntimeCode, RuntimeCode}; use sp_core::H256; use sp_domains::bundle_producer_election::BundleProducerElectionParams; use sp_domains::{BundleProducerElectionApi, DomainId, DomainsApi, OperatorId}; -use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT}; +use sp_externalities::Extensions; +use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, NumberFor}; use sp_runtime::OpaqueExtrinsic; +use sp_state_machine::{create_proof_check_backend, Error, OverlayedChanges, StateMachine}; use sp_std::vec::Vec; use sp_trie::StorageProof; use std::borrow::Cow; @@ -53,6 +57,7 @@ pub trait FraudProofHostFunctions: Send + Sync { /// Check the execution proof fn execution_proof_check( &self, + domain_block_id: (BlockNumber, H256), pre_state_root: H256, // TODO: implement `PassBy` for `sp_trie::StorageProof` in upstream to pass it directly here encoded_proof: Vec, @@ -78,16 +83,22 @@ impl FraudProofExtension { pub struct FraudProofHostFunctionsImpl { consensus_client: Arc, executor: Arc, + domain_extensions_factory: Box>, _phantom: PhantomData<(Block, DomainBlock)>, } impl FraudProofHostFunctionsImpl { - pub fn new(consensus_client: Arc, executor: Arc) -> Self { + pub fn new( + consensus_client: Arc, + executor: Arc, + domain_extensions_factory: Box>, + ) -> Self { FraudProofHostFunctionsImpl { consensus_client, executor, + domain_extensions_factory, _phantom: Default::default(), } } @@ -327,7 +338,7 @@ where &self, consensus_block_hash: H256, domain_id: DomainId, - domain_block_id: (u32, H256), + domain_block_id: (BlockNumber, H256), domain_block_state_root: H256, bundle_extrinsics: Vec, storage_proof: StorageProof, @@ -337,6 +348,7 @@ where let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?; let raw_response = self.execution_proof_check( + domain_block_id, domain_block_state_root, storage_proof.encode(), CHECK_EXTRINSICS_AND_DO_PRE_DISPATCH_METHOD_NAME, @@ -362,6 +374,7 @@ where Block::Hash: From, DomainBlock: BlockT, DomainBlock::Hash: From + Into, + NumberFor: From, Client: BlockBackend + HeaderBackend + ProvideRuntimeApi, Client::Api: DomainsApi + BundleProducerElectionApi, Executor: CodeExecutor + RuntimeVersionOf, @@ -516,6 +529,7 @@ where fn execution_proof_check( &self, + domain_block_id: (BlockNumber, H256), pre_state_root: H256, encoded_proof: Vec, execution_method: &str, @@ -532,7 +546,12 @@ where heap_pages: None, }; - sp_state_machine::execution_proof_check::<::Hashing, _>( + let (domain_block_number, domain_block_hash) = domain_block_id; + let mut domain_extensions = self + .domain_extensions_factory + .extensions_for(domain_block_hash.into(), domain_block_number.into()); + + execution_proof_check::<::Hashing, _>( pre_state_root.into(), proof, &mut Default::default(), @@ -540,7 +559,42 @@ where execution_method, call_data, &runtime_code, + &mut domain_extensions, ) .ok() } } + +#[allow(clippy::too_many_arguments)] +/// Executes the given proof using the runtime +/// The only difference between sp_state_machine::execution_proof_check is Extensions +pub(crate) fn execution_proof_check( + root: H::Out, + proof: StorageProof, + overlay: &mut OverlayedChanges, + exec: &Exec, + method: &str, + call_data: &[u8], + runtime_code: &RuntimeCode, + extensions: &mut Extensions, +) -> Result, Box> +where + H: Hasher, + H::Out: Ord + 'static + codec::Codec, + Exec: CodeExecutor + Clone + 'static, +{ + let trie_backend = create_proof_check_backend::(root, proof)?; + let result = StateMachine::<_, H, Exec>::new( + &trie_backend, + overlay, + exec, + method, + call_data, + extensions, + runtime_code, + CallContext::Offchain, + ) + .execute(); + + result +} diff --git a/crates/sp-domains-fraud-proof/src/runtime_interface.rs b/crates/sp-domains-fraud-proof/src/runtime_interface.rs index 8c7823e237..473c497824 100644 --- a/crates/sp-domains-fraud-proof/src/runtime_interface.rs +++ b/crates/sp-domains-fraud-proof/src/runtime_interface.rs @@ -1,6 +1,7 @@ #[cfg(feature = "std")] use crate::FraudProofExtension; use crate::{FraudProofVerificationInfoRequest, FraudProofVerificationInfoResponse}; +use domain_runtime_primitives::BlockNumber; use sp_core::H256; use sp_domains::DomainId; #[cfg(feature = "std")] @@ -38,6 +39,7 @@ pub trait FraudProofRuntimeInterface { /// Check the execution proof fn execution_proof_check( &mut self, + domain_block_id: (BlockNumber, H256), pre_state_root: H256, encoded_proof: Vec, execution_method: &str, @@ -47,6 +49,7 @@ pub trait FraudProofRuntimeInterface { self.extension::() .expect("No `FraudProofExtension` associated for the current context!") .execution_proof_check( + domain_block_id, pre_state_root, encoded_proof, execution_method, diff --git a/crates/sp-domains-fraud-proof/src/verification.rs b/crates/sp-domains-fraud-proof/src/verification.rs index 5a7a8a43d2..388a4f768a 100644 --- a/crates/sp-domains-fraud-proof/src/verification.rs +++ b/crates/sp-domains-fraud-proof/src/verification.rs @@ -8,7 +8,7 @@ use crate::{ FraudProofVerificationInfoResponse, SetCodeExtrinsic, }; use codec::{Decode, Encode}; -use domain_runtime_primitives::BlockFees; +use domain_runtime_primitives::{BlockFees, BlockNumber}; use hash_db::Hasher; use sp_core::storage::StorageKey; use sp_core::H256; @@ -21,7 +21,9 @@ use sp_domains::{ HeaderNumberFor, InboxedBundle, InvalidBundleType, OperatorPublicKey, SealedBundleHeader, }; use sp_runtime::generic::Digest; -use sp_runtime::traits::{Block as BlockT, Hash, Header as HeaderT, NumberFor}; +use sp_runtime::traits::{ + Block as BlockT, Hash, Header as HeaderT, NumberFor, UniqueSaturatedInto, +}; use sp_runtime::{OpaqueExtrinsic, RuntimeAppPublic, SaturatedConversion}; use sp_std::vec::Vec; use sp_trie::{LayoutV1, StorageProof}; @@ -219,6 +221,7 @@ where CBlock::Hash: Into, DomainHeader: HeaderT, DomainHeader::Hash: Into + From, + DomainHeader::Number: UniqueSaturatedInto + From, { let InvalidStateTransitionProof { domain_id, @@ -241,6 +244,10 @@ where .call_data::(&bad_receipt, &bad_receipt_parent)?; let execution_result = fraud_proof_runtime_interface::execution_proof_check( + ( + bad_receipt_parent.domain_block_number.saturated_into(), + bad_receipt_parent.domain_block_hash.into(), + ), pre_state_root, proof.encode(), execution_phase.execution_method(), diff --git a/crates/sp-subspace-mmr/src/host_functions.rs b/crates/sp-subspace-mmr/src/host_functions.rs index e17f205e62..9b88e22d53 100644 --- a/crates/sp-subspace-mmr/src/host_functions.rs +++ b/crates/sp-subspace-mmr/src/host_functions.rs @@ -3,7 +3,7 @@ use codec::Decode; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_core::H256; -use sp_mmr_primitives::{EncodableOpaqueLeaf, MmrApi, Proof}; +pub use sp_mmr_primitives::{EncodableOpaqueLeaf, MmrApi, Proof}; use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor}; use std::marker::PhantomData; use std::sync::Arc; diff --git a/crates/subspace-node/src/main.rs b/crates/subspace-node/src/main.rs index b0785ff29c..d1c38210a8 100644 --- a/crates/subspace-node/src/main.rs +++ b/crates/subspace-node/src/main.rs @@ -28,7 +28,6 @@ use crate::domain::cli::DomainKey; use crate::domain::{DomainCli, DomainSubcommand}; use clap::Parser; use domain_runtime_primitives::opaque::Block as DomainBlock; -use domain_service::HostFunctions as DomainHostFunctions; use frame_benchmarking_cli::BenchmarkCmd; use futures::future::TryFutureExt; use sc_cli::{ChainSpec, SubstrateCli}; @@ -37,6 +36,7 @@ use serde_json::Value; use sp_core::crypto::Ss58AddressFormat; use subspace_proof_of_space::chia::ChiaTable; use subspace_runtime::{Block, RuntimeApi}; +use subspace_service::domains::HostFunctions as DomainHostFunctions; use subspace_service::HostFunctions; use tracing::warn; diff --git a/crates/subspace-service/src/domains.rs b/crates/subspace-service/src/domains.rs new file mode 100644 index 0000000000..f25c2135fc --- /dev/null +++ b/crates/subspace-service/src/domains.rs @@ -0,0 +1,83 @@ +use sc_client_api::execution_extensions::ExtensionsFactory as ExtensionsFactoryT; +use sc_executor::RuntimeVersionOf; +use sp_api::ProvideRuntimeApi; +use sp_blockchain::HeaderBackend; +use sp_core::traits::CodeExecutor; +use sp_core::H256; +use sp_domains::DomainsApi; +use sp_externalities::Extensions; +use sp_messenger_host_functions::{MessengerApi, MessengerExtension, MessengerHostFunctionsImpl}; +use sp_runtime::traits::{Block as BlockT, NumberFor}; +use sp_subspace_mmr::host_functions::{MmrApi, SubspaceMmrExtension, SubspaceMmrHostFunctionsImpl}; +use std::marker::PhantomData; +use std::sync::Arc; + +/// Host functions required for Subspace domain +#[cfg(not(feature = "runtime-benchmarks"))] +pub type HostFunctions = ( + sp_io::SubstrateHostFunctions, + sp_messenger_host_functions::HostFunctions, + sp_subspace_mmr::DomainHostFunctions, +); + +/// Host functions required for Subspace domain +#[cfg(feature = "runtime-benchmarks")] +pub type HostFunctions = ( + sp_io::SubstrateHostFunctions, + sp_messenger_host_functions::HostFunctions, + sp_subspace_mmr::DomainHostFunctions, + frame_benchmarking::benchmarking::HostFunctions, +); + +/// Runtime executor for Domains +pub type RuntimeExecutor = sc_executor::WasmExecutor; + +/// Extensions factory for subspace domains. +pub struct ExtensionsFactory { + consensus_client: Arc, + executor: Arc, + _marker: PhantomData<(CBlock, Block)>, +} + +impl ExtensionsFactory { + pub fn new(consensus_client: Arc, executor: Arc) -> Self { + Self { + consensus_client, + executor, + _marker: Default::default(), + } + } +} + +impl ExtensionsFactoryT + for ExtensionsFactory +where + Block: BlockT, + CBlock: BlockT, + CBlock::Hash: From, + CClient: HeaderBackend + ProvideRuntimeApi + 'static, + CClient::Api: MmrApi> + + MessengerApi> + + DomainsApi, + Executor: CodeExecutor + RuntimeVersionOf, +{ + fn extensions_for( + &self, + _block_hash: Block::Hash, + _block_number: NumberFor, + ) -> Extensions { + let mut exts = Extensions::new(); + exts.register(SubspaceMmrExtension::new(Arc::new( + SubspaceMmrHostFunctionsImpl::::new(self.consensus_client.clone()), + ))); + + exts.register(MessengerExtension::new(Arc::new( + MessengerHostFunctionsImpl::::new( + self.consensus_client.clone(), + self.executor.clone(), + ), + ))); + + exts + } +} diff --git a/crates/subspace-service/src/lib.rs b/crates/subspace-service/src/lib.rs index a5f1484d86..b49d995b4c 100644 --- a/crates/subspace-service/src/lib.rs +++ b/crates/subspace-service/src/lib.rs @@ -25,6 +25,7 @@ )] pub mod config; +pub mod domains; pub mod dsn; mod metrics; pub mod rpc; @@ -39,6 +40,7 @@ use crate::transaction_pool::FullPool; use core::sync::atomic::{AtomicU32, Ordering}; use cross_domain_message_gossip::xdm_gossip_peers_set_config; use domain_runtime_primitives::opaque::{Block as DomainBlock, Header as DomainHeader}; +use domains::ExtensionsFactory as DomainsExtensionFactory; use frame_system_rpc_runtime_api::AccountNonceApi; use futures::channel::oneshot; use futures::FutureExt; @@ -228,6 +230,7 @@ struct SubspaceExtensionsFactory { client: Arc, pot_verifier: PotVerifier, executor: Arc, + domains_executor: Arc, _pos_table: PhantomData<(PosTable, DomainBlock)>, } @@ -366,9 +369,13 @@ where })); exts.register(FraudProofExtension::new(Arc::new( - FraudProofHostFunctionsImpl::<_, _, DomainBlock, RuntimeExecutor>::new( + FraudProofHostFunctionsImpl::<_, _, DomainBlock, _>::new( self.client.clone(), - self.executor.clone(), + self.domains_executor.clone(), + Box::new(DomainsExtensionFactory::<_, Block, DomainBlock, _>::new( + self.client.clone(), + self.domains_executor.clone(), + )), ), ))); @@ -450,6 +457,7 @@ where .transpose()?; let executor = sc_service::new_wasm_executor(config); + let domains_executor = sc_service::new_wasm_executor(config); let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::( @@ -477,6 +485,7 @@ where client: Arc::clone(&client), pot_verifier: pot_verifier.clone(), executor: executor.clone(), + domains_executor: Arc::new(domains_executor), _pos_table: PhantomData, }); diff --git a/domains/primitives/messenger-host-functions/src/host_functions.rs b/domains/primitives/messenger-host-functions/src/host_functions.rs index 1a6c1ba01a..5f85fe140e 100644 --- a/domains/primitives/messenger-host-functions/src/host_functions.rs +++ b/domains/primitives/messenger-host-functions/src/host_functions.rs @@ -7,7 +7,7 @@ use sp_core::traits::CodeExecutor; use sp_core::H256; use sp_domains::{DomainId, DomainsApi}; use sp_messenger::messages::ChainId; -use sp_messenger::MessengerApi; +pub use sp_messenger::MessengerApi; use sp_runtime::traits::{Block as BlockT, Header, NumberFor}; use std::marker::PhantomData; use std::sync::Arc; diff --git a/domains/primitives/messenger-host-functions/src/lib.rs b/domains/primitives/messenger-host-functions/src/lib.rs index 31a9d4eb78..1a5c02a06e 100644 --- a/domains/primitives/messenger-host-functions/src/lib.rs +++ b/domains/primitives/messenger-host-functions/src/lib.rs @@ -29,7 +29,7 @@ mod host_functions; mod runtime_interface; #[cfg(feature = "std")] -pub use host_functions::{MessengerExtension, MessengerHostFunctionsImpl}; +pub use host_functions::{MessengerApi, MessengerExtension, MessengerHostFunctionsImpl}; pub use runtime_interface::messenger_runtime_interface::get_storage_key; #[cfg(feature = "std")] pub use runtime_interface::messenger_runtime_interface::HostFunctions; diff --git a/domains/service/Cargo.toml b/domains/service/Cargo.toml index 9ceda3809c..ba549cf9fc 100644 --- a/domains/service/Cargo.toml +++ b/domains/service/Cargo.toml @@ -63,6 +63,7 @@ sp-subspace-mmr = { version = "0.1.0", path = "../../crates/sp-subspace-mmr" } sp-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } subspace-core-primitives = { version = "0.1.0", path = "../../crates/subspace-core-primitives" } subspace-runtime-primitives = { version = "0.1.0", path = "../../crates/subspace-runtime-primitives" } +subspace-service = { version = "0.1.0", path = "../../crates/subspace-service" } substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } substrate-prometheus-endpoint = { git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } tokio = "1.35.1" diff --git a/domains/service/src/domain.rs b/domains/service/src/domain.rs index 97f1cc05c4..7f66fc7fd8 100644 --- a/domains/service/src/domain.rs +++ b/domains/service/src/domain.rs @@ -1,6 +1,6 @@ use crate::providers::{BlockImportProvider, RpcProvider}; use crate::transaction_pool::FullChainApiWrapper; -use crate::{DomainExtensionsFactory, FullBackend, FullClient, RuntimeExecutor}; +use crate::{FullBackend, FullClient}; use cross_domain_message_gossip::ChainTxPoolMsg; use domain_client_block_preprocessor::inherents::CreateInherentDataProvider; use domain_client_message_relayer::GossipMessageSink; @@ -46,6 +46,7 @@ use std::str::FromStr; use std::sync::Arc; use subspace_core_primitives::PotOutput; use subspace_runtime_primitives::Nonce; +use subspace_service::domains::{ExtensionsFactory, RuntimeExecutor}; use substrate_frame_rpc_system::AccountNonceApi; pub type DomainOperator = Operator< @@ -173,13 +174,9 @@ where let client = Arc::new(client); let executor = Arc::new(executor); - client - .execution_extensions() - .set_extensions_factory(DomainExtensionsFactory::<_, CBlock, Block> { - consensus_client: consensus_client.clone(), - executor: executor.clone(), - _marker: Default::default(), - }); + client.execution_extensions().set_extensions_factory( + ExtensionsFactory::<_, CBlock, Block, _>::new(consensus_client.clone(), executor.clone()), + ); let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle()); diff --git a/domains/service/src/lib.rs b/domains/service/src/lib.rs index 3514069133..74ca989796 100644 --- a/domains/service/src/lib.rs +++ b/domains/service/src/lib.rs @@ -9,7 +9,6 @@ mod transaction_pool; pub use self::domain::{new_full, DomainOperator, DomainParams, FullPool, NewFull}; use futures::channel::oneshot; use futures::{FutureExt, StreamExt}; -use sc_client_api::execution_extensions::ExtensionsFactory; use sc_client_api::{BlockBackend, BlockchainEvents, HeaderBackend, ProofProvider}; use sc_consensus::ImportQueue; use sc_network::config::Roles; @@ -28,82 +27,17 @@ use sc_service::{ use sc_transaction_pool_api::MaintainedTransactionPool; use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedSender}; use sp_api::ProvideRuntimeApi; -use sp_api::__private::Extensions; use sp_blockchain::HeaderMetadata; use sp_consensus::block_validation::{Chain, DefaultBlockAnnounceValidator}; -use sp_core::H256; -use sp_domains::DomainsApi; -use sp_messenger::MessengerApi; -use sp_messenger_host_functions::{MessengerExtension, MessengerHostFunctionsImpl}; -use sp_mmr_primitives::MmrApi; -use sp_runtime::traits::{Block as BlockT, BlockIdTo, NumberFor, Zero}; -use sp_subspace_mmr::host_functions::{SubspaceMmrExtension, SubspaceMmrHostFunctionsImpl}; -use std::marker::PhantomData; +use sp_runtime::traits::{Block as BlockT, BlockIdTo, Zero}; use std::sync::Arc; - -/// Host functions required for Subspace domain -#[cfg(not(feature = "runtime-benchmarks"))] -pub type HostFunctions = ( - sp_io::SubstrateHostFunctions, - sp_messenger_host_functions::HostFunctions, - sp_subspace_mmr::DomainHostFunctions, -); - -/// Host functions required for Subspace domain -#[cfg(feature = "runtime-benchmarks")] -pub type HostFunctions = ( - sp_io::SubstrateHostFunctions, - sp_messenger_host_functions::HostFunctions, - sp_subspace_mmr::DomainHostFunctions, - frame_benchmarking::benchmarking::HostFunctions, -); - -/// Runtime executor for Subspace domain -pub type RuntimeExecutor = sc_executor::WasmExecutor; +pub use subspace_service::domains::RuntimeExecutor; /// Domain full client. pub type FullClient = TFullClient; pub type FullBackend = sc_service::TFullBackend; -pub(crate) struct DomainExtensionsFactory { - consensus_client: Arc, - executor: Arc, - _marker: PhantomData<(CBlock, Block)>, -} - -impl ExtensionsFactory - for DomainExtensionsFactory -where - Block: BlockT, - CBlock: BlockT, - CBlock::Hash: From, - CClient: HeaderBackend + ProvideRuntimeApi + 'static, - CClient::Api: MmrApi> - + MessengerApi> - + DomainsApi, -{ - fn extensions_for( - &self, - _block_hash: Block::Hash, - _block_number: NumberFor, - ) -> Extensions { - let mut exts = Extensions::new(); - exts.register(SubspaceMmrExtension::new(Arc::new( - SubspaceMmrHostFunctionsImpl::::new(self.consensus_client.clone()), - ))); - - exts.register(MessengerExtension::new(Arc::new( - MessengerHostFunctionsImpl::::new( - self.consensus_client.clone(), - self.executor.clone(), - ), - ))); - - exts - } -} - /// Build the network service, the network status sinks and an RPC sender. /// /// Port from `sc_service::build_network` mostly the same with block sync disabled. diff --git a/test/subspace-test-service/Cargo.toml b/test/subspace-test-service/Cargo.toml index c2fdfb3130..546f3b2805 100644 --- a/test/subspace-test-service/Cargo.toml +++ b/test/subspace-test-service/Cargo.toml @@ -46,6 +46,7 @@ sp-domains = { version = "0.1.0", path = "../../crates/sp-domains" } sp-domains-fraud-proof = { version = "0.1.0", path = "../../crates/sp-domains-fraud-proof" } sp-externalities = { version = "0.19.0", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } sp-keyring = { git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } +sp-messenger = { version = "0.1.0", path = "../../domains/primitives/messenger" } sp-mmr-primitives = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } sp-subspace-mmr = { version = "0.1.0", path = "../../crates/sp-subspace-mmr" } sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } diff --git a/test/subspace-test-service/src/lib.rs b/test/subspace-test-service/src/lib.rs index 70e169c9e0..f3cb5578d8 100644 --- a/test/subspace-test-service/src/lib.rs +++ b/test/subspace-test-service/src/lib.rs @@ -63,6 +63,7 @@ use sp_domains_fraud_proof::{FraudProofExtension, FraudProofHostFunctionsImpl}; use sp_externalities::Extensions; use sp_inherents::{InherentData, InherentDataProvider}; use sp_keyring::Sr25519Keyring; +use sp_messenger::MessengerApi; use sp_mmr_primitives::MmrApi; use sp_runtime::generic::{BlockId, Digest}; use sp_runtime::traits::{ @@ -81,6 +82,7 @@ use std::time; use subspace_core_primitives::{PotOutput, Solution}; use subspace_runtime_primitives::opaque::Block; use subspace_runtime_primitives::{AccountId, Balance, Hash}; +use subspace_service::domains::ExtensionsFactory as DomainsExtensionFactory; use subspace_service::transaction_pool::FullPool; use subspace_service::{FullSelectChain, RuntimeExecutor}; use subspace_test_client::{chain_spec, Backend, Client}; @@ -224,6 +226,7 @@ where Client: BlockBackend + HeaderBackend + ProvideRuntimeApi + 'static, Client::Api: DomainsApi + BundleProducerElectionApi + + MessengerApi> + MmrApi>, Executor: CodeExecutor + sc_executor::RuntimeVersionOf, { @@ -237,6 +240,10 @@ where FraudProofHostFunctionsImpl::<_, _, DomainBlock, Executor>::new( self.consensus_client.clone(), self.executor.clone(), + Box::new(DomainsExtensionFactory::<_, Block, DomainBlock, _>::new( + self.consensus_client.clone(), + self.executor.clone(), + )), ), ))); exts.register(SubspaceMmrExtension::new(Arc::new( @@ -345,13 +352,18 @@ impl MockConsensusNode { sc_service::new_full_parts::(&config, None, executor.clone()) .expect("Fail to new full parts"); + let domain_executor = sc_service::new_wasm_executor(&config); let client = Arc::new(client); let mock_pot_verifier = Arc::new(MockPotVerfier::default()); client .execution_extensions() - .set_extensions_factory(MockExtensionsFactory::<_, DomainBlock, _>::new( + .set_extensions_factory(MockExtensionsFactory::< + _, + DomainBlock, + subspace_service::domains::RuntimeExecutor, + >::new( client.clone(), - Arc::new(executor.clone()), + Arc::new(domain_executor), Arc::clone(&mock_pot_verifier), ));