Skip to content

Commit

Permalink
Rococo/Wococo bridge hub relay integration (paritytech#1565)
Browse files Browse the repository at this point in the history
* [BridgeHub] Added bridge-hub-rococo/wococo clients with bridge-hub-rococo-runtime

* [BridgeHub] Add init-bridge stuff for bridge-hub-rococo/wococo

* [BridgeHub] Add init-bridge stuff for bridge-hub-rococo/wococo

* [BridgeHub] Fixed Call-encoding for init-bridge rococo runtime wrapper

* Final index update to runtime calls

* [BridgeHub] Add init-bridge stuff for bridge-hub-rococo/wococo (otherside)

* Added runtime best_finalized functions + relay-headers init

* Renaming and change BridgeHubRococo/Wococo to Rococo/Wococo config

* [BridgeHub] Add relay-parachains (Rococo/Wococo)

* Missing stuff for adding xcm messaging to BridgeHub

* extracted parachain IDs to the primitives

* fix compilation

* Fixes

* Init setup for Rococo->Wococo messaging support

* Removed unused AccountId from `trait MessagesBridge`

* Removed unused trait SenderOrigin

* Small fixes

* Cleaning after master-merge

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes:
- align WeightToFee with BridgeHubRococo runtime
- MAX_HEADER_SIZE
- updated TODOs

* Added relay_messages cfg for BridgeHubWococo -> BridgeHubRococo

Co-authored-by: Svyatoslav Nikolsky <[email protected]>
  • Loading branch information
2 people authored and serban300 committed Apr 8, 2024
1 parent 290facf commit 21df186
Show file tree
Hide file tree
Showing 34 changed files with 1,476 additions and 4 deletions.
37 changes: 37 additions & 0 deletions bridges/primitives/chain-bridge-hub-rococo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "bp-bridge-hub-rococo"
description = "Primitives of BridgeHubRococo parachain runtime."
version = "0.1.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]
smallvec = "1.10.0"

# Bridge Dependencies

bp-polkadot-core = { path = "../../primitives/polkadot-core", default-features = false }
bp-runtime = { path = "../../primitives/runtime", default-features = false }
bp-messages = { path = "../../primitives/messages", default-features = false }

# Substrate Based Dependencies

frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }

# Polkadot Dependencies
polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }

[features]
default = ["std"]
std = [
"bp-polkadot-core/std",
"bp-messages/std",
"bp-runtime/std",
"frame-support/std",
"sp-api/std",
"sp-std/std",
"polkadot-runtime-constants/std",
]
75 changes: 75 additions & 0 deletions bridges/primitives/chain-bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright 2019-2021 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/>.

//! Module with configuration which reflects BridgeHubRococo runtime setup (AccountId, Headers,
//! Hashes...)

#![cfg_attr(not(feature = "std"), no_std)]

use bp_messages::*;
pub use bp_polkadot_core::*;
use bp_runtime::{decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis};
use frame_support::{
parameter_types,
sp_runtime::{FixedU128, MultiAddress, MultiSigner},
weights::{
constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients,
WeightToFeePolynomial,
},
Parameter,
};
use sp_std::prelude::*;

pub type BridgeHubRococo = PolkadotLike;

/// [`WeightToFee`] should reflect cumulus/bridge-hub-rococo-runtime [`WeightToFee`]
pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
pub const CENTS: Balance = polkadot_runtime_constants::currency::CENTS;

// in Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
// in BridgeHub, we map to 1/10 of that, or 1/100 CENT
let p = CENTS;
let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
smallvec::smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q,
}]
}
}

/// Public key of the chain account that may be used to verify signatures.
pub type AccountSigner = MultiSigner;

/// The address format for describing accounts.
pub type Address = MultiAddress<AccountId, ()>;

/// Identifier of BridgeHubRococo in the Rococo relay chain.
pub const BRIDGE_HUB_ROCOCO_PARACHAIN_ID: u32 = 1013;

/// Name of the With-BridgeHubRococo messages pallet instance that is deployed at bridged chains.
pub const WITH_BRIDGE_HUB_ROCOCO_MESSAGES_PALLET_NAME: &str = "BridgeRococoMessages";

