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 <svyatonik@gmail.com>
  • Loading branch information
bkontur and svyatonik authored Nov 14, 2022
1 parent e2d9437 commit 72b07d1
Show file tree
Hide file tree
Showing 36 changed files with 1,549 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .config/lingua.dic
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Best/MS
BlockId
BlockNumber
BridgeStorage
BridgeHub
BridgeHubRococo
BridgeHubWococo
CLI/MS
Chain1
Chain2
Expand Down
70 changes: 70 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions 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 <admin@parity.io>"]
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 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 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 <admin@parity.io>"]
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 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 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 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 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",
]
Loading

0 comments on commit 72b07d1

Please sign in to comment.