Add mmr_root() to pallet-mmr API to expose root from state (companion for substrate#11183) (#5276)

* Add mmr_root() to pallet-mmr API to expose root from state

* use the right MmrApi primitives

* bridges: use correct mmr primitives

* rococo: beefy-mmr deposit mmr root digest

* fix lockfile

* update lockfile for {"substrate"}

Co-authored-by: parity-processbot <>
This commit is contained in:
Adrian Catangiu
2022-04-13 13:55:18 +03:00
committed by GitHub
parent ff18cabbc5
commit a46237cebb
20 changed files with 262 additions and 220 deletions
+2 -2
View File
@@ -17,6 +17,7 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "mas
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
@@ -44,7 +45,6 @@ pallet-im-online = { git = "https://github.com/paritytech/substrate", branch = "
pallet-indices = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-membership = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-multisig = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
@@ -118,7 +118,6 @@ std = [
"pallet-sudo/std",
"pallet-membership/std",
"pallet-mmr/std",
"pallet-mmr-primitives/std",
"pallet-indices/std",
"pallet-im-online/std",
"pallet-session/std",
@@ -137,6 +136,7 @@ std = [
"sp-api/std",
"sp-core/std",
"sp-io/std",
"sp-mmr-primitives/std",
"sp-runtime/std",
"sp-session/std",
"sp-staking/std",
+7 -3
View File
@@ -33,7 +33,6 @@ use frame_support::{
use frame_system::EnsureRoot;
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_mmr_primitives as mmr;
use pallet_session::historical as session_historical;
use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
@@ -51,6 +50,7 @@ use runtime_common::{
use runtime_parachains::{self, runtime_api_impl::v2 as runtime_api_impl};
use scale_info::TypeInfo;
use sp_core::{OpaqueMetadata, RuntimeDebug, H256};
use sp_mmr_primitives as mmr;
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{
@@ -1371,7 +1371,7 @@ sp_api::impl_runtime_apis! {
}
}
impl pallet_mmr_primitives::MmrApi<Block, Hash> for Runtime {
impl mmr::MmrApi<Block, Hash> for Runtime {
fn generate_proof(leaf_index: u64)
-> Result<(mmr::EncodableOpaqueLeaf, mmr::Proof<Hash>), mmr::Error>
{
@@ -1383,7 +1383,7 @@ sp_api::impl_runtime_apis! {
-> Result<(), mmr::Error>
{
pub type Leaf = <
<Runtime as pallet_mmr::Config>::LeafData as mmr::LeafDataProvider
<Runtime as pallet_mmr::Config>::LeafData as pallet_mmr::LeafDataProvider
>::LeafData;
let leaf: Leaf = leaf
@@ -1402,6 +1402,10 @@ sp_api::impl_runtime_apis! {
let node = mmr::DataOrHash::Data(leaf.into_opaque_leaf());
pallet_mmr::verify_leaf_proof::<MmrHashing, _>(root, node, proof)
}
fn mmr_root() -> Result<Hash, mmr::Error> {
Ok(Mmr::mmr_root())
}
}
impl bp_rococo::RococoFinalityApi<Block> for Runtime {