Skip to content

Commit e0620fd

Browse files
authored
[testnet] BridgeHubRococo nits (#1972)
This PR does not introduce any functional changes to the existing code, it merely addresses several minor refactors: - Moving bridging pallets to separate files. - Improving the readability and naming of weight files for bridging pallets and bridging pallet instances. The reason for this refactor is to facilitate easier plugin integration for the upcoming bridge between Rococo and Westend. --------- Co-authored-by: command-bot <>
1 parent c284a93 commit e0620fd

File tree

22 files changed

+547
-481
lines changed

22 files changed

+547
-481
lines changed

bridges/primitives/chain-bridge-hub-rococo/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,15 @@ pub type Address = MultiAddress<AccountId, ()>;
6868
pub const BRIDGE_HUB_ROCOCO_PARACHAIN_ID: u32 = 1013;
6969

7070
/// Name of the With-BridgeHubRococo messages pallet instance that is deployed at bridged chains.
71-
pub const WITH_BRIDGE_HUB_ROCOCO_MESSAGES_PALLET_NAME: &str = "BridgeRococoMessages";
71+
pub const WITH_BRIDGE_HUB_WOCOCO_TO_ROCOCO_MESSAGES_PALLET_NAME: &str =
72+
"BridgeWococoToRococoMessages";
7273

7374
/// Name of the With-BridgeHubRococo bridge-relayers pallet instance that is deployed at bridged
7475
/// chains.
7576
pub const WITH_BRIDGE_HUB_ROCOCO_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";
7677

77-
/// Pallet index of `BridgeWococoMessages: pallet_bridge_messages::<Instance1>`.
78-
pub const WITH_BRIDGE_WOCOCO_MESSAGES_PALLET_INDEX: u8 = 46;
78+
/// Pallet index of `BridgeRococoToWococoMessages: pallet_bridge_messages::<Instance1>`.
79+
pub const WITH_BRIDGE_ROCOCO_TO_WOCOCO_MESSAGES_PALLET_INDEX: u8 = 46;
7980

8081
decl_bridge_finality_runtime_apis!(bridge_hub_rococo);
8182
decl_bridge_messages_runtime_apis!(bridge_hub_rococo);

bridges/primitives/chain-bridge-hub-wococo/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ impl Parachain for BridgeHubWococo {
6262
pub const BRIDGE_HUB_WOCOCO_PARACHAIN_ID: u32 = 1014;
6363

6464
/// Name of the With-BridgeHubWococo messages pallet instance that is deployed at bridged chains.
65-
pub const WITH_BRIDGE_HUB_WOCOCO_MESSAGES_PALLET_NAME: &str = "BridgeWococoMessages";
65+
pub const WITH_BRIDGE_HUB_ROCOCO_TO_WOCOCO_MESSAGES_PALLET_NAME: &str =
66+
"BridgeRococoToWococoMessages";
6667

6768
/// Name of the With-BridgeHubWococo bridge-relayers pallet instance that is deployed at bridged
6869
/// chains.
6970
pub const WITH_BRIDGE_HUB_WOCOCO_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";
7071

71-
/// Pallet index of `BridgeRococoMessages: pallet_bridge_messages::<Instance2>`.
72-
pub const WITH_BRIDGE_ROCOCO_MESSAGES_PALLET_INDEX: u8 = 45;
72+
/// Pallet index of `BridgeWococoToRococoMessages: pallet_bridge_messages::<Instance2>`.
73+
pub const WITH_BRIDGE_WOCOCO_TO_ROCOCO_MESSAGES_PALLET_INDEX: u8 = 45;
7374

7475
decl_bridge_finality_runtime_apis!(bridge_hub_wococo);
7576
decl_bridge_messages_runtime_apis!(bridge_hub_wococo);

cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn example() {
6464
outcome: Outcome::Complete(_),
6565
..
6666
}) => {},
67-
RuntimeEvent::BridgeWococoMessages(pallet_bridge_messages::Event::MessageAccepted {
67+
RuntimeEvent::BridgeRococoToWococoMessages(pallet_bridge_messages::Event::MessageAccepted {
6868
lane_id: LaneId([0, 0, 0, 1]),
6969
nonce: 1,
7070
}) => {},

cumulus/parachains/integration-tests/emulated/common/src/constants.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -669,14 +669,16 @@ pub mod bridge_hub_rococo {
669669
owner: Some(get_account_id_from_seed::<sr25519::Public>(accounts::BOB)),
670670
..Default::default()
671671
},
672-
bridge_rococo_messages: bridge_hub_rococo_runtime::BridgeRococoMessagesConfig {
673-
owner: Some(get_account_id_from_seed::<sr25519::Public>(accounts::BOB)),
674-
..Default::default()
675-
},
676-
bridge_wococo_messages: bridge_hub_rococo_runtime::BridgeWococoMessagesConfig {
677-
owner: Some(get_account_id_from_seed::<sr25519::Public>(accounts::BOB)),
678-
..Default::default()
679-
},
672+
bridge_wococo_to_rococo_messages:
673+
bridge_hub_rococo_runtime::BridgeWococoToRococoMessagesConfig {
674+
owner: Some(get_account_id_from_seed::<sr25519::Public>(accounts::BOB)),
675+
..Default::default()
676+
},
677+
bridge_rococo_to_wococo_messages:
678+
bridge_hub_rococo_runtime::BridgeRococoToWococoMessagesConfig {
679+
owner: Some(get_account_id_from_seed::<sr25519::Public>(accounts::BOB)),
680+
..Default::default()
681+
},
680682
..Default::default()
681683
};
682684

cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ impl pallet_xcm_bridge_hub_router::Config<ToWococoXcmRouterInstance> for Runtime
838838

839839
type UniversalLocation = xcm_config::UniversalLocation;
840840
type BridgedNetworkId = xcm_config::bridging::to_wococo::WococoNetwork;
841-
type Bridges = xcm_config::bridging::to_wococo::NetworkExportTable;
841+
type Bridges = xcm_config::bridging::NetworkExportTable;
842842

843843
#[cfg(not(feature = "runtime-benchmarks"))]
844844
type BridgeHubOrigin = EnsureXcm<Equals<xcm_config::bridging::SiblingBridgeHub>>;
@@ -869,7 +869,7 @@ impl pallet_xcm_bridge_hub_router::Config<ToRococoXcmRouterInstance> for Runtime
869869

870870
type UniversalLocation = xcm_config::UniversalLocation;
871871
type BridgedNetworkId = xcm_config::bridging::to_rococo::RococoNetwork;
872-
type Bridges = xcm_config::bridging::to_rococo::NetworkExportTable;
872+
type Bridges = xcm_config::bridging::NetworkExportTable;
873873

874874
#[cfg(not(feature = "runtime-benchmarks"))]
875875
type BridgeHubOrigin = EnsureXcm<Equals<xcm_config::bridging::SiblingBridgeHub>>;

cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,16 @@ pub mod bridging {
763763
pub XcmBridgeHubRouterFeeAssetId: AssetId = TokenLocation::get().into();
764764
/// Price per byte - can be adjusted via governance `set_storage` call.
765765
pub storage XcmBridgeHubRouterByteFee: Balance = TransactionByteFee::get();
766+
767+
pub BridgeTable: sp_std::vec::Vec<NetworkExportTableItem> =
768+
sp_std::vec::Vec::new().into_iter()
769+
.chain(to_wococo::BridgeTable::get())
770+
.chain(to_rococo::BridgeTable::get())
771+
.collect();
766772
}
767773

774+
pub type NetworkExportTable = xcm_builder::NetworkExportTable<BridgeTable>;
775+
768776
pub mod to_wococo {
769777
use super::*;
770778

@@ -773,7 +781,7 @@ pub mod bridging {
773781
1,
774782
X2(
775783
Parachain(SiblingBridgeHubParaId::get()),
776-
PalletInstance(bp_bridge_hub_rococo::WITH_BRIDGE_WOCOCO_MESSAGES_PALLET_INDEX)
784+
PalletInstance(bp_bridge_hub_rococo::WITH_BRIDGE_ROCOCO_TO_WOCOCO_MESSAGES_PALLET_INDEX)
777785
)
778786
);
779787

@@ -824,8 +832,6 @@ pub mod bridging {
824832
}
825833
}
826834

827-
pub type NetworkExportTable = xcm_builder::NetworkExportTable<BridgeTable>;
828-
829835
/// Trusted reserve locations filter for `xcm_executor::Config::IsReserve`.
830836
/// Locations from which the runtime accepts reserved assets.
831837
pub type IsTrustedBridgedReserveLocationForConcreteAsset =
@@ -864,7 +870,7 @@ pub mod bridging {
864870
1,
865871
X2(
866872
Parachain(SiblingBridgeHubParaId::get()),
867-
PalletInstance(bp_bridge_hub_wococo::WITH_BRIDGE_ROCOCO_MESSAGES_PALLET_INDEX)
873+
PalletInstance(bp_bridge_hub_wococo::WITH_BRIDGE_WOCOCO_TO_ROCOCO_MESSAGES_PALLET_INDEX)
868874
)
869875
);
870876

@@ -915,8 +921,6 @@ pub mod bridging {
915921
}
916922
}
917923

918-
pub type NetworkExportTable = xcm_builder::NetworkExportTable<BridgeTable>;
919-
920924
/// Reserve locations filter for `xcm_executor::Config::IsReserve`.
921925
/// Locations from which the runtime accepts reserved assets.
922926
pub type IsTrustedBridgedReserveLocationForConcreteAsset =

cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ mod asset_hub_rococo_tests {
704704
(MultiLocation { parents: 2, interior: X1(GlobalConsensus(Wococo)) }, 1000000000000, 1_000_000_000),
705705
bridging_to_asset_hub_wococo,
706706
(
707-
X1(PalletInstance(bp_bridge_hub_rococo::WITH_BRIDGE_WOCOCO_MESSAGES_PALLET_INDEX)),
707+
X1(PalletInstance(bp_bridge_hub_rococo::WITH_BRIDGE_ROCOCO_TO_WOCOCO_MESSAGES_PALLET_INDEX)),
708708
GlobalConsensus(Wococo),
709709
X1(Parachain(1000))
710710
)
@@ -909,7 +909,7 @@ mod asset_hub_wococo_tests {
909909
(MultiLocation { parents: 2, interior: X1(GlobalConsensus(Rococo)) }, 1000000000000, 1_000_000_000),
910910
with_wococo_flavor_bridging_to_asset_hub_rococo,
911911
(
912-
X1(PalletInstance(bp_bridge_hub_wococo::WITH_BRIDGE_ROCOCO_MESSAGES_PALLET_INDEX)),
912+
X1(PalletInstance(bp_bridge_hub_wococo::WITH_BRIDGE_WOCOCO_TO_ROCOCO_MESSAGES_PALLET_INDEX)),
913913
GlobalConsensus(Rococo),
914914
X1(Parachain(1000))
915915
)

cumulus/parachains/runtimes/bridge-hubs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ cd <polkadot-sdk-git-repo-dir>
172172

173173
- open explorers: (see zombienets)
174174
- AssetHubRococo (see events `xcmpQueue.XcmpMessageSent`, `polkadotXcm.Attempted`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:9910#/explorer
175-
- BridgeHubRococo (see `bridgeWococoMessages.MessageAccepted`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer
176-
- BridgeHubWococo (see `bridgeRococoMessages.MessagesReceived`, `xcmpQueue.XcmpMessageSent`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8945#/explorer
175+
- BridgeHubRococo (see `bridgeRococoToWococoMessages.MessageAccepted`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer
176+
- BridgeHubWococo (see `bridgeWococoToRococoMessages.MessagesReceived`, `xcmpQueue.XcmpMessageSent`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8945#/explorer
177177
- AssetHubWococo (see `foreignAssets.Issued`, `xcmpQueue.Success`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:9010#/explorer
178-
- BridgeHubRocococ (see `bridgeWococoMessages.MessagesDelivered`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer
178+
- BridgeHubRocococ (see `bridgeRococoToWococoMessages.MessagesDelivered`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer
179179

180180
### Claim relayer's rewards on BridgeHubRococo and BridgeHubWococo
181181

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright (C) Parity Technologies (UK) Ltd.
2+
// This file is part of Cumulus.
3+
4+
// Cumulus is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Cumulus is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//! Bridge definitions that can be used by multiple BridgeHub flavors.
18+
//! All configurations here should be dedicated to a single chain; in other words, we don't need two
19+
//! chains for a single pallet configuration.
20+
//!
21+
//! For example, the messaging pallet needs to know the sending and receiving chains, but the
22+
//! GRANDPA tracking pallet only needs to be aware of one chain.
23+
24+
use super::{weights, AccountId, Balance, Balances, BlockNumber, Runtime, RuntimeEvent};
25+
use bp_parachains::SingleParaStoredHeaderDataBuilder;
26+
use frame_support::{parameter_types, traits::ConstU32};
27+
28+
parameter_types! {
29+
pub const RelayChainHeadersToKeep: u32 = 1024;
30+
pub const ParachainHeadsToKeep: u32 = 64;
31+
32+
pub const RococoBridgeParachainPalletName: &'static str = "Paras";
33+
pub const MaxRococoParaHeadDataSize: u32 = bp_rococo::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;
34+
pub const WococoBridgeParachainPalletName: &'static str = "Paras";
35+
pub const MaxWococoParaHeadDataSize: u32 = bp_wococo::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;
36+
37+
pub storage RequiredStakeForStakeAndSlash: Balance = 1_000_000;
38+
pub const RelayerStakeLease: u32 = 8;
39+
pub const RelayerStakeReserveId: [u8; 8] = *b"brdgrlrs";
40+
41+
pub storage DeliveryRewardInBalance: u64 = 1_000_000;
42+
}
43+
44+
/// Add GRANDPA bridge pallet to track Wococo relay chain.
45+
pub type BridgeGrandpaWococoInstance = pallet_bridge_grandpa::Instance1;
46+
impl pallet_bridge_grandpa::Config<BridgeGrandpaWococoInstance> for Runtime {
47+
type RuntimeEvent = RuntimeEvent;
48+
type BridgedChain = bp_wococo::Wococo;
49+
type MaxFreeMandatoryHeadersPerBlock = ConstU32<4>;
50+
type HeadersToKeep = RelayChainHeadersToKeep;
51+
type WeightInfo = weights::pallet_bridge_grandpa_wococo_finality::WeightInfo<Runtime>;
52+
}
53+
54+
/// Add parachain bridge pallet to track Wococo BridgeHub parachain
55+
pub type BridgeParachainWococoInstance = pallet_bridge_parachains::Instance1;
56+
impl pallet_bridge_parachains::Config<BridgeParachainWococoInstance> for Runtime {
57+
type RuntimeEvent = RuntimeEvent;
58+
type WeightInfo = weights::pallet_bridge_parachains_within_wococo::WeightInfo<Runtime>;
59+
type BridgesGrandpaPalletInstance = BridgeGrandpaWococoInstance;
60+
type ParasPalletName = WococoBridgeParachainPalletName;
61+
type ParaStoredHeaderDataBuilder =
62+
SingleParaStoredHeaderDataBuilder<bp_bridge_hub_wococo::BridgeHubWococo>;
63+
type HeadsToKeep = ParachainHeadsToKeep;
64+
type MaxParaHeadDataSize = MaxWococoParaHeadDataSize;
65+
}
66+
67+
/// Add GRANDPA bridge pallet to track Rococo relay chain.
68+
pub type BridgeGrandpaRococoInstance = pallet_bridge_grandpa::Instance2;
69+
impl pallet_bridge_grandpa::Config<BridgeGrandpaRococoInstance> for Runtime {
70+
type RuntimeEvent = RuntimeEvent;
71+
type BridgedChain = bp_rococo::Rococo;
72+
type MaxFreeMandatoryHeadersPerBlock = ConstU32<4>;
73+
type HeadersToKeep = RelayChainHeadersToKeep;
74+
type WeightInfo = weights::pallet_bridge_grandpa_rococo_finality::WeightInfo<Runtime>;
75+
}
76+
77+
/// Add parachain bridge pallet to track Rococo BridgeHub parachain
78+
pub type BridgeParachainRococoInstance = pallet_bridge_parachains::Instance2;
79+
impl pallet_bridge_parachains::Config<BridgeParachainRococoInstance> for Runtime {
80+
type RuntimeEvent = RuntimeEvent;
81+
type WeightInfo = weights::pallet_bridge_parachains_within_rococo::WeightInfo<Runtime>;
82+
type BridgesGrandpaPalletInstance = BridgeGrandpaRococoInstance;
83+
type ParasPalletName = RococoBridgeParachainPalletName;
84+
type ParaStoredHeaderDataBuilder =
85+
SingleParaStoredHeaderDataBuilder<bp_bridge_hub_rococo::BridgeHubRococo>;
86+
type HeadsToKeep = ParachainHeadsToKeep;
87+
type MaxParaHeadDataSize = MaxRococoParaHeadDataSize;
88+
}
89+
90+
/// Allows collect and claim rewards for relayers
91+
impl pallet_bridge_relayers::Config for Runtime {
92+
type RuntimeEvent = RuntimeEvent;
93+
type Reward = Balance;
94+
type PaymentProcedure =
95+
bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
96+
type StakeAndSlash = pallet_bridge_relayers::StakeAndSlashNamed<
97+
AccountId,
98+
BlockNumber,
99+
Balances,
100+
RelayerStakeReserveId,
101+
RequiredStakeForStakeAndSlash,
102+
RelayerStakeLease,
103+
>;
104+
type WeightInfo = weights::pallet_bridge_relayers::WeightInfo<Runtime>;
105+
}

0 commit comments

Comments
 (0)