Skip to content

Commit 1a65128

Browse files
authoredDec 12, 2022
Fix bridge hub rococo/wococo weights (paritytech#1712)
* Fix bridge hub rococo/wococo weights * Remove SS58Prefix
1 parent a11d77d commit 1a65128

File tree

16 files changed

+154
-90
lines changed

16 files changed

+154
-90
lines changed
 

‎bridges/bin/runtime-common/src/refund_relayer_extension.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ mod tests {
608608
}
609609

610610
fn run_test(test: impl FnOnce()) {
611-
sp_io::TestExternalities::new(Default::default()).execute_with(|| test())
611+
sp_io::TestExternalities::new(Default::default()).execute_with(test)
612612
}
613613

614614
fn run_pre_dispatch(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[package]
2+
name = "bp-bridge-hub-cumulus"
3+
description = "Primitives of BridgeHubRococo parachain runtime."
4+
version = "0.1.0"
5+
authors = ["Parity Technologies <admin@parity.io>"]
6+
edition = "2021"
7+
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
8+
9+
[dependencies]
10+
smallvec = "1.10.0"
11+
12+
# Bridge Dependencies
13+
14+
bp-polkadot-core = { path = "../../primitives/polkadot-core", default-features = false }
15+
bp-runtime = { path = "../../primitives/runtime", default-features = false }
16+
bp-messages = { path = "../../primitives/messages", default-features = false }
17+
18+
# Substrate Based Dependencies
19+
20+
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
21+
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
22+
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
23+
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
24+
25+
# Polkadot Dependencies
26+
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
27+
polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
28+
29+
[features]
30+
default = ["std"]
31+
std = [
32+
"bp-polkadot-core/std",
33+
"bp-messages/std",
34+
"bp-runtime/std",
35+
"frame-system/std",
36+
"frame-support/std",
37+
"sp-api/std",
38+
"sp-std/std",
39+
"polkadot-primitives/std",
40+
"polkadot-runtime-constants/std",
41+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
#![cfg_attr(not(feature = "std"), no_std)]
18+
19+
use bp_messages::*;
20+
pub use bp_polkadot_core::{
21+
AccountId, AccountInfoStorageMapKeyProvider, AccountPublic, Balance, BlockNumber, Hash, Hasher,
22+
Hashing, Header, Index, Nonce, Perbill, Signature, SignedBlock, SignedExtensions,
23+
UncheckedExtrinsic, MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
24+
MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, TX_EXTRA_BYTES,
25+
};
26+
use frame_support::{
27+
dispatch::DispatchClass,
28+
parameter_types,
29+
sp_runtime::{MultiAddress, MultiSigner},
30+
weights::{constants, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial},
31+
};
32+
use frame_system::limits;
33+
34+
/// All cumulus bridge hubs allow normal extrinsics to fill block up to 75 percent.
35+
///
36+
/// This is a copy-paste from the cumulus repo's `parachains-common` crate.
37+
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
38+
39+
/// All cumulus bridge hubs chains allow for 0.5 seconds of compute with a 6-second average block
40+
/// time.
41+
///
42+
/// This is a copy-paste from the cumulus repo's `parachains-common` crate.
43+
pub const MAXIMUM_BLOCK_WEIGHT: Weight = constants::WEIGHT_PER_SECOND
44+
.saturating_div(2)
45+
.set_proof_size(polkadot_primitives::v2::MAX_POV_SIZE as u64);
46+
47+
/// All cumulus bridge hubs assume that about 5 percent of the block weight is consumed by
48+
/// `on_initialize` handlers. This is used to limit the maximal weight of a single extrinsic.
49+
///
50+
/// This is a copy-paste from the cumulus repo's `parachains-common` crate.
51+
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);
52+
53+
parameter_types! {
54+
pub BlockLength: limits::BlockLength = limits::BlockLength::max_with_normal_ratio(
55+
5 * 1024 * 1024,
56+
NORMAL_DISPATCH_RATIO,
57+
);
58+
59+
pub const BlockExecutionWeight: Weight = constants::WEIGHT_PER_NANOS.saturating_mul(5_000_000);
60+
61+
pub const ExtrinsicBaseWeight: Weight = constants::WEIGHT_PER_NANOS.saturating_mul(125_000);
62+
63+
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
64+
.base_block(BlockExecutionWeight::get())
65+
.for_class(DispatchClass::all(), |weights| {
66+
weights.base_extrinsic = ExtrinsicBaseWeight::get();
67+
})
68+
.for_class(DispatchClass::Normal, |weights| {
69+
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
70+
})
71+
.for_class(DispatchClass::Operational, |weights| {
72+
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
73+
// Operational transactions have an extra reserved space, so that they
74+
// are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.
75+
weights.reserved = Some(
76+
MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT,
77+
);
78+
})
79+
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
80+
.build_or_panic();
81+
}
82+
83+
/// [`WeightToFee`] should reflect cumulus/bridge-hub-* [`WeightToFee`]
84+
pub struct WeightToFee;
85+
impl WeightToFeePolynomial for WeightToFee {
86+
type Balance = Balance;
87+
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
88+
pub const CENTS: Balance = polkadot_runtime_constants::currency::CENTS;
89+
90+
// In BridgeHub, we map the extrinsic base weight to 1/100 CENT.
91+
let p = CENTS;
92+
let q = 100 * Balance::from(constants::ExtrinsicBaseWeight::get().ref_time());
93+
smallvec::smallvec![WeightToFeeCoefficient {
94+
degree: 1,
95+
negative: false,
96+
coeff_frac: Perbill::from_rational(p % q, q),
97+
coeff_integer: p / q,
98+
}]
99+
}
100+
}
101+
102+
/// Public key of the chain account that may be used to verify signatures.
103+
pub type AccountSigner = MultiSigner;
104+
105+
/// The address format for describing accounts.
106+
pub type Address = MultiAddress<AccountId, ()>;

‎bridges/primitives/chain-bridge-hub-rococo/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ smallvec = "1.10.0"
1111

1212
# Bridge Dependencies
1313

14-
bp-polkadot-core = { path = "../../primitives/polkadot-core", default-features = false }
14+
bp-bridge-hub-cumulus = { path = "../chain-bridge-hub-cumulus", default-features = false }
1515
bp-runtime = { path = "../../primitives/runtime", default-features = false }
1616
bp-messages = { path = "../../primitives/messages", default-features = false }
1717

@@ -27,7 +27,7 @@ polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", d
2727
[features]
2828
default = ["std"]
2929
std = [
30-
"bp-polkadot-core/std",
30+
"bp-bridge-hub-cumulus/std",
3131
"bp-messages/std",
3232
"bp-runtime/std",
3333
"frame-support/std",

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

+1-30
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,14 @@
1919
2020
#![cfg_attr(not(feature = "std"), no_std)]
2121

22+
pub use bp_bridge_hub_cumulus::*;
2223
use bp_messages::*;
23-
pub use bp_polkadot_core::*;
2424
use bp_runtime::{
2525
decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, Parachain,
2626
};
2727
use frame_support::{
2828
dispatch::DispatchClass,
29-
parameter_types,
3029
sp_runtime::{MultiAddress, MultiSigner},
31-
weights::{
32-
constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients,
33-
WeightToFeePolynomial,
34-
},
3530
RuntimeDebug,
3631
};
3732
use sp_std::prelude::*;
@@ -67,26 +62,6 @@ impl Parachain for BridgeHubRococo {
6762
const PARACHAIN_ID: u32 = BRIDGE_HUB_ROCOCO_PARACHAIN_ID;
6863
}
6964

70-
/// [`WeightToFee`] should reflect cumulus/bridge-hub-rococo-runtime [`WeightToFee`]
71-
pub struct WeightToFee;
72-
impl WeightToFeePolynomial for WeightToFee {
73-
type Balance = Balance;
74-
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
75-
pub const CENTS: Balance = polkadot_runtime_constants::currency::CENTS;
76-
77-
// in Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
78-
// in BridgeHub, we map to 1/10 of that, or 1/100 CENT
79-
let p = CENTS;
80-
let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
81-
smallvec::smallvec![WeightToFeeCoefficient {
82-
degree: 1,
83-
negative: false,
84-
coeff_frac: Perbill::from_rational(p % q, q),
85-
coeff_integer: p / q,
86-
}]
87-
}
88-
}
89-
9065
/// Public key of the chain account that may be used to verify signatures.
9166
pub type AccountSigner = MultiSigner;
9267

@@ -99,9 +74,5 @@ pub const BRIDGE_HUB_ROCOCO_PARACHAIN_ID: u32 = 1013;
9974
/// Name of the With-BridgeHubRococo messages pallet instance that is deployed at bridged chains.
10075
pub const WITH_BRIDGE_HUB_ROCOCO_MESSAGES_PALLET_NAME: &str = "BridgeRococoMessages";
10176

102-
parameter_types! {
103-
pub const SS58Prefix: u16 = 42;
104-
}
105-
10677
decl_bridge_finality_runtime_apis!(bridge_hub_rococo);
10778
decl_bridge_messages_runtime_apis!(bridge_hub_rococo);

‎bridges/primitives/chain-bridge-hub-wococo/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
1010

1111
# Bridge Dependencies
1212

13-
bp-bridge-hub-rococo = { path = "../chain-bridge-hub-rococo", default-features = false }
13+
bp-bridge-hub-cumulus = { path = "../chain-bridge-hub-cumulus", default-features = false }
1414
bp-runtime = { path = "../../primitives/runtime", default-features = false }
1515
bp-messages = { path = "../../primitives/messages", default-features = false }
1616

@@ -23,10 +23,10 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", d
2323
[features]
2424
default = ["std"]
2525
std = [
26+
"bp-bridge-hub-cumulus/std",
2627
"bp-runtime/std",
2728
"bp-messages/std",
2829
"frame-support/std",
2930
"sp-api/std",
3031
"sp-std/std",
31-
"bp-bridge-hub-rococo/std",
3232
]

‎bridges/primitives/chain-bridge-hub-wococo/src/lib.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@
2323
#![cfg_attr(not(feature = "std"), no_std)]
2424

2525
// Re-export only what is really needed
26-
pub use bp_bridge_hub_rococo::{
27-
AccountId, AccountInfoStorageMapKeyProvider, AccountPublic, AccountSigner, Address, Balance,
28-
BlockLength, BlockNumber, BlockWeights, Hash, Hasher, Hashing, Header, Index, Nonce,
29-
SS58Prefix, Signature, SignedBlock, SignedExtensions, UncheckedExtrinsic, WeightToFee,
30-
MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
31-
TX_EXTRA_BYTES,
32-
};
26+
pub use bp_bridge_hub_cumulus::*;
3327
use bp_messages::*;
3428
use bp_runtime::{
3529
decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, Parachain,

‎bridges/relays/bin-substrate/src/chains/millau.rs

-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,4 @@ impl CliChain for Millau {
5656
const RUNTIME_VERSION: Option<RuntimeVersion> = Some(millau_runtime::VERSION);
5757

5858
type KeyPair = sp_core::sr25519::Pair;
59-
60-
fn ss58_format() -> u16 {
61-
millau_runtime::SS58Prefix::get() as u16
62-
}
6359
}

‎bridges/relays/bin-substrate/src/chains/rialto.rs

-4
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,4 @@ impl CliChain for Rialto {
4848
const RUNTIME_VERSION: Option<RuntimeVersion> = Some(rialto_runtime::VERSION);
4949

5050
type KeyPair = sp_core::sr25519::Pair;
51-
52-
fn ss58_format() -> u16 {
53-
rialto_runtime::SS58Prefix::get() as u16
54-
}
5551
}

‎bridges/relays/bin-substrate/src/chains/rialto_parachain.rs

-4
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,4 @@ impl CliChain for RialtoParachain {
5050
const RUNTIME_VERSION: Option<RuntimeVersion> = Some(rialto_parachain_runtime::VERSION);
5151

5252
type KeyPair = sp_core::sr25519::Pair;
53-
54-
fn ss58_format() -> u16 {
55-
rialto_parachain_runtime::SS58Prefix::get() as u16
56-
}
5753
}

‎bridges/relays/bin-substrate/src/chains/rococo.rs

-8
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,10 @@ impl CliChain for Rococo {
2525
const RUNTIME_VERSION: Option<RuntimeVersion> = None;
2626

2727
type KeyPair = sp_core::sr25519::Pair;
28-
29-
fn ss58_format() -> u16 {
30-
bp_rococo::SS58Prefix::get() as u16
31-
}
3228
}
3329

3430
impl CliChain for BridgeHubRococo {
3531
const RUNTIME_VERSION: Option<RuntimeVersion> = None;
3632

3733
type KeyPair = sp_core::sr25519::Pair;
38-
39-
fn ss58_format() -> u16 {
40-
relay_bridge_hub_rococo_client::runtime::SS58Prefix::get()
41-
}
4234
}

‎bridges/relays/bin-substrate/src/chains/westend.rs

-14
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,10 @@ impl CliChain for Westend {
2424
const RUNTIME_VERSION: Option<RuntimeVersion> = None;
2525

2626
type KeyPair = sp_core::sr25519::Pair;
27-
28-
fn ss58_format() -> u16 {
29-
sp_core::crypto::Ss58AddressFormat::from(
30-
sp_core::crypto::Ss58AddressFormatRegistry::SubstrateAccount,
31-
)
32-
.into()
33-
}
3427
}
3528

3629
impl CliChain for Westmint {
3730
const RUNTIME_VERSION: Option<RuntimeVersion> = None;
3831

3932
type KeyPair = sp_core::sr25519::Pair;
40-
41-
fn ss58_format() -> u16 {
42-
sp_core::crypto::Ss58AddressFormat::from(
43-
sp_core::crypto::Ss58AddressFormatRegistry::SubstrateAccount,
44-
)
45-
.into()
46-
}
4733
}

‎bridges/relays/bin-substrate/src/chains/wococo.rs

-8
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,10 @@ impl CliChain for Wococo {
2525
const RUNTIME_VERSION: Option<RuntimeVersion> = None;
2626

2727
type KeyPair = sp_core::sr25519::Pair;
28-
29-
fn ss58_format() -> u16 {
30-
bp_wococo::SS58Prefix::get() as u16
31-
}
3228
}
3329

3430
impl CliChain for BridgeHubWococo {
3531
const RUNTIME_VERSION: Option<RuntimeVersion> = None;
3632

3733
type KeyPair = sp_core::sr25519::Pair;
38-
39-
fn ss58_format() -> u16 {
40-
relay_bridge_hub_wococo_client::runtime::SS58Prefix::get()
41-
}
4234
}

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

-3
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ pub trait CliChain: relay_substrate_client::Chain {
167167
///
168168
/// In case of chains supporting multiple cryptos, pick one used by the CLI.
169169
type KeyPair: sp_core::crypto::Pair;
170-
171-
/// Numeric value of SS58 format.
172-
fn ss58_format() -> u16;
173170
}
174171

175172
/// Lane id.

‎bridges/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use bp_polkadot_core::PolkadotLike;
2222
use codec::{Decode, Encode};
2323
use scale_info::TypeInfo;
2424

25-
pub use bp_bridge_hub_rococo::SS58Prefix;
2625
use bp_messages::UnrewardedRelayersState;
2726
use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId};
2827
use bp_runtime::Chain;

‎bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
//! Types that are specific to the BridgeHubWococo runtime.
1818
19-
pub use bp_bridge_hub_wococo::SS58Prefix;
20-
2119
// We reuse everything from rococo runtime wrapper
2220
pub type Call = relay_bridge_hub_rococo_client::runtime::Call;
2321
pub type UncheckedExtrinsic = bp_bridge_hub_wococo::UncheckedExtrinsic<Call>;

0 commit comments

Comments
 (0)