From 23d10d143ffed5e4f079e7206e2aa7cee235cc15 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Fri, 9 Dec 2022 10:19:35 +0200 Subject: [PATCH 1/2] fix weight tests --- .../bridge-hub-rococo/src/weights/block_weights.rs | 10 ++++++++-- .../bridge-hub-rococo/src/weights/extrinsic_weights.rs | 10 ++++++++-- .../bridge-hub-rococo/src/weights/paritydb_weights.rs | 8 ++++---- .../bridge-hub-rococo/src/weights/rocksdb_weights.rs | 8 ++++---- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/block_weights.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/block_weights.rs index 4eaa2cba639..c004307336d 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/block_weights.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/block_weights.rs @@ -38,9 +38,15 @@ pub mod constants { let w = super::constants::BlockExecutionWeight::get(); // At least 100 µs. - assert!(w >= 100 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs."); + assert!( + w.ref_time() >= 100u64 * constants::WEIGHT_PER_MICROS.ref_time(), + "Weight should be at least 100 µs." + ); // At most 50 ms. - assert!(w <= 50 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms."); + assert!( + w.ref_time() <= 50u64 * constants::WEIGHT_PER_MILLIS.ref_time(), + "Weight should be at most 50 ms." + ); } } } diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/extrinsic_weights.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/extrinsic_weights.rs index 834374b6fad..3ce6b73d584 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/extrinsic_weights.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/extrinsic_weights.rs @@ -38,9 +38,15 @@ pub mod constants { let w = super::constants::ExtrinsicBaseWeight::get(); // At least 10 µs. - assert!(w >= 10 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs."); + assert!( + w.ref_time() >= 10u64 * constants::WEIGHT_PER_MICROS.ref_time(), + "Weight should be at least 10 µs." + ); // At most 1 ms. - assert!(w <= constants::WEIGHT_PER_MILLIS, "Weight should be at most 1 ms."); + assert!( + w.ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(), + "Weight should be at most 1 ms." + ); } } } diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/paritydb_weights.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/paritydb_weights.rs index 8083ccb4001..dca7d348310 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/paritydb_weights.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/paritydb_weights.rs @@ -42,20 +42,20 @@ pub mod constants { fn sane() { // At least 1 µs. assert!( - W::get().reads(1) >= constants::WEIGHT_PER_MICROS, + W::get().reads(1).ref_time() >= constants::WEIGHT_PER_MICROS.ref_time(), "Read weight should be at least 1 µs." ); assert!( - W::get().writes(1) >= constants::WEIGHT_PER_MICROS, + W::get().writes(1).ref_time() >= constants::WEIGHT_PER_MICROS.ref_time(), "Write weight should be at least 1 µs." ); // At most 1 ms. assert!( - W::get().reads(1) <= constants::WEIGHT_PER_MILLIS, + W::get().reads(1).ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(), "Read weight should be at most 1 ms." ); assert!( - W::get().writes(1) <= constants::WEIGHT_PER_MILLIS, + W::get().writes(1).ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(), "Write weight should be at most 1 ms." ); } diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/rocksdb_weights.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/rocksdb_weights.rs index 1db87f143f3..87867ebfe17 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/rocksdb_weights.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/rocksdb_weights.rs @@ -42,20 +42,20 @@ pub mod constants { fn sane() { // At least 1 µs. assert!( - W::get().reads(1) >= constants::WEIGHT_PER_MICROS, + W::get().reads(1).ref_time() >= constants::WEIGHT_PER_MICROS.ref_time(), "Read weight should be at least 1 µs." ); assert!( - W::get().writes(1) >= constants::WEIGHT_PER_MICROS, + W::get().writes(1).ref_time() >= constants::WEIGHT_PER_MICROS.ref_time(), "Write weight should be at least 1 µs." ); // At most 1 ms. assert!( - W::get().reads(1) <= constants::WEIGHT_PER_MILLIS, + W::get().reads(1).ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(), "Read weight should be at most 1 ms." ); assert!( - W::get().writes(1) <= constants::WEIGHT_PER_MILLIS, + W::get().writes(1).ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(), "Write weight should be at most 1 ms." ); } From 13d48b447f0ab497d4989ac1f9543c12185c702c Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Fri, 9 Dec 2022 15:16:14 +0200 Subject: [PATCH 2/2] Move BHR and BHW primitives to bridges-ext --- Cargo.lock | 26 +++++- Cargo.toml | 5 +- .../chain-bridge-hub-common/Cargo.toml | 44 ++++++++++ .../src}/block_weights.rs | 0 .../chain-bridge-hub-common}/src/constants.rs | 0 .../src}/extrinsic_weights.rs | 0 .../chain-bridge-hub-common/src/lib.rs | 78 +++++++++++++++++ .../chain-bridge-hub-rococo/Cargo.toml | 44 ++++++++++ .../chain-bridge-hub-rococo/src/lib.rs | 85 +++++++++++++++++++ .../chain-bridge-hub-wococo/Cargo.toml | 32 +++++++ .../chain-bridge-hub-wococo/src/lib.rs | 72 ++++++++++++++++ .../bridge-hubs/bridge-hub-rococo/Cargo.toml | 4 +- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 40 ++------- .../bridge-hub-rococo/src/weights/mod.rs | 8 +- 14 files changed, 396 insertions(+), 42 deletions(-) create mode 100644 bridges-ext/primitives/chain-bridge-hub-common/Cargo.toml rename {parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights => bridges-ext/primitives/chain-bridge-hub-common/src}/block_weights.rs (100%) rename {parachains/runtimes/bridge-hubs/bridge-hub-rococo => bridges-ext/primitives/chain-bridge-hub-common}/src/constants.rs (100%) rename {parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights => bridges-ext/primitives/chain-bridge-hub-common/src}/extrinsic_weights.rs (100%) create mode 100644 bridges-ext/primitives/chain-bridge-hub-common/src/lib.rs create mode 100644 bridges-ext/primitives/chain-bridge-hub-rococo/Cargo.toml create mode 100644 bridges-ext/primitives/chain-bridge-hub-rococo/src/lib.rs create mode 100644 bridges-ext/primitives/chain-bridge-hub-wococo/Cargo.toml create mode 100644 bridges-ext/primitives/chain-bridge-hub-wococo/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index a12f111e275..ce4884be999 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -735,16 +735,38 @@ dependencies = [ ] [[package]] -name = "bp-bridge-hub-rococo" +name = "bp-bridge-hub-common" version = "0.1.0" dependencies = [ "bp-messages", "bp-polkadot-core", "bp-runtime", "frame-support", + "frame-system", + "parachains-common", + "polkadot-core-primitives", "polkadot-runtime-constants", "smallvec", "sp-api", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "bp-bridge-hub-rococo" +version = "0.1.0" +dependencies = [ + "bp-bridge-hub-common", + "bp-messages", + "bp-runtime", + "frame-support", + "frame-system", + "parachains-common", + "polkadot-core-primitives", + "polkadot-runtime-constants", + "smallvec", + "sp-api", + "sp-runtime", "sp-std", ] @@ -752,7 +774,7 @@ dependencies = [ name = "bp-bridge-hub-wococo" version = "0.1.0" dependencies = [ - "bp-bridge-hub-rococo", + "bp-bridge-hub-common", "bp-messages", "bp-runtime", "frame-support", diff --git a/Cargo.toml b/Cargo.toml index a0d0e4e3b6b..c8d3ab7dd51 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,9 @@ members = [ "bridges/modules/shift-session-manager", "bridges/primitives/messages", "bridges/primitives/runtime", - "bridges/primitives/chain-bridge-hub-rococo", - "bridges/primitives/chain-bridge-hub-wococo", + "bridges-ext/primitives/chain-bridge-hub-common", + "bridges-ext/primitives/chain-bridge-hub-rococo", + "bridges-ext/primitives/chain-bridge-hub-wococo", "bridges/primitives/chain-rococo", "bridges/primitives/chain-wococo", "client/cli", diff --git a/bridges-ext/primitives/chain-bridge-hub-common/Cargo.toml b/bridges-ext/primitives/chain-bridge-hub-common/Cargo.toml new file mode 100644 index 00000000000..5387a365197 --- /dev/null +++ b/bridges-ext/primitives/chain-bridge-hub-common/Cargo.toml @@ -0,0 +1,44 @@ +[package] +name = "bp-bridge-hub-common" +description = "Primitives for cumulus BridgeHub runtimes." +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2021" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" + +[dependencies] +smallvec = "1.10.0" + +# Bridge Dependencies +bp-polkadot-core = { path = "../../../bridges/primitives/polkadot-core", default-features = false } +bp-runtime = { path = "../../../bridges/primitives/runtime", default-features = false } +bp-messages = { path = "../../../bridges/primitives/messages", default-features = false } + +# Substrate Based Dependencies +frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +frame-system = { 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-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } + +# Polkadot Dependencies +polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } +polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } + +# Cumulus +parachains-common = { path = "../../../parachains/common", default-features = false } + +[features] +default = ["std"] +std = [ + "bp-polkadot-core/std", + "bp-messages/std", + "bp-runtime/std", + "frame-support/std", + "sp-api/std", + "sp-runtime/std", + "sp-std/std", + "polkadot-core-primitives/std", + "polkadot-runtime-constants/std", + "parachains-common/std", +] diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/block_weights.rs b/bridges-ext/primitives/chain-bridge-hub-common/src/block_weights.rs similarity index 100% rename from parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/block_weights.rs rename to bridges-ext/primitives/chain-bridge-hub-common/src/block_weights.rs diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs b/bridges-ext/primitives/chain-bridge-hub-common/src/constants.rs similarity index 100% rename from parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs rename to bridges-ext/primitives/chain-bridge-hub-common/src/constants.rs diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/extrinsic_weights.rs b/bridges-ext/primitives/chain-bridge-hub-common/src/extrinsic_weights.rs similarity index 100% rename from parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/extrinsic_weights.rs rename to bridges-ext/primitives/chain-bridge-hub-common/src/extrinsic_weights.rs diff --git a/bridges-ext/primitives/chain-bridge-hub-common/src/lib.rs b/bridges-ext/primitives/chain-bridge-hub-common/src/lib.rs new file mode 100644 index 00000000000..125eeeb299e --- /dev/null +++ b/bridges-ext/primitives/chain-bridge-hub-common/src/lib.rs @@ -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 . + +//! Module with configuration which reflects BridgeHubRococo runtime setup (AccountId, Headers, +//! Hashes...) + +#![cfg_attr(not(feature = "std"), no_std)] + +pub mod block_weights; +pub mod constants; +pub mod extrinsic_weights; + +pub use bp_polkadot_core::{ + AccountId, AccountInfoStorageMapKeyProvider, AccountPublic, Balance, BlockNumber, Hash, Hasher, + Hashing, Header, Index, Nonce, Signature, SignedBlock, SignedExtensions, UncheckedExtrinsic, + MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, + TX_EXTRA_BYTES, +}; +use frame_support::{ + dispatch::DispatchClass, + parameter_types, + sp_runtime::{MultiAddress, MultiSigner}, +}; +use frame_system::limits; +pub use parachains_common::{ + AVERAGE_ON_INITIALIZE_RATIO, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, +}; + +parameter_types! { + pub BlockLength: limits::BlockLength = limits::BlockLength::max_with_normal_ratio( + 5 * 1024 * 1024, + NORMAL_DISPATCH_RATIO, + ); + + pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder() + .base_block(block_weights::constants::BlockExecutionWeight::get()) + .for_class(DispatchClass::all(), |weights| { + weights.base_extrinsic = extrinsic_weights::constants::ExtrinsicBaseWeight::get(); + }) + .for_class(DispatchClass::Normal, |weights| { + weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT); + }) + .for_class(DispatchClass::Operational, |weights| { + weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT); + // Operational transactions have an extra reserved space, so that they + // are included even if block reached `MAXIMUM_BLOCK_WEIGHT`. + weights.reserved = Some( + MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT, + ); + }) + .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) + .build_or_panic(); +} + +pub use constants::fee::WeightToFee; + +/// 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; + +parameter_types! { + pub const SS58Prefix: u16 = 42; +} diff --git a/bridges-ext/primitives/chain-bridge-hub-rococo/Cargo.toml b/bridges-ext/primitives/chain-bridge-hub-rococo/Cargo.toml new file mode 100644 index 00000000000..4c4e25385f4 --- /dev/null +++ b/bridges-ext/primitives/chain-bridge-hub-rococo/Cargo.toml @@ -0,0 +1,44 @@ +[package] +name = "bp-bridge-hub-rococo" +description = "Primitives of BridgeHubRococo parachain runtime." +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2021" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" + +[dependencies] +smallvec = "1.10.0" + +# Bridge Dependencies +bp-bridge-hub-common = { path = "../chain-bridge-hub-common", default-features = false } +bp-runtime = { path = "../../../bridges/primitives/runtime", default-features = false } +bp-messages = { path = "../../../bridges/primitives/messages", default-features = false } + +# Substrate Based Dependencies +frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +frame-system = { 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-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } + +# Polkadot Dependencies +polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } +polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } + +# Cumulus +parachains-common = { path = "../../../parachains/common", default-features = false } + +[features] +default = ["std"] +std = [ + "bp-bridge-hub-common/std", + "bp-messages/std", + "bp-runtime/std", + "frame-support/std", + "sp-api/std", + "sp-runtime/std", + "sp-std/std", + "polkadot-core-primitives/std", + "polkadot-runtime-constants/std", + "parachains-common/std", +] diff --git a/bridges-ext/primitives/chain-bridge-hub-rococo/src/lib.rs b/bridges-ext/primitives/chain-bridge-hub-rococo/src/lib.rs new file mode 100644 index 00000000000..b666cc95bc7 --- /dev/null +++ b/bridges-ext/primitives/chain-bridge-hub-rococo/src/lib.rs @@ -0,0 +1,85 @@ +// 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 . + +//! Module with configuration which reflects BridgeHubRococo runtime setup (AccountId, Headers, +//! Hashes...) + +#![cfg_attr(not(feature = "std"), no_std)] + +pub use bp_bridge_hub_common::*; +use bp_messages::*; +use bp_runtime::{ + decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, Parachain, +}; +use frame_support::{dispatch::DispatchClass, parameter_types, RuntimeDebug}; +use frame_system::limits; +pub use parachains_common::{ + AVERAGE_ON_INITIALIZE_RATIO, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, +}; +use sp_std::prelude::*; + +parameter_types! { + pub BlockLength: limits::BlockLength = limits::BlockLength::max_with_normal_ratio( + 5 * 1024 * 1024, + NORMAL_DISPATCH_RATIO, + ); + + pub BlockWeights: limits::BlockWeights = bp_bridge_hub_common::BlockWeights::get(); +} + +/// BridgeHubRococo parachain. +#[derive(RuntimeDebug)] +pub struct BridgeHubRococo; + +impl Chain for BridgeHubRococo { + type BlockNumber = BlockNumber; + type Hash = Hash; + type Hasher = Hasher; + type Header = Header; + + type AccountId = AccountId; + type Balance = Balance; + type Index = Index; + type Signature = Signature; + + fn max_extrinsic_size() -> u32 { + *BlockLength::get().max.get(DispatchClass::Normal) + } + + fn max_extrinsic_weight() -> Weight { + BlockWeights::get() + .get(DispatchClass::Normal) + .max_extrinsic + .unwrap_or(Weight::MAX) + } +} + +impl Parachain for BridgeHubRococo { + const PARACHAIN_ID: u32 = BRIDGE_HUB_ROCOCO_PARACHAIN_ID; +} + +/// 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); diff --git a/bridges-ext/primitives/chain-bridge-hub-wococo/Cargo.toml b/bridges-ext/primitives/chain-bridge-hub-wococo/Cargo.toml new file mode 100644 index 00000000000..181b0bf02ec --- /dev/null +++ b/bridges-ext/primitives/chain-bridge-hub-wococo/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "bp-bridge-hub-wococo" +description = "Primitives of BridgeHubWococo parachain runtime." +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2021" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" + +[dependencies] + +# Bridge Dependencies + +bp-bridge-hub-common = { path = "../chain-bridge-hub-common", default-features = false } +bp-runtime = { path = "../../../bridges/primitives/runtime", default-features = false } +bp-messages = { path = "../../../bridges/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-bridge-hub-common/std", + "bp-runtime/std", + "bp-messages/std", + "frame-support/std", + "sp-api/std", + "sp-std/std", +] diff --git a/bridges-ext/primitives/chain-bridge-hub-wococo/src/lib.rs b/bridges-ext/primitives/chain-bridge-hub-wococo/src/lib.rs new file mode 100644 index 00000000000..20817b583ee --- /dev/null +++ b/bridges-ext/primitives/chain-bridge-hub-wococo/src/lib.rs @@ -0,0 +1,72 @@ +// 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 . + +//! 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_common::*; +use bp_messages::*; +use bp_runtime::{ + decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, Parachain, +}; +use frame_support::{dispatch::DispatchClass, RuntimeDebug}; +use sp_std::prelude::*; + +/// BridgeHubWococo parachain. +#[derive(RuntimeDebug)] +pub struct BridgeHubWococo; + +impl Chain for BridgeHubWococo { + type BlockNumber = BlockNumber; + type Hash = Hash; + type Hasher = Hasher; + type Header = Header; + + type AccountId = AccountId; + type Balance = Balance; + type Index = Index; + type Signature = Signature; + + fn max_extrinsic_size() -> u32 { + *BlockLength::get().max.get(DispatchClass::Normal) + } + + fn max_extrinsic_weight() -> Weight { + BlockWeights::get() + .get(DispatchClass::Normal) + .max_extrinsic + .unwrap_or(Weight::MAX) + } +} + +impl Parachain for BridgeHubWococo { + const PARACHAIN_ID: u32 = BRIDGE_HUB_WOCOCO_PARACHAIN_ID; +} + +/// Identifier of BridgeHubWococo in the Wococo relay chain. +pub const BRIDGE_HUB_WOCOCO_PARACHAIN_ID: u32 = 1014; + +/// 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); diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 6b453580ddf..a81b5ee2aa7 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -69,8 +69,8 @@ parachain-info = { path = "../../../../parachains/pallets/parachain-info", defau parachains-common = { path = "../../../../parachains/common", default-features = false } # Bridges -bp-bridge-hub-rococo = { path = "../../../../bridges/primitives/chain-bridge-hub-rococo", default-features = false } -bp-bridge-hub-wococo = { path = "../../../../bridges/primitives/chain-bridge-hub-wococo", default-features = false } +bp-bridge-hub-rococo = { path = "../../../../bridges-ext/primitives/chain-bridge-hub-rococo", default-features = false } +bp-bridge-hub-wococo = { path = "../../../../bridges-ext/primitives/chain-bridge-hub-wococo", default-features = false } bp-messages = { path = "../../../../bridges/primitives/messages", default-features = false } bp-runtime = { path = "../../../../bridges/primitives/runtime", default-features = false } bp-rococo = { path = "../../../../bridges/primitives/chain-rococo", default-features = false } diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index a91787fc118..36f2331757c 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -25,13 +25,12 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod bridge_common_config; pub mod bridge_hub_rococo_config; pub mod bridge_hub_wococo_config; -pub mod constants; mod weights; pub mod xcm_config; +use bp_bridge_hub_rococo::constants::currency::*; use bridge_common_config::*; use codec::Decode; -use constants::currency::*; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; @@ -48,9 +47,7 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use frame_support::{ - construct_runtime, - dispatch::DispatchClass, - parameter_types, + construct_runtime, parameter_types, traits::Everything, weights::{ConstantMultiplier, Weight}, PalletId, @@ -70,16 +67,13 @@ pub use sp_runtime::BuildStorage; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; -use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; +use weights::RocksDbWeight; use crate::{ bridge_hub_rococo_config::OnBridgeHubRococoBlobDispatcher, - bridge_hub_wococo_config::OnBridgeHubWococoBlobDispatcher, constants::fee::WeightToFee, - xcm_config::XcmRouter, -}; -use parachains_common::{ - AccountId, Signature, AVERAGE_ON_INITIALIZE_RATIO, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, + bridge_hub_wococo_config::OnBridgeHubWococoBlobDispatcher, xcm_config::XcmRouter, }; +use parachains_common::{AccountId, Signature, MAXIMUM_BLOCK_WEIGHT}; use xcm::latest::prelude::BodyId; use xcm_executor::XcmExecutor; @@ -224,26 +218,8 @@ pub mod runtime_api { parameter_types! { pub const Version: RuntimeVersion = VERSION; - pub RuntimeBlockLength: BlockLength = - BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); - pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder() - .base_block(BlockExecutionWeight::get()) - .for_class(DispatchClass::all(), |weights| { - weights.base_extrinsic = ExtrinsicBaseWeight::get(); - }) - .for_class(DispatchClass::Normal, |weights| { - weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT); - }) - .for_class(DispatchClass::Operational, |weights| { - weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT); - // Operational transactions have some extra reserved space, so that they - // are included even if block reached `MAXIMUM_BLOCK_WEIGHT`. - weights.reserved = Some( - MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT - ); - }) - .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) - .build_or_panic(); + pub RuntimeBlockLength: BlockLength = bp_bridge_hub_rococo::BlockLength::get(); + pub RuntimeBlockWeights: BlockWeights = bp_bridge_hub_rococo::BlockWeights::get(); pub const SS58Prefix: u16 = 42; } @@ -352,7 +328,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter; - type WeightToFee = WeightToFee; + type WeightToFee = bp_bridge_hub_rococo::WeightToFee; type LengthToFee = ConstantMultiplier; type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; type OperationalFeeMultiplier = OperationalFeeMultiplier; diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/mod.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/mod.rs index 8006fb43e5d..b7a98a4a1d1 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/mod.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/mod.rs @@ -17,15 +17,15 @@ //! Expose the auto generated weight files. -pub mod block_weights; pub mod cumulus_pallet_xcmp_queue; -pub mod extrinsic_weights; pub mod pallet_balances; pub mod paritydb_weights; pub mod rocksdb_weights; pub mod xcm; -pub use block_weights::constants::BlockExecutionWeight; -pub use extrinsic_weights::constants::ExtrinsicBaseWeight; +pub use bp_bridge_hub_rococo::{ + block_weights::constants::BlockExecutionWeight, + extrinsic_weights::constants::ExtrinsicBaseWeight, +}; pub use paritydb_weights::constants::ParityDbWeight; pub use rocksdb_weights::constants::RocksDbWeight;