Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XDM with MMR proofs: 1 #2508

Merged
merged 10 commits into from
Feb 23, 2024
62 changes: 62 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,10 @@ impl<T: Config> Pallet<T> {
) -> Option<ReceiptHashFor<T>> {
BlockTree::<T>::get(domain_id, domain_number)
}

pub fn confirmed_domain_block_storage_key(domain_id: DomainId) -> Vec<u8> {
LatestConfirmedDomainBlock::<T>::hashed_key_for(domain_id)
}
}

impl<T> Pallet<T>
Expand Down
1 change: 1 addition & 0 deletions crates/pallet-domains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ impl FraudProofHostFunctions for MockDomainFraudProofExtension {

fn execution_proof_check(
&self,
_domain_id: (u32, H256),
_pre_state_root: H256,
_encoded_proof: Vec<u8>,
_execution_method: &str,
Expand Down
33 changes: 33 additions & 0 deletions crates/sc-domains/Cargo.toml
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"]
101 changes: 101 additions & 0 deletions crates/sc-domains/src/lib.rs
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
}
}
Loading
Loading