Skip to content

Commit 59882a7

Browse files
svyatonikbkchr
authored andcommitted
Added Rococo BH <> Rococo Bulletin bridge (#2724)
* added Rococo BH <> Rococo Bulletin bridge * init-bridge support * allow customising finality-related runtime APIs * revert me * use Rococo/BridgeHubRococo pretending to be a Polkadot/BridgeHubPolkadot in Rococo <> RococoBulletin bridge * Revert "revert me" This reverts commit 90c598d9d50a25e7182c97eee7818bf8d4bc404c. * Revert "allow customising finality-related runtime APIs" This reverts commit b39c32c34acddfd0b919042122e0e667470bd0a4. * fmt * WITH_BRIDGE_ROCOCO_TO_BULLETIN_MESSAGES_PALLET_INDEX * regenerate bulletin chain runtime (pallet indices have changed) * fx WITH_BRIDGE_ROCOCO_TO_BULLETIN_MESSAGES_PALLET_INDEX constant because of latest changes * also change indices in runtime * fmt * clippy
1 parent e711c9a commit 59882a7

File tree

24 files changed

+2077
-495
lines changed

24 files changed

+2077
-495
lines changed

bridges/modules/beefy/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub fn validator_ids(index: u32, count: u32) -> Vec<BeefyId> {
163163
validator_pairs(index, count).into_iter().map(|pair| pair.public()).collect()
164164
}
165165

166-
pub fn authority_set_info(id: u64, validators: &Vec<BeefyId>) -> TestBridgedAuthoritySetInfo {
166+
pub fn authority_set_info(id: u64, validators: &[BeefyId]) -> TestBridgedAuthoritySetInfo {
167167
let merkle_root = get_authorities_mmr_root::<TestRuntime, (), _>(validators.iter());
168168

169169
TestBridgedAuthoritySetInfo { id, len: validators.len() as u32, keyset_commitment: merkle_root }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ pub const WITH_BRIDGE_HUB_ROCOCO_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";
7676

7777
/// Pallet index of `BridgeWestendMessages: pallet_bridge_messages::<Instance3>`.
7878
pub const WITH_BRIDGE_ROCOCO_TO_WESTEND_MESSAGES_PALLET_INDEX: u8 = 51;
79+
/// Pallet index of `BridgePolkadotBulletinMessages: pallet_bridge_messages::<Instance4>`.
80+
pub const WITH_BRIDGE_ROCOCO_TO_BULLETIN_MESSAGES_PALLET_INDEX: u8 = 61;
7981

8082
decl_bridge_finality_runtime_apis!(bridge_hub_rococo);
8183
decl_bridge_messages_runtime_apis!(bridge_hub_rococo);

bridges/primitives/runtime/src/chain.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use crate::HeaderIdProvider;
18-
use codec::{Decode, Encode, MaxEncodedLen};
18+
use codec::{Codec, Decode, Encode, MaxEncodedLen};
1919
use frame_support::{weights::Weight, Parameter};
2020
use num_traits::{AsPrimitive, Bounded, CheckedSub, Saturating, SaturatingAdd, Zero};
2121
use sp_runtime::{
@@ -39,7 +39,7 @@ pub enum EncodedOrDecodedCall<ChainCall> {
3939
Decoded(ChainCall),
4040
}
4141

42-
impl<ChainCall: Clone + Decode> EncodedOrDecodedCall<ChainCall> {
42+
impl<ChainCall: Clone + Codec> EncodedOrDecodedCall<ChainCall> {
4343
/// Returns decoded call.
4444
pub fn to_decoded(&self) -> Result<ChainCall, codec::Error> {
4545
match self {
@@ -57,6 +57,14 @@ impl<ChainCall: Clone + Decode> EncodedOrDecodedCall<ChainCall> {
5757
Self::Decoded(decoded_call) => Ok(decoded_call),
5858
}
5959
}
60+
61+
/// Converts self to encoded call.
62+
pub fn into_encoded(self) -> Vec<u8> {
63+
match self {
64+
Self::Encoded(encoded_call) => encoded_call,
65+
Self::Decoded(decoded_call) => decoded_call.encode(),
66+
}
67+
}
6068
}
6169

6270
impl<ChainCall> From<ChainCall> for EncodedOrDecodedCall<ChainCall> {

bridges/relays/bin-substrate/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ signal-hook-async-std = "0.2.2"
2323
strum = { version = "0.25.0", features = ["derive"] }
2424

2525
# Bridge dependencies
26+
bp-bridge-hub-polkadot = { path = "../../primitives/chain-bridge-hub-polkadot" }
27+
bp-bridge-hub-rococo = { path = "../../primitives/chain-bridge-hub-rococo" }
2628
bp-header-chain = { path = "../../primitives/header-chain" }
2729
bp-messages = { path = "../../primitives/messages" }
2830
bp-parachains = { path = "../../primitives/parachains" }
2931
bp-polkadot-bulletin = { path = "../../primitives/chain-polkadot-bulletin" }
32+
bp-polkadot = { path = "../../primitives/chain-polkadot" }
3033
bp-polkadot-core = { path = "../../primitives/polkadot-core" }
34+
bp-rococo = { path = "../../primitives/chain-rococo" }
3135
bp-runtime = { path = "../../primitives/runtime" }
3236
bridge-runtime-common = { path = "../../bin/runtime-common" }
3337
pallet-bridge-parachains = { path = "../../modules/parachains" }

bridges/relays/bin-substrate/src/bridges/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
1919
pub mod kusama_polkadot;
2020
pub mod polkadot_bulletin;
21+
pub mod rococo_bulletin;
2122
pub mod rococo_westend;

bridges/relays/bin-substrate/src/bridges/polkadot_bulletin/bridge_hub_polkadot_messages_to_polkadot_bulletin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ impl MessagesCliBridge for BridgeHubPolkadotToPolkadotBulletinMessagesCliBridge
3636
substrate_relay_helper::generate_receive_message_proof_call_builder!(
3737
BridgeHubPolkadotMessagesToPolkadotBulletinMessageLane,
3838
BridgeHubPolkadotMessagesToPolkadotBulletinMessageLaneReceiveMessagesProofCallBuilder,
39-
relay_polkadot_bulletin_client::RuntimeCall::BridgePolkadotBridgeHubMessages,
40-
relay_polkadot_bulletin_client::BridgePolkadotBridgeHubMessagesCall::receive_messages_proof
39+
relay_polkadot_bulletin_client::RuntimeCall::BridgePolkadotMessages,
40+
relay_polkadot_bulletin_client::BridgePolkadotMessagesCall::receive_messages_proof
4141
);
4242

4343
substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(

bridges/relays/bin-substrate/src/bridges/polkadot_bulletin/polkadot_bulletin_messages_to_bridge_hub_polkadot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ substrate_relay_helper::generate_receive_message_proof_call_builder!(
4343
substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
4444
PolkadotBulletinMessagesToBridgeHubPolkadotMessageLane,
4545
PolkadotBulletinMessagesToBridgeHubPolkadotMessageLaneReceiveMessagesDeliveryProofCallBuilder,
46-
relay_polkadot_bulletin_client::RuntimeCall::BridgePolkadotBridgeHubMessages,
47-
relay_polkadot_bulletin_client::BridgePolkadotBridgeHubMessagesCall::receive_messages_delivery_proof
46+
relay_polkadot_bulletin_client::RuntimeCall::BridgePolkadotMessages,
47+
relay_polkadot_bulletin_client::BridgePolkadotMessagesCall::receive_messages_delivery_proof
4848
);
4949

5050
/// PolkadotBulletin-to-BridgeHubPolkadot messages lane.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2022 Parity Technologies (UK) Ltd.
2+
// This file is part of Parity Bridges Common.
3+
4+
// Parity Bridges Common 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+
// Parity Bridges Common 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 Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//! BridgeHubRococo-to-RococoBulletin messages sync entrypoint.
18+
19+
use super::BridgeHubRococoAsBridgeHubPolkadot;
20+
use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
21+
use relay_polkadot_bulletin_client::PolkadotBulletin as RococoBulletin;
22+
use substrate_relay_helper::{messages_lane::SubstrateMessageLane, UtilityPalletBatchCallBuilder};
23+
24+
/// BridgeHubRococo-to-RococoBulletin messages bridge.
25+
pub struct BridgeHubRococoToRococoBulletinMessagesCliBridge {}
26+
27+
impl CliBridgeBase for BridgeHubRococoToRococoBulletinMessagesCliBridge {
28+
type Source = BridgeHubRococoAsBridgeHubPolkadot;
29+
type Target = RococoBulletin;
30+
}
31+
32+
impl MessagesCliBridge for BridgeHubRococoToRococoBulletinMessagesCliBridge {
33+
type MessagesLane = BridgeHubRococoMessagesToRococoBulletinMessageLane;
34+
}
35+
36+
substrate_relay_helper::generate_receive_message_proof_call_builder!(
37+
BridgeHubRococoMessagesToRococoBulletinMessageLane,
38+
BridgeHubRococoMessagesToRococoBulletinMessageLaneReceiveMessagesProofCallBuilder,
39+
relay_polkadot_bulletin_client::RuntimeCall::BridgePolkadotMessages,
40+
relay_polkadot_bulletin_client::BridgePolkadotMessagesCall::receive_messages_proof
41+
);
42+
43+
substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
44+
BridgeHubRococoMessagesToRococoBulletinMessageLane,
45+
BridgeHubRococoMessagesToRococoBulletinMessageLaneReceiveMessagesDeliveryProofCallBuilder,
46+
relay_bridge_hub_rococo_client::RuntimeCall::BridgePolkadotBulletinMessages,
47+
relay_bridge_hub_rococo_client::BridgeBulletinMessagesCall::receive_messages_delivery_proof
48+
);
49+
50+
/// BridgeHubRococo-to-RococoBulletin messages lane.
51+
#[derive(Clone, Debug)]
52+
pub struct BridgeHubRococoMessagesToRococoBulletinMessageLane;
53+
54+
impl SubstrateMessageLane for BridgeHubRococoMessagesToRococoBulletinMessageLane {
55+
type SourceChain = BridgeHubRococoAsBridgeHubPolkadot;
56+
type TargetChain = RococoBulletin;
57+
58+
type ReceiveMessagesProofCallBuilder =
59+
BridgeHubRococoMessagesToRococoBulletinMessageLaneReceiveMessagesProofCallBuilder;
60+
type ReceiveMessagesDeliveryProofCallBuilder =
61+
BridgeHubRococoMessagesToRococoBulletinMessageLaneReceiveMessagesDeliveryProofCallBuilder;
62+
63+
type SourceBatchCallBuilder = UtilityPalletBatchCallBuilder<BridgeHubRococoAsBridgeHubPolkadot>;
64+
type TargetBatchCallBuilder = ();
65+
}

0 commit comments

Comments
 (0)