parameter_types! {
pub const SS58Prefix: u16 = 42;
}

decl_bridge_finality_runtime_apis!(bridge_hub_rococo);
decl_bridge_messages_runtime_apis!(bridge_hub_rococo);
32 changes: 32 additions & 0 deletions bridges/primitives/chain-bridge-hub-wococo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "bp-bridge-hub-wococo"
description = "Primitives of BridgeHubWococo parachain runtime."
version = "0.1.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]

# Bridge Dependencies

bp-bridge-hub-rococo = { path = "../chain-bridge-hub-rococo", default-features = false }
bp-runtime = { path = "../../primitives/runtime", default-features = false }
bp-messages = { path = "../../primitives/messages", default-features = false }

# Substrate Based Dependencies

frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }

[features]
default = ["std"]
std = [
"bp-runtime/std",
"bp-messages/std",
"frame-support/std",
"sp-api/std",
"sp-std/std",
"bp-bridge-hub-rococo/std",
]
49 changes: 49 additions & 0 deletions bridges/primitives/chain-bridge-hub-wococo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2019-2021 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/>.

//! Module with configuration which reflects BridgeHubWococo runtime setup
//! (AccountId, Headers, Hashes...)
//!
//! but actually this is just reexported BridgeHubRococo stuff, because they are supposed to be
//! identical, at least uses the same parachain runtime

#![cfg_attr(not(feature = "std"), no_std)]

// Re-export only what is really needed
pub use bp_bridge_hub_rococo::{
account_info_storage_key, AccountId, AccountPublic, AccountSigner, Address, Balance,
BlockNumber, Hash, Hashing, Header, Nonce, SS58Prefix, Signature, SignedBlock,
SignedExtensions, UncheckedExtrinsic, WeightToFee, ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT,
DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT, EXTRA_STORAGE_PROOF_SIZE,
MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT,
MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
PAY_INBOUND_DISPATCH_FEE_WEIGHT, TX_EXTRA_BYTES,
};
use bp_messages::*;
use bp_runtime::{decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis};
use frame_support::{sp_runtime::FixedU128, Parameter};
use sp_std::prelude::*;

pub type BridgeHubWococo = bp_bridge_hub_rococo::BridgeHubRococo;

/// Identifier of BridgeHubWococo in the Wococo relay chain.
pub const BRIDGE_HUB_WOCOCO_PARACHAIN_ID: u32 = 1013;

/// Name of the With-BridgeHubWococo messages pallet instance that is deployed at bridged chains.
pub const WITH_BRIDGE_HUB_WOCOCO_MESSAGES_PALLET_NAME: &str = "BridgeWococoMessages";

decl_bridge_finality_runtime_apis!(bridge_hub_wococo);
decl_bridge_messages_runtime_apis!(bridge_hub_wococo);
2 changes: 2 additions & 0 deletions bridges/primitives/chain-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ bp-runtime = { path = "../runtime", default-features = false }

# Substrate Based Dependencies
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }

[features]
default = ["std"]
std = [
"bp-polkadot-core/std",
"bp-runtime/std",
"sp-api/std",
"frame-support/std",
]
23 changes: 23 additions & 0 deletions bridges/primitives/chain-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,34 @@

pub use bp_polkadot_core::*;
use bp_runtime::decl_bridge_finality_runtime_apis;
use frame_support::parameter_types;

/// Rococo Chain
pub type Rococo = PolkadotLike;

parameter_types! {
pub const SS58Prefix: u8 = 42;
}

/// Name of the parachains pallet in the Rococo runtime.
pub const PARAS_PALLET_NAME: &str = "Paras";

/// Name of the With-Rococo GRANDPA pallet instance that is deployed at bridged chains.
pub const WITH_ROCOCO_GRANDPA_PALLET_NAME: &str = "BridgeRococoGrandpa";

/// Maximal SCALE-encoded header size (in bytes) at Rococo.
///
/// Let's assume that the largest header is header that enacts new authorities set with
/// `MAX_AUTHORITES_COUNT`. Every authority means 32-byte key and 8-byte weight. Let's also have
/// some fixed reserve for other things (digest, block hash and number, ...) as well.
pub const MAX_HEADER_SIZE: u32 = 4096 + MAX_AUTHORITIES_COUNT * 40;

