Skip to content

Commit

Permalink
Merge pull request #2851 from subspace/xdm-host-func
Browse files Browse the repository at this point in the history
Ensure to use the domain executor within the messenger and fraud proof host function
  • Loading branch information
NingLin-P authored Jun 18, 2024
2 parents b2f53af + 1b9d394 commit be55eb4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
58 changes: 35 additions & 23 deletions crates/sp-domains-fraud-proof/src/host_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl FraudProofExtension {
/// Trait Impl to query and verify Domains Fraud proof.
pub struct FraudProofHostFunctionsImpl<Block, Client, DomainBlock, Executor, EFC> {
consensus_client: Arc<Client>,
executor: Arc<Executor>,
domain_executor: Arc<Executor>,
domain_extensions_factory_creator: EFC,
_phantom: PhantomData<(Block, DomainBlock)>,
}
Expand All @@ -142,12 +142,12 @@ impl<Block, Client, DomainBlock, Executor, EFC>
{
pub fn new(
consensus_client: Arc<Client>,
executor: Arc<Executor>,
domain_executor: Arc<Executor>,
domain_extensions_factory_creator: EFC,
) -> Self {
FraudProofHostFunctionsImpl {
consensus_client,
executor,
domain_executor,
domain_extensions_factory_creator,
_phantom: Default::default(),
}
Expand Down Expand Up @@ -186,8 +186,10 @@ where
let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?;
let timestamp = runtime_api.timestamp(consensus_block_hash.into()).ok()?;

let domain_stateless_runtime =
StatelessRuntime::<DomainBlock, _>::new(self.executor.clone(), runtime_code.into());
let domain_stateless_runtime = StatelessRuntime::<DomainBlock, _>::new(
self.domain_executor.clone(),
runtime_code.into(),
);

domain_stateless_runtime
.construct_timestamp_extrinsic(timestamp)
Expand All @@ -206,8 +208,10 @@ where
.domain_chains_allowlist_update(consensus_block_hash.into(), domain_id)
.ok()??;

let domain_stateless_runtime =
StatelessRuntime::<DomainBlock, _>::new(self.executor.clone(), runtime_code.into());
let domain_stateless_runtime = StatelessRuntime::<DomainBlock, _>::new(
self.domain_executor.clone(),
runtime_code.into(),
);

domain_stateless_runtime
.construct_domain_update_chain_allowlist_extrinsic(updates)
Expand All @@ -226,8 +230,10 @@ where
.ok()?;

let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?;
let domain_stateless_runtime =
StatelessRuntime::<DomainBlock, _>::new(self.executor.clone(), runtime_code.into());
let domain_stateless_runtime = StatelessRuntime::<DomainBlock, _>::new(
self.domain_executor.clone(),
runtime_code.into(),
);

domain_stateless_runtime
.construct_consensus_chain_byte_fee_extrinsic(consensus_chain_byte_fee)
Expand Down Expand Up @@ -274,8 +280,10 @@ where

if let Some(upgraded_runtime) = maybe_upgraded_runtime {
let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?;
let domain_stateless_runtime =
StatelessRuntime::<DomainBlock, _>::new(self.executor.clone(), runtime_code.into());
let domain_stateless_runtime = StatelessRuntime::<DomainBlock, _>::new(
self.domain_executor.clone(),
runtime_code.into(),
);

domain_stateless_runtime
.construct_set_code_extrinsic(upgraded_runtime)
Expand Down Expand Up @@ -363,11 +371,13 @@ where
opaque_extrinsic: OpaqueExtrinsic,
) -> Option<bool> {
let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?;
let mut domain_stateless_runtime =
StatelessRuntime::<DomainBlock, _>::new(self.executor.clone(), runtime_code.into());
let mut domain_stateless_runtime = StatelessRuntime::<DomainBlock, _>::new(
self.domain_executor.clone(),
runtime_code.into(),
);
let extension_factory = (self.domain_extensions_factory_creator)(
self.consensus_client.clone(),
self.executor.clone(),
self.domain_executor.clone(),
);
domain_stateless_runtime.set_extension_factory(extension_factory);

Expand Down Expand Up @@ -406,8 +416,10 @@ where
req: StorageKeyRequest,
) -> Option<Vec<u8>> {
let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?;
let domain_stateless_runtime =
StatelessRuntime::<DomainBlock, _>::new(self.executor.clone(), runtime_code.into());
let domain_stateless_runtime = StatelessRuntime::<DomainBlock, _>::new(
self.domain_executor.clone(),
runtime_code.into(),
);
Some(
match req {
StorageKeyRequest::Transfers => domain_stateless_runtime.transfers_storage_key(),
Expand Down Expand Up @@ -633,7 +645,7 @@ where
}

let domain_stateless_runtime = StatelessRuntime::<DomainBlock, _>::new(
self.executor.clone(),
self.domain_executor.clone(),
domain_runtime_code.into(),
);

Expand Down Expand Up @@ -674,15 +686,15 @@ where
let (domain_block_number, domain_block_hash) = domain_block_id;
let mut domain_extensions = (self.domain_extensions_factory_creator)(
self.consensus_client.clone(),
self.executor.clone(),
self.domain_executor.clone(),
)
.extensions_for(domain_block_hash.into(), domain_block_number.into());

execution_proof_check::<<DomainBlock::Header as HeaderT>::Hashing, _>(
pre_state_root.into(),
proof,
&mut Default::default(),
self.executor.as_ref(),
self.domain_executor.as_ref(),
execution_method,
call_data,
&runtime_code,
Expand Down Expand Up @@ -734,7 +746,7 @@ where
} = domain_inherent_extrinsic_data;

let domain_stateless_runtime = StatelessRuntime::<DomainBlock, _>::new(
self.executor.clone(),
self.domain_executor.clone(),
domain_runtime_code.into(),
);

Expand Down Expand Up @@ -783,7 +795,7 @@ where
req: DomainStorageKeyRequest,
) -> Option<Vec<u8>> {
let domain_stateless_runtime = StatelessRuntime::<DomainBlock, _>::new(
self.executor.clone(),
self.domain_executor.clone(),
domain_runtime_code.into(),
);
let key = match req {
Expand All @@ -800,7 +812,7 @@ where
call: StatelessDomainRuntimeCall,
) -> Option<bool> {
let domain_stateless_runtime = StatelessRuntime::<DomainBlock, _>::new(
self.executor.clone(),
self.domain_executor.clone(),
domain_runtime_code.into(),
);

Expand Down Expand Up @@ -840,7 +852,7 @@ where
bundle_body: Vec<OpaqueExtrinsic>,
) -> Option<Weight> {
let domain_stateless_runtime = StatelessRuntime::<DomainBlock, _>::new(
self.executor.clone(),
self.domain_executor.clone(),
domain_runtime_code.into(),
);
let mut estimated_bundle_weight = Weight::default();
Expand Down
6 changes: 1 addition & 5 deletions crates/subspace-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ struct SubspaceExtensionsFactory<PosTable, Client, DomainBlock> {
client: Arc<Client>,
backend: Arc<FullBackend>,
pot_verifier: PotVerifier,
executor: Arc<RuntimeExecutor>,
domains_executor: Arc<sc_domains::RuntimeExecutor>,
_pos_table: PhantomData<(PosTable, DomainBlock)>,
}
Expand Down Expand Up @@ -403,7 +402,7 @@ where
exts.register(MessengerExtension::new(Arc::new(
MessengerHostFunctionsImpl::<Block, _, DomainBlock, _>::new(
self.client.clone(),
self.executor.clone(),
self.domains_executor.clone(),
),
)));

Expand Down Expand Up @@ -500,15 +499,12 @@ where
POT_VERIFIER_CACHE_SIZE,
);

let executor = Arc::new(executor);

client
.execution_extensions()
.set_extensions_factory(SubspaceExtensionsFactory::<PosTable, _, DomainBlock> {
kzg: kzg.clone(),
client: Arc::clone(&client),
pot_verifier: pot_verifier.clone(),
executor: executor.clone(),
domains_executor: Arc::new(domains_executor),
backend: backend.clone(),
_pos_table: PhantomData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ impl MessengerExtension {
/// Implementation of Messenger host function.
pub struct MessengerHostFunctionsImpl<Block, Client, DomainBlock, Executor> {
consensus_client: Arc<Client>,
executor: Arc<Executor>,
domain_executor: Arc<Executor>,
_phantom: PhantomData<(Block, DomainBlock)>,
}

impl<Block, Client, DomainBlock, Executor>
MessengerHostFunctionsImpl<Block, Client, DomainBlock, Executor>
{
pub fn new(consensus_client: Arc<Client>, executor: Arc<Executor>) -> Self {
pub fn new(consensus_client: Arc<Client>, domain_executor: Arc<Executor>) -> Self {
MessengerHostFunctionsImpl {
consensus_client,
executor,
domain_executor,
_phantom: Default::default(),
}
}
Expand Down Expand Up @@ -81,8 +81,10 @@ where
.ok()
.flatten()
.map(|(data, _)| data.raw_genesis.into_storage())?;
let mut domain_stateless_runtime =
StatelessRuntime::<DomainBlock, _>::new(self.executor.clone(), domain_runtime.into());
let mut domain_stateless_runtime = StatelessRuntime::<DomainBlock, _>::new(
self.domain_executor.clone(),
domain_runtime.into(),
);

domain_stateless_runtime.set_storage(domain_state);
Some(domain_stateless_runtime)
Expand Down

0 comments on commit be55eb4

Please sign in to comment.