-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2508 from subspace/xdm_mmr
XDM with MMR proofs: 1
- Loading branch information
Showing
52 changed files
with
1,358 additions
and
730 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[package] | ||
name = "sc-domains" | ||
version = "0.1.0" | ||
authors = ["Subspace Labs <https://subspace.network>"] | ||
description = "Subspace service." | ||
edition = "2021" | ||
license = "GPL-3.0-or-later" | ||
homepage = "https://subspace.network" | ||
repository = "https://github.com/subspace/subspace" | ||
include = [ | ||
"/src", | ||
"/Cargo.toml", | ||
] | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8", optional = true } | ||
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } | ||
sc-executor = { version = "0.10.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } | ||
sp-api = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } | ||
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } | ||
sp-core = { version = "21.0.0", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } | ||
sp-domains = { version = "0.1.0", path = "../sp-domains" } | ||
sp-externalities = { version = "0.19.0", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } | ||
sp-io = { version = "23.0.0", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } | ||
sp-messenger-host-functions = { version = "0.1.0", path = "../../domains/primitives/messenger-host-functions" } | ||
sp-runtime = { version = "24.0.0", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } | ||
sp-subspace-mmr = { version = "0.1.0", path = "../sp-subspace-mmr" } | ||
|
||
[features] | ||
runtime-benchmarks = ["dep:frame-benchmarking"] |
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,101 @@ | ||
// Copyright (C) 2021 Subspace Labs, Inc. | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
//! Domain specific Host functions and Extension factory | ||
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.