Skip to content

Commit

Permalink
Added Rococo BH <> Rococo Bulletin bridge (paritytech#2724)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
svyatonik authored and serban300 committed Apr 10, 2024
1 parent bc08cbf commit 5feb9ab
Show file tree
Hide file tree
Showing 24 changed files with 2,077 additions and 495 deletions.
2 changes: 1 addition & 1 deletion bridges/modules/beefy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub fn validator_ids(index: u32, count: u32) -> Vec<BeefyId> {
validator_pairs(index, count).into_iter().map(|pair| pair.public()).collect()
}

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

TestBridgedAuthoritySetInfo { id, len: validators.len() as u32, keyset_commitment: merkle_root }
Expand Down
2 changes: 2 additions & 0 deletions bridges/primitives/chain-bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pub const WITH_BRIDGE_HUB_ROCOCO_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";

/// Pallet index of `BridgeWestendMessages: pallet_bridge_messages::<Instance3>`.
pub const WITH_BRIDGE_ROCOCO_TO_WESTEND_MESSAGES_PALLET_INDEX: u8 = 51;
/// Pallet index of `BridgePolkadotBulletinMessages: pallet_bridge_messages::<Instance4>`.
pub const WITH_BRIDGE_ROCOCO_TO_BULLETIN_MESSAGES_PALLET_INDEX: u8 = 61;

decl_bridge_finality_runtime_apis!(bridge_hub_rococo);
decl_bridge_messages_runtime_apis!(bridge_hub_rococo);
Expand Down
12 changes: 10 additions & 2 deletions bridges/primitives/runtime/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.

use crate::HeaderIdProvider;
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Codec, Decode, Encode, MaxEncodedLen};
use frame_support::{weights::Weight, Parameter};
use num_traits::{AsPrimitive, Bounded, CheckedSub, Saturating, SaturatingAdd, Zero};
use sp_runtime::{
Expand All @@ -39,7 +39,7 @@ pub enum EncodedOrDecodedCall<ChainCall> {
Decoded(ChainCall),
}

impl<ChainCall: Clone + Decode> EncodedOrDecodedCall<ChainCall> {
impl<ChainCall: Clone + Codec> EncodedOrDecodedCall<ChainCall> {
/// Returns decoded call.
pub fn to_decoded(&self) -> Result<ChainCall, codec::Error> {
match self {
Expand All @@ -57,6 +57,14 @@ impl<ChainCall: Clone + Decode> EncodedOrDecodedCall<ChainCall> {
Self::Decoded(decoded_call) => Ok(decoded_call),
}
}

/// Converts self to encoded call.
pub fn into_encoded(self) -> Vec<u8> {
match self {
Self::Encoded(encoded_call) => encoded_call,
Self::Decoded(decoded_call) => decoded_call.encode(),
}
}
}

impl<ChainCall> From<ChainCall> for EncodedOrDecodedCall<ChainCall> {
Expand Down
4 changes: 4 additions & 0 deletions bridges/relays/bin-substrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ signal-hook-async-std = "0.2.2"
strum = { version = "0.25.0", features = ["derive"] }

# Bridge dependencies
bp-bridge-hub-polkadot = { path = "../../primitives/chain-bridge-hub-polkadot" }
bp-bridge-hub-rococo = { path = "../../primitives/chain-bridge-hub-rococo" }
bp-header-chain = { path = "../../primitives/header-chain" }
bp-messages = { path = "../../primitives/messages" }
bp-parachains = { path = "../../primitives/parachains" }
bp-polkadot-bulletin = { path = "../../primitives/chain-polkadot-bulletin" }
bp-polkadot = { path = "../../primitives/chain-polkadot" }
bp-polkadot-core = { path = "../../primitives/polkadot-core" }
bp-rococo = { path = "../../primitives/chain-rococo" }
bp-runtime = { path = "../../primitives/runtime" }
bridge-runtime-common = { path = "../../bin/runtime-common" }
pallet-bridge-parachains = { path = "../../modules/parachains" }
Expand Down
1 change: 1 addition & 0 deletions bridges/relays/bin-substrate/src/bridges/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@

pub mod kusama_polkadot;
pub mod polkadot_bulletin;
pub mod rococo_bulletin;
pub mod rococo_westend;
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ impl MessagesCliBridge for BridgeHubPolkadotToPolkadotBulletinMessagesCliBridge
substrate_relay_helper::generate_receive_message_proof_call_builder!(
BridgeHubPolkadotMessagesToPolkadotBulletinMessageLane,
BridgeHubPolkadotMessagesToPolkadotBulletinMessageLaneReceiveMessagesProofCallBuilder,
relay_polkadot_bulletin_client::RuntimeCall::BridgePolkadotBridgeHubMessages,
relay_polkadot_bulletin_client::BridgePolkadotBridgeHubMessagesCall::receive_messages_proof
relay_polkadot_bulletin_client::RuntimeCall::BridgePolkadotMessages,
relay_polkadot_bulletin_client::BridgePolkadotMessagesCall::receive_messages_proof
);

substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ substrate_relay_helper::generate_receive_message_proof_call_builder!(
substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
PolkadotBulletinMessagesToBridgeHubPolkadotMessageLane,
PolkadotBulletinMessagesToBridgeHubPolkadotMessageLaneReceiveMessagesDeliveryProofCallBuilder,
relay_polkadot_bulletin_client::RuntimeCall::BridgePolkadotBridgeHubMessages,
relay_polkadot_bulletin_client::BridgePolkadotBridgeHubMessagesCall::receive_messages_delivery_proof
relay_polkadot_bulletin_client::RuntimeCall::BridgePolkadotMessages,
relay_polkadot_bulletin_client::BridgePolkadotMessagesCall::receive_messages_delivery_proof
);

/// PolkadotBulletin-to-BridgeHubPolkadot messages lane.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2022 Parity Technologies (UK) Ltd.
// This file is part of Parity Bridges Common.

// Parity Bridges Common 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.

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

//! BridgeHubRococo-to-RococoBulletin messages sync entrypoint.

use super::BridgeHubRococoAsBridgeHubPolkadot;
use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
use relay_polkadot_bulletin_client::PolkadotBulletin as RococoBulletin;
use substrate_relay_helper::{messages_lane::SubstrateMessageLane, UtilityPalletBatchCallBuilder};

/// BridgeHubRococo-to-RococoBulletin messages bridge.
pub struct BridgeHubRococoToRococoBulletinMessagesCliBridge {}

impl CliBridgeBase for BridgeHubRococoToRococoBulletinMessagesCliBridge {
type Source = BridgeHubRococoAsBridgeHubPolkadot;
type Target = RococoBulletin;
}

impl MessagesCliBridge for BridgeHubRococoToRococoBulletinMessagesCliBridge {
type MessagesLane = BridgeHubRococoMessagesToRococoBulletinMessageLane;
}

substrate_relay_helper::generate_receive_message_proof_call_builder!(
BridgeHubRococoMessagesToRococoBulletinMessageLane,
BridgeHubRococoMessagesToRococoBulletinMessageLaneReceiveMessagesProofCallBuilder,
relay_polkadot_bulletin_client::RuntimeCall::BridgePolkadotMessages,
relay_polkadot_bulletin_client::BridgePolkadotMessagesCall::receive_messages_proof
);

substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
BridgeHubRococoMessagesToRococoBulletinMessageLane,
BridgeHubRococoMessagesToRococoBulletinMessageLaneReceiveMessagesDeliveryProofCallBuilder,
relay_bridge_hub_rococo_client::RuntimeCall::BridgePolkadotBulletinMessages,
relay_bridge_hub_rococo_client::BridgeBulletinMessagesCall::receive_messages_delivery_proof
);

/// BridgeHubRococo-to-RococoBulletin messages lane.
#[derive(Clone, Debug)]
pub struct BridgeHubRococoMessagesToRococoBulletinMessageLane;

impl SubstrateMessageLane for BridgeHubRococoMessagesToRococoBulletinMessageLane {
type SourceChain = BridgeHubRococoAsBridgeHubPolkadot;
type TargetChain = RococoBulletin;

type ReceiveMessagesProofCallBuilder =
BridgeHubRococoMessagesToRococoBulletinMessageLaneReceiveMessagesProofCallBuilder;
type ReceiveMessagesDeliveryProofCallBuilder =
BridgeHubRococoMessagesToRococoBulletinMessageLaneReceiveMessagesDeliveryProofCallBuilder;

type SourceBatchCallBuilder = UtilityPalletBatchCallBuilder<BridgeHubRococoAsBridgeHubPolkadot>;
type TargetBatchCallBuilder = ();
}
Loading

0 comments on commit 5feb9ab

Please sign in to comment.