/// Maximal SCALE-encoded size of parachains headers that are stored at Rococo `Paras` pallet.
pub const MAX_NESTED_PARACHAIN_HEAD_SIZE: u32 = MAX_HEADER_SIZE;

/// Maximal number of GRANDPA authorities at Rococo.
///
/// Corresponds to the `MaxAuthorities` constant value from the Rococo runtime configuration.
pub const MAX_AUTHORITIES_COUNT: u32 = 100_000;

decl_bridge_finality_runtime_apis!(rococo);
2 changes: 2 additions & 0 deletions bridges/primitives/chain-wococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
# Bridge Dependencies
bp-polkadot-core = { path = "../polkadot-core", default-features = false }
bp-runtime = { path = "../runtime", default-features = false }
bp-rococo = { path = "../chain-rococo", default-features = false }

# Substrate Based Dependencies
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
Expand All @@ -20,5 +21,6 @@ default = ["std"]
std = [
"bp-polkadot-core/std",
"bp-runtime/std",
"bp-rococo/std",
"sp-api/std",
]
4 changes: 4 additions & 0 deletions bridges/primitives/chain-wococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#![allow(clippy::too_many_arguments)]

pub use bp_polkadot_core::*;
pub use bp_rococo::{
SS58Prefix, MAX_AUTHORITIES_COUNT, MAX_HEADER_SIZE, MAX_NESTED_PARACHAIN_HEAD_SIZE,
PARAS_PALLET_NAME,
};
use bp_runtime::decl_bridge_finality_runtime_apis;

/// Wococo Chain
Expand Down
6 changes: 6 additions & 0 deletions bridges/primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ pub const ROCOCO_CHAIN_ID: ChainId = *b"roco";
/// Bridge-with-Wococo instance id.
pub const WOCOCO_CHAIN_ID: ChainId = *b"woco";

/// Bridge-with-BridgeHubRococo instance id.
pub const BRIDGE_HUB_ROCOCO_CHAIN_ID: ChainId = *b"bhro";

/// Bridge-with-BridgeHubWococo instance id.
pub const BRIDGE_HUB_WOCOCO_CHAIN_ID: ChainId = *b"bhwo";

/// Call-dispatch module prefix.
pub const CALL_DISPATCH_MODULE_PREFIX: &[u8] = b"pallet-bridge/dispatch";

Expand Down
9 changes: 9 additions & 0 deletions bridges/relays/bin-substrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ strum = { version = "0.21.0", features = ["derive"] }

# Bridge dependencies

