mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 05:38:00 +00:00
Refactor beefy-mmr implementation (#4719)
* update pallet-beefy-mmr implementation
* minor fix
* fix build
* use H256 for rococo leaf extra
* update lockfile for {"substrate"}
* fix fmt
Co-authored-by: acatangiu <adrian@parity.io>
This commit is contained in:
Generated
+164
-163
File diff suppressed because it is too large
Load Diff
@@ -32,7 +32,7 @@ pub mod rialto_messages;
|
||||
|
||||
use crate::rialto_messages::{ToRialtoMessagePayload, WithRialtoMessageBridge};
|
||||
|
||||
use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet};
|
||||
use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::{MmrLeafVersion}, ValidatorSet};
|
||||
use bridge_runtime_common::messages::{
|
||||
source::estimate_message_dispatch_and_delivery_fee, MessageBridge,
|
||||
};
|
||||
@@ -281,7 +281,7 @@ parameter_types! {
|
||||
impl pallet_beefy_mmr::Config for Runtime {
|
||||
type LeafVersion = LeafVersion;
|
||||
type BeefyAuthorityToMerkleLeaf = pallet_beefy_mmr::BeefyEcdsaToEthereum;
|
||||
type ParachainHeads = ();
|
||||
type BeefyDataProvider = ();
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
|
||||
@@ -33,7 +33,7 @@ pub mod parachains;
|
||||
|
||||
use crate::millau_messages::{ToMillauMessagePayload, WithMillauMessageBridge};
|
||||
|
||||
use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet};
|
||||
use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::{MmrLeafVersion}, ValidatorSet};
|
||||
use bridge_runtime_common::messages::{
|
||||
source::estimate_message_dispatch_and_delivery_fee, MessageBridge,
|
||||
};
|
||||
@@ -280,10 +280,12 @@ impl pallet_grandpa::Config for Runtime {
|
||||
type MaxAuthorities = MaxAuthorities;
|
||||
}
|
||||
|
||||
type MmrHash = <Keccak256 as sp_runtime::traits::Hash>::Output;
|
||||
|
||||
impl pallet_mmr::Config for Runtime {
|
||||
const INDEXING_PREFIX: &'static [u8] = b"mmr";
|
||||
type Hashing = Keccak256;
|
||||
type Hash = <Keccak256 as sp_runtime::traits::Hash>::Output;
|
||||
type Hash = MmrHash;
|
||||
type OnNewRoot = pallet_beefy_mmr::DepositBeefyDigest<Runtime>;
|
||||
type WeightInfo = ();
|
||||
type LeafData = pallet_beefy_mmr::Pallet<Runtime>;
|
||||
@@ -309,7 +311,7 @@ parameter_types! {
|
||||
impl pallet_beefy_mmr::Config for Runtime {
|
||||
type LeafVersion = LeafVersion;
|
||||
type BeefyAuthorityToMerkleLeaf = pallet_beefy_mmr::BeefyEcdsaToEthereum;
|
||||
type ParachainHeads = ();
|
||||
type BeefyDataProvider = ();
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
|
||||
@@ -30,6 +30,7 @@ offchain-primitives = { package = "sp-offchain", git = "https://github.com/parit
|
||||
|
||||
babe-primitives = { package = "sp-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
beefy-merkle-tree = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
frame-executive = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
pallet-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
|
||||
@@ -21,7 +21,10 @@
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
|
||||
use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion};
|
||||
use beefy_primitives::{
|
||||
crypto::AuthorityId as BeefyId,
|
||||
mmr::{BeefyDataProvider, MmrLeafVersion},
|
||||
};
|
||||
use frame_support::{
|
||||
construct_runtime, parameter_types,
|
||||
traits::{Contains, InstanceFilter, KeyOwnerProofSystem},
|
||||
@@ -47,7 +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};
|
||||
use sp_core::{OpaqueMetadata, RuntimeDebug, H256};
|
||||
use sp_runtime::{
|
||||
create_runtime_str, generic, impl_opaque_keys,
|
||||
traits::{
|
||||
@@ -673,25 +676,17 @@ impl pallet_beefy::Config for Runtime {
|
||||
type BeefyId = BeefyId;
|
||||
}
|
||||
|
||||
type MmrHash = <Keccak256 as sp_runtime::traits::Hash>::Output;
|
||||
|
||||
impl pallet_mmr::Config for Runtime {
|
||||
const INDEXING_PREFIX: &'static [u8] = b"mmr";
|
||||
type Hashing = Keccak256;
|
||||
type Hash = <Keccak256 as sp_runtime::traits::Hash>::Output;
|
||||
type Hash = MmrHash;
|
||||
type OnNewRoot = pallet_beefy_mmr::DepositBeefyDigest<Runtime>;
|
||||
type WeightInfo = ();
|
||||
type LeafData = pallet_beefy_mmr::Pallet<Runtime>;
|
||||
}
|
||||
|
||||
pub struct ParasProvider;
|
||||
impl pallet_beefy_mmr::ParachainHeadsProvider for ParasProvider {
|
||||
fn parachain_heads() -> Vec<(u32, Vec<u8>)> {
|
||||
Paras::parachains()
|
||||
.into_iter()
|
||||
.filter_map(|id| Paras::para_head(&id).map(|head| (id.into(), head.0)))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
/// Version of the produced MMR leaf.
|
||||
///
|
||||
@@ -709,10 +704,26 @@ parameter_types! {
|
||||
pub LeafVersion: MmrLeafVersion = MmrLeafVersion::new(0, 0);
|
||||
}
|
||||
|
||||
pub struct ParasProvider;
|
||||
impl BeefyDataProvider<H256> for ParasProvider {
|
||||
fn extra_data() -> H256 {
|
||||
let mut para_heads: Vec<(u32, Vec<u8>)> = Paras::parachains()
|
||||
.into_iter()
|
||||
.filter_map(|id| Paras::para_head(&id).map(|head| (id.into(), head.0)))
|
||||
.collect();
|
||||
para_heads.sort();
|
||||
beefy_merkle_tree::merkle_root::<pallet_beefy_mmr::Pallet<Runtime>, _, _>(
|
||||
para_heads.into_iter().map(|pair| pair.encode()),
|
||||
)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl pallet_beefy_mmr::Config for Runtime {
|
||||
type LeafVersion = LeafVersion;
|
||||
type BeefyAuthorityToMerkleLeaf = pallet_beefy_mmr::BeefyEcdsaToEthereum;
|
||||
type ParachainHeads = ParasProvider;
|
||||
type LeafExtra = H256;
|
||||
type BeefyDataProvider = ParasProvider;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
|
||||
Reference in New Issue
Block a user