-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor domain specific host functions and ext factory and update fr…
…aud proof verifier to use the extensions
- Loading branch information
Showing
17 changed files
with
203 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<HostFunctions>; | ||
|
||
/// Extensions factory for subspace domains. | ||
pub struct ExtensionsFactory<CClient, CBlock, Block, Executor> { | ||
consensus_client: Arc<CClient>, | ||
executor: Arc<Executor>, | ||
_marker: PhantomData<(CBlock, Block)>, | ||
} | ||
|
||
impl<CClient, CBlock, Block, Executor> ExtensionsFactory<CClient, CBlock, Block, Executor> { | ||
pub fn new(consensus_client: Arc<CClient>, executor: Arc<Executor>) -> Self { | ||
Self { | ||
consensus_client, | ||
executor, | ||
_marker: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
impl<CClient, CBlock, Block, Executor> ExtensionsFactoryT<Block> | ||
for ExtensionsFactory<CClient, CBlock, Block, Executor> | ||
where | ||
Block: BlockT, | ||
CBlock: BlockT, | ||
CBlock::Hash: From<H256>, | ||
CClient: HeaderBackend<CBlock> + ProvideRuntimeApi<CBlock> + 'static, | ||
CClient::Api: MmrApi<CBlock, H256, NumberFor<CBlock>> | ||
+ MessengerApi<CBlock, NumberFor<CBlock>> | ||
+ DomainsApi<CBlock, Block::Header>, | ||
Executor: CodeExecutor + RuntimeVersionOf, | ||
{ | ||
fn extensions_for( | ||
&self, | ||
_block_hash: Block::Hash, | ||
_block_number: NumberFor<Block>, | ||
) -> Extensions { | ||
let mut exts = Extensions::new(); | ||
exts.register(SubspaceMmrExtension::new(Arc::new( | ||
SubspaceMmrHostFunctionsImpl::<CBlock, _>::new(self.consensus_client.clone()), | ||
))); | ||
|
||
exts.register(MessengerExtension::new(Arc::new( | ||
MessengerHostFunctionsImpl::<CBlock, _, Block, _>::new( | ||
self.consensus_client.clone(), | ||
self.executor.clone(), | ||
), | ||
))); | ||
|
||
exts | ||
} | ||
} |
Oops, something went wrong.