Skip to content

Commit

Permalink
Move grandpa pallet to bridge_common_config.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur committed Oct 20, 2023
1 parent 583dad3 commit a9e48b0
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus 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.

// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.

//! Bridge definitions that can be used by multiple BridgeHub flavors.
//! All configurations here should be dedicated to a single chain; in other words, we don't need two
//! chains for a single pallet configuration.
//!
//! For example, the messaging pallet needs to know the sending and receiving chains, but the
//! GRANDPA tracking pallet only needs to be aware of one chain.
use super::{weights, Runtime, RuntimeEvent};
use bp_parachains::SingleParaStoredHeaderDataBuilder;
use frame_support::{parameter_types, traits::ConstU32};

parameter_types! {
pub const RelayChainHeadersToKeep: u32 = 1024;
pub const ParachainHeadsToKeep: u32 = 64;

pub const RococoBridgeParachainPalletName: &'static str = "Paras";
pub const MaxRococoParaHeadDataSize: u32 = bp_rococo::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;
pub const WococoBridgeParachainPalletName: &'static str = "Paras";
pub const MaxWococoParaHeadDataSize: u32 = bp_wococo::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;
}

/// Add GRANDPA bridge pallet to track Wococo relay chain.
pub type BridgeGrandpaWococoInstance = pallet_bridge_grandpa::Instance1;
impl pallet_bridge_grandpa::Config<BridgeGrandpaWococoInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type BridgedChain = bp_wococo::Wococo;
type MaxFreeMandatoryHeadersPerBlock = ConstU32<4>;
type HeadersToKeep = RelayChainHeadersToKeep;
type WeightInfo = weights::pallet_bridge_grandpa_bridge_wococo_grandpa::WeightInfo<Runtime>;
}

/// Add parachain bridge pallet to track Wococo BridgeHub parachain
pub type BridgeParachainWococoInstance = pallet_bridge_parachains::Instance1;
impl pallet_bridge_parachains::Config<BridgeParachainWococoInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_bridge_parachains_bridge_parachains_bench_runtime_bridge_parachain_wococo_instance::WeightInfo<Runtime>;
type BridgesGrandpaPalletInstance = BridgeGrandpaWococoInstance;
type ParasPalletName = WococoBridgeParachainPalletName;
type ParaStoredHeaderDataBuilder =
SingleParaStoredHeaderDataBuilder<bp_bridge_hub_wococo::BridgeHubWococo>;
type HeadsToKeep = ParachainHeadsToKeep;
type MaxParaHeadDataSize = MaxWococoParaHeadDataSize;
}

/// Add GRANDPA bridge pallet to track Rococo relay chain.
pub type BridgeGrandpaRococoInstance = pallet_bridge_grandpa::Instance2;
impl pallet_bridge_grandpa::Config<BridgeGrandpaRococoInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type BridgedChain = bp_rococo::Rococo;
type MaxFreeMandatoryHeadersPerBlock = ConstU32<4>;
type HeadersToKeep = RelayChainHeadersToKeep;
type WeightInfo = weights::pallet_bridge_grandpa_bridge_rococo_grandpa::WeightInfo<Runtime>;
}

