Skip to content

Commit ab65eba

Browse files
authored
Merge pull request #2508 from subspace/xdm_mmr
XDM with MMR proofs: 1
2 parents 81004be + 5cdebfd commit ab65eba

File tree

52 files changed

+1358
-730
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1358
-730
lines changed

Cargo.lock

+62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pallet-domains/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,10 @@ impl<T: Config> Pallet<T> {
20392039
) -> Option<ReceiptHashFor<T>> {
20402040
BlockTree::<T>::get(domain_id, domain_number)
20412041
}
2042+
2043+
pub fn confirmed_domain_block_storage_key(domain_id: DomainId) -> Vec<u8> {
2044+
LatestConfirmedDomainBlock::<T>::hashed_key_for(domain_id)
2045+
}
20422046
}
20432047

20442048
impl<T> Pallet<T>

crates/pallet-domains/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ impl FraudProofHostFunctions for MockDomainFraudProofExtension {
448448

449449
fn execution_proof_check(
450450
&self,
451+
_domain_id: (u32, H256),
451452
_pre_state_root: H256,
452453
_encoded_proof: Vec<u8>,
453454
_execution_method: &str,

crates/sc-domains/Cargo.toml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[package]
2+
name = "sc-domains"
3+
version = "0.1.0"
4+
authors = ["Subspace Labs <https://subspace.network>"]
5+
description = "Subspace service."
6+
edition = "2021"
7+
license = "GPL-3.0-or-later"
8+
homepage = "https://subspace.network"
9+
repository = "https://github.com/subspace/subspace"
10+
include = [
11+
"/src",
12+
"/Cargo.toml",
13+
]
14+
15+
[package.metadata.docs.rs]
16+
targets = ["x86_64-unknown-linux-gnu"]
17+
18+
[dependencies]
19+
frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8", optional = true }
20+
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
21+
sc-executor = { version = "0.10.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
22+
sp-api = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
23+
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
24+
sp-core = { version = "21.0.0", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
25+
sp-domains = { version = "0.1.0", path = "../sp-domains" }
26+
sp-externalities = { version = "0.19.0", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
27+
sp-io = { version = "23.0.0", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
28+
sp-messenger-host-functions = { version = "0.1.0", path = "../../domains/primitives/messenger-host-functions" }
29+
sp-runtime = { version = "24.0.0", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
30+
sp-subspace-mmr = { version = "0.1.0", path = "../sp-subspace-mmr" }
31+
32+
[features]
33+
runtime-benchmarks = ["dep:frame-benchmarking"]

crates/sc-domains/src/lib.rs

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright (C) 2021 Subspace Labs, Inc.
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
//! Domain specific Host functions and Extension factory
18+
19+
use sc_client_api::execution_extensions::ExtensionsFactory as ExtensionsFactoryT;
20+
use sc_executor::RuntimeVersionOf;
21+
use sp_api::ProvideRuntimeApi;
22+
use sp_blockchain::HeaderBackend;
23+
use sp_core::traits::CodeExecutor;
24+
use sp_core::H256;
25+
use sp_domains::DomainsApi;
26+
use sp_externalities::Extensions;
27+
use sp_messenger_host_functions::{MessengerApi, MessengerExtension, MessengerHostFunctionsImpl};
28+
use sp_runtime::traits::{Block as BlockT, NumberFor};
29+
use sp_subspace_mmr::host_functions::{MmrApi, SubspaceMmrExtension, SubspaceMmrHostFunctionsImpl};
30+
use std::marker::PhantomData;
31+
use std::sync::Arc;
32+
33+
/// Host functions required for Subspace domain
34+
#[cfg(not(feature = "runtime-benchmarks"))]
35+
pub type HostFunctions = (
36+
sp_io::SubstrateHostFunctions,
37+
sp_messenger_host_functions::HostFunctions,
38+
sp_subspace_mmr::DomainHostFunctions,
39+
);
40+
41+
/// Host functions required for Subspace domain
42+
#[cfg(feature = "runtime-benchmarks")]
43+
pub type HostFunctions = (
44+
sp_io::SubstrateHostFunctions,
45+
sp_messenger_host_functions::HostFunctions,
46+
sp_subspace_mmr::DomainHostFunctions,
47+
frame_benchmarking::benchmarking::HostFunctions,
48+
);
49+
50+
/// Runtime executor for Domains
51+
pub type RuntimeExecutor = sc_executor::WasmExecutor<HostFunctions>;
52+
53+
/// Extensions factory for subspace domains.
54+
pub struct ExtensionsFactory<CClient, CBlock, Block, Executor> {
55+
consensus_client: Arc<CClient>,
56+
executor: Arc<Executor>,
57+
_marker: PhantomData<(CBlock, Block)>,
58+
}
59+
60+
impl<CClient, CBlock, Block, Executor> ExtensionsFactory<CClient, CBlock, Block, Executor> {
61+
pub fn new(consensus_client: Arc<CClient>, executor: Arc<Executor>) -> Self {
62+
Self {
63+
consensus_client,
64+
executor,
65+
_marker: Default::default(),
66+
}
67+
}
68+
}
69+
70+
impl<CClient, CBlock, Block, Executor> ExtensionsFactoryT<Block>
71+
for ExtensionsFactory<CClient, CBlock, Block, Executor>
72+
where
73+
Block: BlockT,
74+
CBlock: BlockT,
75+
CBlock::Hash: From<H256>,
76+
CClient: HeaderBackend<CBlock> + ProvideRuntimeApi<CBlock> + 'static,
77+
CClient::Api: MmrApi<CBlock, H256, NumberFor<CBlock>>
78+
+ MessengerApi<CBlock, NumberFor<CBlock>>
79+
+ DomainsApi<CBlock, Block::Header>,
80+
Executor: CodeExecutor + RuntimeVersionOf,
81+
{
82+
fn extensions_for(
83+
&self,
84+
_block_hash: Block::Hash,
85+
_block_number: NumberFor<Block>,
86+
) -> Extensions {
87+
let mut exts = Extensions::new();
88+
exts.register(SubspaceMmrExtension::new(Arc::new(
89+
SubspaceMmrHostFunctionsImpl::<CBlock, _>::new(self.consensus_client.clone()),
90+
)));
91+
92+
exts.register(MessengerExtension::new(Arc::new(
93+
MessengerHostFunctionsImpl::<CBlock, _, Block, _>::new(
94+
self.consensus_client.clone(),
95+
self.executor.clone(),
96+
),
97+
)));
98+
99+
exts
100+
}
101+
}

0 commit comments

Comments
 (0)