bp-bridge-hub-rococo = { path = "../../primitives/chain-bridge-hub-rococo" }
bp-bridge-hub-wococo = { path = "../../primitives/chain-bridge-hub-wococo" }
bp-header-chain = { path = "../../primitives/header-chain" }
bp-messages = { path = "../../primitives/messages" }
bp-millau = { path = "../../primitives/chain-millau" }
bp-polkadot-core = { path = "../../primitives/polkadot-core" }
bp-rialto = { path = "../../primitives/chain-rialto" }
bp-rialto-parachain = { path = "../../primitives/chain-rialto-parachain" }
bp-rococo = { path = "../../primitives/chain-rococo" }
bp-runtime = { path = "../../primitives/runtime" }
bp-statemine = { path = "../../primitives/chain-statemine" }
bp-westend = { path = "../../primitives/chain-westend" }
bp-wococo = { path = "../../primitives/chain-wococo" }
bridge-runtime-common = { path = "../../bin/runtime-common" }
messages-relay = { path = "../messages" }
millau-runtime = { path = "../../bin/millau/runtime" }
Expand All @@ -37,10 +42,14 @@ parachains-relay = { path = "../parachains" }
relay-millau-client = { path = "../client-millau" }
relay-rialto-client = { path = "../client-rialto" }
relay-rialto-parachain-client = { path = "../client-rialto-parachain" }
relay-bridge-hub-rococo-client = { path = "../client-bridge-hub-rococo" }
relay-bridge-hub-wococo-client = { path = "../client-bridge-hub-wococo" }
relay-rococo-client = { path = "../client-rococo" }
relay-statemine-client = { path = "../client-statemine" }
relay-substrate-client = { path = "../client-substrate" }
relay-utils = { path = "../utils" }
relay-westend-client = { path = "../client-westend" }
relay-wococo-client = { path = "../client-wococo" }
rialto-parachain-runtime = { path = "../../bin/rialto-parachain/runtime" }
rialto-runtime = { path = "../../bin/rialto/runtime" }
substrate-relay-helper = { path = "../lib-substrate-relay" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// 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-BridgeHubWococo messages sync entrypoint.

use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
use bp_messages::Weight;
use messages_relay::relay_strategy::MixStrategy;
use relay_bridge_hub_rococo_client::BridgeHubRococo;
use relay_bridge_hub_wococo_client::BridgeHubWococo;
use substrate_relay_helper::messages_lane::SubstrateMessageLane;

pub struct BridgeHubRococoToBridgeHubWococoMessagesCliBridge {}

impl CliBridgeBase for BridgeHubRococoToBridgeHubWococoMessagesCliBridge {
type Source = BridgeHubRococo;
type Target = BridgeHubWococo;
}

impl MessagesCliBridge for BridgeHubRococoToBridgeHubWococoMessagesCliBridge {
const ESTIMATE_MESSAGE_FEE_METHOD: &'static str =
"TODO: not needed now, used for send_message and estimate_fee CLI";
type MessagesLane = BridgeHubRococoMessagesToBridgeHubWococoMessageLane;
}

substrate_relay_helper::generate_mocked_receive_message_proof_call_builder!(
BridgeHubRococoMessagesToBridgeHubWococoMessageLane,
BridgeHubRococoMessagesToBridgeHubWococoMessageLaneReceiveMessagesProofCallBuilder,
relay_bridge_hub_wococo_client::runtime::Call::BridgeRococoMessages,
relay_bridge_hub_wococo_client::runtime::BridgeRococoMessagesCall::receive_messages_proof
);

substrate_relay_helper::generate_mocked_receive_message_delivery_proof_call_builder!(
BridgeHubRococoMessagesToBridgeHubWococoMessageLane,
BridgeHubRococoMessagesToBridgeHubWococoMessageLaneReceiveMessagesDeliveryProofCallBuilder,
relay_bridge_hub_rococo_client::runtime::Call::BridgeWococoMessages,
relay_bridge_hub_rococo_client::runtime::BridgeWococoMessagesCall::receive_messages_delivery_proof
);

/// Description of BridgeHubRococo -> BridgeHubWococo messages bridge.
#[derive(Clone, Debug)]
pub struct BridgeHubRococoMessagesToBridgeHubWococoMessageLane;

impl SubstrateMessageLane for BridgeHubRococoMessagesToBridgeHubWococoMessageLane {
const SOURCE_TO_TARGET_CONVERSION_RATE_PARAMETER_NAME: Option<&'static str> = None;
const TARGET_TO_SOURCE_CONVERSION_RATE_PARAMETER_NAME: Option<&'static str> = None;

const SOURCE_FEE_MULTIPLIER_PARAMETER_NAME: Option<&'static str> = None;
const TARGET_FEE_MULTIPLIER_PARAMETER_NAME: Option<&'static str> = None;

const AT_SOURCE_TRANSACTION_PAYMENT_PALLET_NAME: Option<&'static str> = None;
const AT_TARGET_TRANSACTION_PAYMENT_PALLET_NAME: Option<&'static str> = None;

type SourceChain = BridgeHubRococo;
type TargetChain = BridgeHubWococo;

type ReceiveMessagesProofCallBuilder =
BridgeHubRococoMessagesToBridgeHubWococoMessageLaneReceiveMessagesProofCallBuilder;
type ReceiveMessagesDeliveryProofCallBuilder =
BridgeHubRococoMessagesToBridgeHubWococoMessageLaneReceiveMessagesDeliveryProofCallBuilder;

type TargetToSourceChainConversionRateUpdateBuilder = ();

type RelayStrategy = MixStrategy;
}
Loading

0 comments on commit 21df186

Please sign in to comment.