mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 12:51:02 +00:00
Merge commit '114f487fd9daef4b4cd791446372a9a690c137ac' into update-bridges-subtree-r/w
This commit is contained in:
@@ -34,19 +34,23 @@ pub mod rialto_messages;
|
||||
|
||||
use crate::rialto_messages::{ToRialtoMessagePayload, WithRialtoMessageBridge};
|
||||
|
||||
use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet};
|
||||
use bridge_runtime_common::messages::{
|
||||
source::estimate_message_dispatch_and_delivery_fee, MessageBridge,
|
||||
};
|
||||
use pallet_grandpa::{
|
||||
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
|
||||
};
|
||||
use pallet_mmr_primitives::{
|
||||
DataOrHash, EncodableOpaqueLeaf, Error as MmrError, LeafDataProvider, Proof as MmrProof,
|
||||
};
|
||||
use pallet_transaction_payment::{FeeDetails, Multiplier, RuntimeDispatchInfo};
|
||||
use sp_api::impl_runtime_apis;
|
||||
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
||||
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
|
||||
use sp_runtime::{
|
||||
create_runtime_str, generic, impl_opaque_keys,
|
||||
traits::{Block as BlockT, IdentityLookup, NumberFor, OpaqueKeys},
|
||||
traits::{Block as BlockT, IdentityLookup, Keccak256, NumberFor, OpaqueKeys},
|
||||
transaction_validity::{TransactionSource, TransactionValidity},
|
||||
ApplyExtrinsicResult, FixedPointNumber, MultiSignature, MultiSigner, Perquintill,
|
||||
};
|
||||
@@ -100,9 +104,6 @@ pub type Hash = bp_millau::Hash;
|
||||
/// Hashing algorithm used by the chain.
|
||||
pub type Hashing = bp_millau::Hasher;
|
||||
|
||||
/// Digest item type.
|
||||
pub type DigestItem = generic::DigestItem<Hash>;
|
||||
|
||||
/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
|
||||
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
|
||||
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
|
||||
@@ -123,6 +124,7 @@ pub mod opaque {
|
||||
impl_opaque_keys! {
|
||||
pub struct SessionKeys {
|
||||
pub aura: Aura,
|
||||
pub beefy: Beefy,
|
||||
pub grandpa: Grandpa,
|
||||
}
|
||||
}
|
||||
@@ -215,6 +217,11 @@ impl pallet_aura::Config for Runtime {
|
||||
type MaxAuthorities = MaxAuthorities;
|
||||
type DisabledValidators = ();
|
||||
}
|
||||
|
||||
impl pallet_beefy::Config for Runtime {
|
||||
type BeefyId = BeefyId;
|
||||
}
|
||||
|
||||
impl pallet_bridge_dispatch::Config for Runtime {
|
||||
type Event = Event;
|
||||
type BridgeMessageId = (bp_messages::LaneId, bp_messages::MessageNonce);
|
||||
@@ -243,6 +250,40 @@ 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 = MmrHash;
|
||||
type OnNewRoot = pallet_beefy_mmr::DepositBeefyDigest<Runtime>;
|
||||
type WeightInfo = ();
|
||||
type LeafData = pallet_beefy_mmr::Pallet<Runtime>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
/// Version of the produced MMR leaf.
|
||||
///
|
||||
/// The version consists of two parts;
|
||||
/// - `major` (3 bits)
|
||||
/// - `minor` (5 bits)
|
||||
///
|
||||
/// `major` should be updated only if decoding the previous MMR Leaf format from the payload
|
||||
/// is not possible (i.e. backward incompatible change).
|
||||
/// `minor` should be updated if fields are added to the previous MMR Leaf, which given SCALE
|
||||
/// encoding does not prevent old leafs from being decoded.
|
||||
///
|
||||
/// Hence we expect `major` to be changed really rarely (think never).
|
||||
/// See [`MmrLeafVersion`] type documentation for more details.
|
||||
pub LeafVersion: MmrLeafVersion = MmrLeafVersion::new(0, 0);
|
||||
}
|
||||
|
||||
impl pallet_beefy_mmr::Config for Runtime {
|
||||
type LeafVersion = LeafVersion;
|
||||
type BeefyAuthorityToMerkleLeaf = pallet_beefy_mmr::BeefyEcdsaToEthereum;
|
||||
type ParachainHeads = ();
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const MinimumPeriod: u64 = bp_millau::SLOT_DURATION / 2;
|
||||
}
|
||||
@@ -462,6 +503,11 @@ construct_runtime!(
|
||||
ShiftSessionManager: pallet_shift_session_manager::{Pallet},
|
||||
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage},
|
||||
|
||||
// BEEFY Bridges support.
|
||||
Beefy: pallet_beefy::{Pallet, Storage, Config<T>},
|
||||
Mmr: pallet_mmr::{Pallet, Storage},
|
||||
MmrLeaf: pallet_beefy_mmr::{Pallet, Storage},
|
||||
|
||||
// Rialto bridge modules.
|
||||
BridgeRialtoGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage},
|
||||
BridgeDispatch: pallet_bridge_dispatch::{Pallet, Event<T>},
|
||||
@@ -606,6 +652,45 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl beefy_primitives::BeefyApi<Block> for Runtime {
|
||||
fn validator_set() -> ValidatorSet<BeefyId> {
|
||||
Beefy::validator_set()
|
||||
}
|
||||
}
|
||||
|
||||
impl pallet_mmr_primitives::MmrApi<Block, MmrHash> for Runtime {
|
||||
fn generate_proof(leaf_index: u64)
|
||||
-> Result<(EncodableOpaqueLeaf, MmrProof<MmrHash>), MmrError>
|
||||
{
|
||||
Mmr::generate_proof(leaf_index)
|
||||
.map(|(leaf, proof)| (EncodableOpaqueLeaf::from_leaf(&leaf), proof))
|
||||
}
|
||||
|
||||
fn verify_proof(leaf: EncodableOpaqueLeaf, proof: MmrProof<MmrHash>)
|
||||
-> Result<(), MmrError>
|
||||
{
|
||||
pub type Leaf = <
|
||||
<Runtime as pallet_mmr::Config>::LeafData as LeafDataProvider
|
||||
>::LeafData;
|
||||
|
||||
let leaf: Leaf = leaf
|
||||
.into_opaque_leaf()
|
||||
.try_decode()
|
||||
.ok_or(MmrError::Verify)?;
|
||||
Mmr::verify_leaf(leaf, proof)
|
||||
}
|
||||
|
||||
fn verify_proof_stateless(
|
||||
root: MmrHash,
|
||||
leaf: EncodableOpaqueLeaf,
|
||||
proof: MmrProof<MmrHash>
|
||||
) -> Result<(), MmrError> {
|
||||
type MmrHashing = <Runtime as pallet_mmr::Config>::Hashing;
|
||||
let node = DataOrHash::Data(leaf.into_opaque_leaf());
|
||||
pallet_mmr::verify_leaf_proof::<MmrHashing, _>(root, node, proof)
|
||||
}
|
||||
}
|
||||
|
||||
impl fg_primitives::GrandpaApi<Block> for Runtime {
|
||||
fn current_set_id() -> fg_primitives::SetId {
|
||||
Grandpa::current_set_id()
|
||||
|
||||
Reference in New Issue
Block a user