/// Add parachain bridge pallet to track Rococo BridgeHub parachain
pub type BridgeParachainRococoInstance = pallet_bridge_parachains::Instance2;
impl pallet_bridge_parachains::Config<BridgeParachainRococoInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_bridge_parachains_bridge_parachains_bench_runtime_bridge_parachain_rococo_instance::WeightInfo<Runtime>;
type BridgesGrandpaPalletInstance = BridgeGrandpaRococoInstance;
type ParasPalletName = RococoBridgeParachainPalletName;
type ParaStoredHeaderDataBuilder =
SingleParaStoredHeaderDataBuilder<bp_bridge_hub_rococo::BridgeHubRococo>;
type HeadsToKeep = ParachainHeadsToKeep;
type MaxParaHeadDataSize = MaxRococoParaHeadDataSize;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
//! Bridge definitions that are used on Rococo to bridge with Wococo.
use crate::{
BridgeParachainWococoInstance, BridgeWococoMessages, ParachainInfo, Runtime,
WithBridgeHubWococoMessagesInstance, XcmRouter,
bridge_common_config::BridgeParachainWococoInstance, BridgeWococoMessages, ParachainInfo,
Runtime, WithBridgeHubWococoMessagesInstance, XcmRouter,
};
use bp_messages::LaneId;
use bridge_runtime_common::{
Expand Down Expand Up @@ -185,7 +185,7 @@ parameter_types! {
#[cfg(test)]
mod tests {
use super::*;
use crate::BridgeGrandpaWococoInstance;
use crate::bridge_common_config::BridgeGrandpaWococoInstance;
use bridge_runtime_common::{
assert_complete_bridge_types,
integrity::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
//! Bridge definitions that are used on Wococo to bridge with Rococo.
use crate::{
BridgeParachainRococoInstance, BridgeRococoMessages, ParachainInfo, Runtime,
WithBridgeHubRococoMessagesInstance, XcmRouter,
bridge_common_config::BridgeParachainRococoInstance, BridgeRococoMessages, ParachainInfo,
Runtime, WithBridgeHubRococoMessagesInstance, XcmRouter,
};
use bp_messages::LaneId;
use bridge_runtime_common::{
Expand Down Expand Up @@ -185,7 +185,7 @@ parameter_types! {
#[cfg(test)]
mod tests {
use super::*;
use crate::BridgeGrandpaRococoInstance;
use crate::bridge_common_config::BridgeGrandpaRococoInstance;
use bridge_runtime_common::{
assert_complete_bridge_types,
integrity::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

pub mod bridge_common_config;
pub mod bridge_hub_rococo_config;
pub mod bridge_hub_wococo_config;
mod weights;
Expand Down Expand Up @@ -68,7 +69,6 @@ pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin};

use bp_parachains::SingleParaStoredHeaderDataBuilder;
use bp_runtime::HeaderId;

#[cfg(any(feature = "std", test))]
Expand Down Expand Up @@ -468,70 +468,14 @@ impl pallet_utility::Config for Runtime {
type WeightInfo = weights::pallet_utility::WeightInfo<Runtime>;
}

// Add bridge pallets (GPA)

/// Add GRANDPA bridge pallet to track Wococo relay chain on Rococo BridgeHub
pub type BridgeGrandpaWococoInstance = pallet_bridge_grandpa::Instance1;
impl pallet_bridge_grandpa::Config<BridgeGrandpaWococoInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type BridgedChain = bp_wococo::Wococo;
type MaxFreeMandatoryHeadersPerBlock = ConstU32<4>;
type HeadersToKeep = RelayChainHeadersToKeep;
type WeightInfo = weights::pallet_bridge_grandpa_bridge_wococo_grandpa::WeightInfo<Runtime>;
}

/// Add GRANDPA bridge pallet to track Rococo relay chain on Wococo BridgeHub
pub type BridgeGrandpaRococoInstance = pallet_bridge_grandpa::Instance2;
impl pallet_bridge_grandpa::Config<BridgeGrandpaRococoInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type BridgedChain = bp_rococo::Rococo;
type MaxFreeMandatoryHeadersPerBlock = ConstU32<4>;
type HeadersToKeep = RelayChainHeadersToKeep;
type WeightInfo = weights::pallet_bridge_grandpa_bridge_rococo_grandpa::WeightInfo<Runtime>;
}

parameter_types! {
pub const RelayChainHeadersToKeep: u32 = 1024;
pub const ParachainHeadsToKeep: u32 = 64;
pub const RelayerStakeLease: u32 = 8;

pub const RococoBridgeParachainPalletName: &'static str = "Paras";
pub const WococoBridgeParachainPalletName: &'static str = "Paras";
pub const MaxRococoParaHeadDataSize: u32 = bp_rococo::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;
pub const MaxWococoParaHeadDataSize: u32 = bp_wococo::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;

pub storage DeliveryRewardInBalance: u64 = 1_000_000;
pub storage RequiredStakeForStakeAndSlash: Balance = 1_000_000;

pub const RelayerStakeLease: u32 = 8;
pub const RelayerStakeReserveId: [u8; 8] = *b"brdgrlrs";
}

/// Add parachain bridge pallet to track Wococo BridgeHub parachain
pub type BridgeParachainWococoInstance = pallet_bridge_parachains::Instance1;
impl pallet_bridge_parachains::Config<BridgeParachainWococoInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_bridge_parachains_bridge_parachains_bench_runtime_bridge_parachain_wococo_instance::WeightInfo<Runtime>;
type BridgesGrandpaPalletInstance = BridgeGrandpaWococoInstance;
type ParasPalletName = WococoBridgeParachainPalletName;
type ParaStoredHeaderDataBuilder =
SingleParaStoredHeaderDataBuilder<bp_bridge_hub_wococo::BridgeHubWococo>;
type HeadsToKeep = ParachainHeadsToKeep;
type MaxParaHeadDataSize = MaxWococoParaHeadDataSize;
}

/// Add parachain bridge pallet to track Rococo BridgeHub parachain
pub type BridgeParachainRococoInstance = pallet_bridge_parachains::Instance2;
impl pallet_bridge_parachains::Config<BridgeParachainRococoInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_bridge_parachains_bridge_parachains_bench_runtime_bridge_parachain_rococo_instance::WeightInfo<Runtime>;
type BridgesGrandpaPalletInstance = BridgeGrandpaRococoInstance;
type ParasPalletName = RococoBridgeParachainPalletName;
type ParaStoredHeaderDataBuilder =
SingleParaStoredHeaderDataBuilder<bp_bridge_hub_rococo::BridgeHubRococo>;
type HeadsToKeep = ParachainHeadsToKeep;
type MaxParaHeadDataSize = MaxRococoParaHeadDataSize;
}

/// Add XCM messages support for BridgeHubRococo to support Rococo->Wococo XCM messages
pub type WithBridgeHubWococoMessagesInstance = pallet_bridge_messages::Instance1;
impl pallet_bridge_messages::Config<WithBridgeHubWococoMessagesInstance> for Runtime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

use super::{
AccountId, AllPalletsWithSystem, Balances, BaseDeliveryFee, BridgeGrandpaRococoInstance,
BridgeGrandpaWococoInstance, DeliveryRewardInBalance, FeeAssetId, ParachainInfo,
ParachainSystem, PolkadotXcm, RequiredStakeForStakeAndSlash, Runtime, RuntimeCall,
RuntimeEvent, RuntimeFlavor, RuntimeOrigin, TransactionByteFee, WeightToFee, XcmpQueue,
AccountId, AllPalletsWithSystem, Balances, BaseDeliveryFee, DeliveryRewardInBalance,
FeeAssetId, ParachainInfo, ParachainSystem, PolkadotXcm, RequiredStakeForStakeAndSlash,
Runtime, RuntimeCall, RuntimeEvent, RuntimeFlavor, RuntimeOrigin, TransactionByteFee,
WeightToFee, XcmpQueue,
};
use crate::{
bridge_common_config::{BridgeGrandpaRococoInstance, BridgeGrandpaWococoInstance},
bridge_hub_rococo_config::ToBridgeHubWococoHaulBlobExporter,
bridge_hub_wococo_config::ToBridgeHubRococoHaulBlobExporter,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use bp_polkadot_core::Signature;
use bridge_hub_rococo_runtime::{
bridge_hub_rococo_config, bridge_hub_wococo_config,
bridge_common_config, bridge_hub_rococo_config, bridge_hub_wococo_config,
xcm_config::{RelayNetwork, TokenLocation, XcmConfig},
AllPalletsWithoutSystem, BridgeRejectObsoleteHeadersAndMessages, DeliveryRewardInBalance,
Executive, ExistentialDeposit, ParachainSystem, PolkadotXcm, RequiredStakeForStakeAndSlash,
Expand Down Expand Up @@ -95,13 +95,11 @@ fn collator_session_keys() -> bridge_hub_test_utils::CollatorSessionKeys<Runtime

mod bridge_hub_rococo_tests {
use super::*;
use bridge_common_config::{BridgeGrandpaWococoInstance, BridgeParachainWococoInstance};
use bridge_hub_rococo_config::{
WithBridgeHubWococoMessageBridge, DEFAULT_XCM_LANE_TO_BRIDGE_HUB_WOCOCO,
};
use bridge_hub_rococo_runtime::{
BridgeGrandpaWococoInstance, BridgeParachainWococoInstance,
WithBridgeHubWococoMessagesInstance,
};
use bridge_hub_rococo_runtime::WithBridgeHubWococoMessagesInstance;

bridge_hub_test_utils::test_cases::include_teleports_for_native_asset_works!(
Runtime,
Expand Down Expand Up @@ -299,9 +297,9 @@ mod bridge_hub_rococo_tests {

mod bridge_hub_wococo_tests {
use super::*;
use bridge_common_config::{BridgeGrandpaRococoInstance, BridgeParachainRococoInstance};
use bridge_hub_rococo_runtime::{
xcm_config, AllPalletsWithoutSystem, BridgeGrandpaRococoInstance,
BridgeParachainRococoInstance, RuntimeFlavor, WithBridgeHubRococoMessagesInstance,
xcm_config, AllPalletsWithoutSystem, RuntimeFlavor, WithBridgeHubRococoMessagesInstance,
};
use bridge_hub_wococo_config::{
WithBridgeHubRococoMessageBridge, DEFAULT_XCM_LANE_TO_BRIDGE_HUB_ROCOCO,
Expand Down

0 comments on commit a9e48b0

Please sign in to comment.