Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Companion for: pallet-mmr: move offchain logic to client-side gadget (#…
Browse files Browse the repository at this point in the history
…6321)

* Spawn MMR gadget when offchain indexing is enabled

* companion PR code review changes: 1st iteration

* Code review changes: 2nd iteration

* update lockfile for {"substrate"}

Co-authored-by: acatangiu <adrian@parity.io>
Co-authored-by: parity-processbot <>
  • Loading branch information
serban300 and acatangiu committed Nov 29, 2022
1 parent 98d2350 commit 3f288d3
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 182 deletions.
385 changes: 204 additions & 181 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "
beefy-gadget = { git = "https://github.com/paritytech/substrate", branch = "master" }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" }
grandpa = { package = "sc-finality-grandpa", git = "https://github.com/paritytech/substrate", branch = "master" }
mmr-gadget = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master"}
sc-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down
14 changes: 14 additions & 0 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub use polkadot_client::PolkadotExecutorDispatch;

pub use chain_spec::{KusamaChainSpec, PolkadotChainSpec, RococoChainSpec, WestendChainSpec};
pub use consensus_common::{block_validation::Chain, Proposal, SelectChain};
use mmr_gadget::MmrGadget;
#[cfg(feature = "full-node")]
pub use polkadot_client::{
AbstractClient, Client, ClientHandle, ExecuteWithClient, FullBackend, FullClient,
Expand Down Expand Up @@ -758,6 +759,7 @@ where
{
use polkadot_node_network_protocol::request_response::IncomingRequest;

let is_offchain_indexing_enabled = config.offchain_worker.indexing_enabled;
let role = config.role.clone();
let force_authoring = config.force_authoring;
let backoff_authoring_blocks = {
Expand Down Expand Up @@ -1219,6 +1221,18 @@ where
} else {
task_manager.spawn_handle().spawn_blocking("beefy-gadget", None, gadget);
}

if is_offchain_indexing_enabled {
task_manager.spawn_handle().spawn_blocking(
"mmr-gadget",
None,
MmrGadget::start(
client.clone(),
backend.clone(),
sp_mmr_primitives::INDEXING_PREFIX.to_vec(),
),
);
}
}

let config = grandpa::Config {
Expand Down
4 changes: 4 additions & 0 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,10 @@ sp_api::impl_runtime_apis! {
Err(mmr::Error::PalletNotIncluded)
}

fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}

fn generate_proof(
_block_numbers: Vec<BlockNumber>,
_best_known_block_number: Option<BlockNumber>,
Expand Down
4 changes: 4 additions & 0 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,10 @@ sp_api::impl_runtime_apis! {
Err(mmr::Error::PalletNotIncluded)
}

fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}

fn generate_proof(
_block_numbers: Vec<BlockNumber>,
_best_known_block_number: Option<BlockNumber>,
Expand Down
6 changes: 5 additions & 1 deletion runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ impl pallet_beefy::Config for Runtime {
type MmrHash = <Keccak256 as sp_runtime::traits::Hash>::Output;

impl pallet_mmr::Config for Runtime {
const INDEXING_PREFIX: &'static [u8] = b"mmr";
const INDEXING_PREFIX: &'static [u8] = mmr::INDEXING_PREFIX;
type Hashing = Keccak256;
type Hash = MmrHash;
type OnNewRoot = pallet_beefy_mmr::DepositBeefyDigest<Runtime>;
Expand Down Expand Up @@ -1715,6 +1715,10 @@ sp_api::impl_runtime_apis! {
Ok(Mmr::mmr_root())
}

fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
Ok(Mmr::mmr_leaves())
}

fn generate_proof(
block_numbers: Vec<BlockNumber>,
best_known_block_number: Option<BlockNumber>,
Expand Down
4 changes: 4 additions & 0 deletions runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,10 @@ sp_api::impl_runtime_apis! {
Err(mmr::Error::PalletNotIncluded)
}

fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}

fn generate_proof(
_block_numbers: Vec<BlockNumber>,
_best_known_block_number: Option<BlockNumber>,
Expand Down
3 changes: 3 additions & 0 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,10 @@ sp_api::impl_runtime_apis! {

impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
fn mmr_root() -> Result<Hash, mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}

fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}

Expand Down

0 comments on commit 3f288d3

Please sign in to comment.