diff --git a/bridges/bin/millau/runtime/src/rialto_messages.rs b/bridges/bin/millau/runtime/src/rialto_messages.rs index 1bc361d58823..62ad919d96cc 100644 --- a/bridges/bin/millau/runtime/src/rialto_messages.rs +++ b/bridges/bin/millau/runtime/src/rialto_messages.rs @@ -30,14 +30,14 @@ pub const XCM_LANE: LaneId = LaneId([0, 0, 0, 0]); /// Weight of 2 XCM instructions is for simple `Trap(42)` program, coming through bridge /// (it is prepended with `UniversalOrigin` instruction). It is used just for simplest manual /// tests, confirming that we don't break encoding somewhere between. -pub const BASE_XCM_WEIGHT_TWICE: u64 = 2 * crate::xcm_config::BASE_XCM_WEIGHT; +pub const BASE_XCM_WEIGHT_TWICE: Weight = crate::xcm_config::BaseXcmWeight::get().saturating_mul(2); parameter_types! { /// Weight credit for our test messages. /// /// 2 XCM instructions is for simple `Trap(42)` program, coming through bridge /// (it is prepended with `UniversalOrigin` instruction). - pub const WeightCredit: Weight = Weight::from_ref_time(BASE_XCM_WEIGHT_TWICE); + pub const WeightCredit: Weight = BASE_XCM_WEIGHT_TWICE; } /// Message payload for Millau -> Rialto messages. diff --git a/bridges/bin/millau/runtime/src/rialto_parachain_messages.rs b/bridges/bin/millau/runtime/src/rialto_parachain_messages.rs index d19e41364083..1cfdc9c8f494 100644 --- a/bridges/bin/millau/runtime/src/rialto_parachain_messages.rs +++ b/bridges/bin/millau/runtime/src/rialto_parachain_messages.rs @@ -30,14 +30,14 @@ pub const XCM_LANE: LaneId = LaneId([0, 0, 0, 0]); /// Weight of 2 XCM instructions is for simple `Trap(42)` program, coming through bridge /// (it is prepended with `UniversalOrigin` instruction). It is used just for simplest manual /// tests, confirming that we don't break encoding somewhere between. -pub const BASE_XCM_WEIGHT_TWICE: u64 = 2 * crate::xcm_config::BASE_XCM_WEIGHT; +pub const BASE_XCM_WEIGHT_TWICE: Weight = crate::xcm_config::BaseXcmWeight::get().saturating_mul(2); parameter_types! { /// Weight credit for our test messages. /// /// 2 XCM instructions is for simple `Trap(42)` program, coming through bridge /// (it is prepended with `UniversalOrigin` instruction). - pub const WeightCredit: Weight = Weight::from_ref_time(BASE_XCM_WEIGHT_TWICE); + pub const WeightCredit: Weight = BASE_XCM_WEIGHT_TWICE; } /// Message payload for Millau -> RialtoParachain messages. diff --git a/bridges/bin/millau/runtime/src/xcm_config.rs b/bridges/bin/millau/runtime/src/xcm_config.rs index 17bdc43da3d6..aaaa7bf642db 100644 --- a/bridges/bin/millau/runtime/src/xcm_config.rs +++ b/bridges/bin/millau/runtime/src/xcm_config.rs @@ -93,13 +93,9 @@ type LocalOriginConverter = ( SignedAccountId32AsNative, ); -/// The amount of weight an XCM operation takes. This is a safe overestimate. -pub const BASE_XCM_WEIGHT: u64 = 1_000_000_000; - parameter_types! { /// The amount of weight an XCM operation takes. This is a safe overestimate. - // TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - check `set_proof_size` 0 or 64*1024 or 1026? - pub const BaseXcmWeight: Weight = Weight::from_parts(BASE_XCM_WEIGHT, 0); + pub const BaseXcmWeight: Weight = Weight::from_parts(1_000_000_000, 64 * 1024); /// Maximum number of instructions in a single XCM fragment. A sanity check against weight /// calculations getting too crazy. pub const MaxInstructions: u32 = 100; @@ -314,17 +310,14 @@ mod tests { }; let dispatch_weight = MessageDispatcher::dispatch_weight(&mut incoming_message); - assert_eq!( - dispatch_weight, - frame_support::weights::Weight::from_ref_time(1_000_000_000) - ); + assert_eq!(dispatch_weight, BaseXcmWeight::get()); let dispatch_result = MessageDispatcher::dispatch(&AccountId::from([0u8; 32]), incoming_message); assert_eq!( dispatch_result, MessageDispatchResult { - unspent_weight: frame_support::weights::Weight::from_ref_time(0), + unspent_weight: frame_support::weights::Weight::zero(), dispatch_level_result: (), } ); diff --git a/bridges/bin/rialto-parachain/runtime/src/lib.rs b/bridges/bin/rialto-parachain/runtime/src/lib.rs index be457d950415..ba1aa05463b1 100644 --- a/bridges/bin/rialto-parachain/runtime/src/lib.rs +++ b/bridges/bin/rialto-parachain/runtime/src/lib.rs @@ -368,13 +368,9 @@ pub type XcmOriginToTransactDispatchOrigin = ( // TODO: until https://github.com/paritytech/parity-bridges-common/issues/1417 is fixed (in either way), // the following constant must match the similar constant in the Millau runtime. -/// One XCM operation is `1_000_000_000` weight - almost certainly a conservative estimate. -pub const BASE_XCM_WEIGHT: u64 = 1_000_000_000; - parameter_types! { /// The amount of weight an XCM operation takes. This is a safe overestimate. - // TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - check `set_proof_size` 0 or 64*1024 or 1026? - pub UnitWeightCost: Weight = Weight::from_parts(BASE_XCM_WEIGHT, 0); + pub const UnitWeightCost: Weight = Weight::from_parts(1_000_000, 64 * 1024); // One UNIT buys 1 second of weight. pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), UNIT); pub const MaxInstructions: u32 = 100; @@ -902,17 +898,14 @@ mod tests { }; let dispatch_weight = MessageDispatcher::dispatch_weight(&mut incoming_message); - assert_eq!( - dispatch_weight, - frame_support::weights::Weight::from_ref_time(1_000_000_000) - ); + assert_eq!(dispatch_weight, UnitWeightCost::get()); let dispatch_result = MessageDispatcher::dispatch(&AccountId::from([0u8; 32]), incoming_message); assert_eq!( dispatch_result, MessageDispatchResult { - unspent_weight: frame_support::weights::Weight::from_ref_time(0), + unspent_weight: frame_support::weights::Weight::zero(), dispatch_level_result: (), } ); diff --git a/bridges/bin/rialto-parachain/runtime/src/millau_messages.rs b/bridges/bin/rialto-parachain/runtime/src/millau_messages.rs index 850ec1da60db..ee7a089992eb 100644 --- a/bridges/bin/rialto-parachain/runtime/src/millau_messages.rs +++ b/bridges/bin/rialto-parachain/runtime/src/millau_messages.rs @@ -33,14 +33,14 @@ pub const XCM_LANE: LaneId = LaneId([0, 0, 0, 0]); /// Weight of 2 XCM instructions is for simple `Trap(42)` program, coming through bridge /// (it is prepended with `UniversalOrigin` instruction). It is used just for simplest manual /// tests, confirming that we don't break encoding somewhere between. -pub const BASE_XCM_WEIGHT_TWICE: u64 = 2 * crate::BASE_XCM_WEIGHT; +pub const BASE_XCM_WEIGHT_TWICE: Weight = crate::UnitWeightCost::get().saturating_mul(2); parameter_types! { /// Weight credit for our test messages. /// /// 2 XCM instructions is for simple `Trap(42)` program, coming through bridge /// (it is prepended with `UniversalOrigin` instruction). - pub const WeightCredit: Weight = Weight::from_ref_time(BASE_XCM_WEIGHT_TWICE); + pub const WeightCredit: Weight = BASE_XCM_WEIGHT_TWICE; } /// Message payload for RialtoParachain -> Millau messages. diff --git a/bridges/bin/rialto/node/src/chain_spec.rs b/bridges/bin/rialto/node/src/chain_spec.rs index 345778755adb..cfc0ed62e106 100644 --- a/bridges/bin/rialto/node/src/chain_spec.rs +++ b/bridges/bin/rialto/node/src/chain_spec.rs @@ -253,7 +253,10 @@ fn testnet_genesis( max_upward_queue_count: 8, max_upward_queue_size: 1024 * 1024, max_downward_message_size: 1024 * 1024, - ump_service_total_weight: Weight::from_ref_time(100_000_000_000), + ump_service_total_weight: Weight::from_parts( + 100_000_000_000, + polkadot_primitives::v2::MAX_POV_SIZE as u64, + ), max_upward_message_size: 50 * 1024, max_upward_message_num_per_candidate: 5, hrmp_sender_deposit: 0, diff --git a/bridges/bin/rialto/runtime/src/millau_messages.rs b/bridges/bin/rialto/runtime/src/millau_messages.rs index 09fbe46453df..4774d871b788 100644 --- a/bridges/bin/rialto/runtime/src/millau_messages.rs +++ b/bridges/bin/rialto/runtime/src/millau_messages.rs @@ -30,14 +30,14 @@ pub const XCM_LANE: LaneId = LaneId([0, 0, 0, 0]); /// Weight of 2 XCM instructions is for simple `Trap(42)` program, coming through bridge /// (it is prepended with `UniversalOrigin` instruction). It is used just for simplest manual /// tests, confirming that we don't break encoding somewhere between. -pub const BASE_XCM_WEIGHT_TWICE: u64 = 2 * crate::xcm_config::BASE_XCM_WEIGHT; +pub const BASE_XCM_WEIGHT_TWICE: Weight = crate::xcm_config::BaseXcmWeight::get().saturating_mul(2); parameter_types! { /// Weight credit for our test messages. /// /// 2 XCM instructions is for simple `Trap(42)` program, coming through bridge /// (it is prepended with `UniversalOrigin` instruction). - pub const WeightCredit: Weight = Weight::from_ref_time(BASE_XCM_WEIGHT_TWICE); + pub const WeightCredit: Weight = BASE_XCM_WEIGHT_TWICE; } /// Message payload for Rialto -> Millau messages. diff --git a/bridges/bin/rialto/runtime/src/parachains.rs b/bridges/bin/rialto/runtime/src/parachains.rs index 1c7280198a42..9a3346eafd87 100644 --- a/bridges/bin/rialto/runtime/src/parachains.rs +++ b/bridges/bin/rialto/runtime/src/parachains.rs @@ -21,7 +21,7 @@ use crate::{ RuntimeOrigin, ShiftSessionManager, Slots, UncheckedExtrinsic, }; -use frame_support::{parameter_types, traits::KeyOwnerProofSystem, weights::Weight}; +use frame_support::{parameter_types, traits::KeyOwnerProofSystem}; use frame_system::EnsureRoot; use polkadot_primitives::v2::{ValidatorId, ValidatorIndex}; use polkadot_runtime_common::{paras_registrar, paras_sudo_wrapper, slots}; @@ -163,44 +163,3 @@ impl slots::Config for Runtime { } impl paras_sudo_wrapper::Config for Runtime {} - -pub struct ZeroWeights; - -impl polkadot_runtime_common::paras_registrar::WeightInfo for ZeroWeights { - fn reserve() -> Weight { - Weight::from_ref_time(0) - } - fn register() -> Weight { - Weight::from_ref_time(0) - } - fn force_register() -> Weight { - Weight::from_ref_time(0) - } - fn deregister() -> Weight { - Weight::from_ref_time(0) - } - fn swap() -> Weight { - Weight::from_ref_time(0) - } - fn schedule_code_upgrade(_: u32) -> Weight { - Weight::from_ref_time(0) - } - fn set_current_head(_: u32) -> Weight { - Weight::from_ref_time(0) - } -} - -impl polkadot_runtime_common::slots::WeightInfo for ZeroWeights { - fn force_lease() -> Weight { - Weight::from_ref_time(0) - } - fn manage_lease_period_start(_c: u32, _t: u32) -> Weight { - Weight::from_ref_time(0) - } - fn clear_all_leases() -> Weight { - Weight::from_ref_time(0) - } - fn trigger_onboard() -> Weight { - Weight::from_ref_time(0) - } -} diff --git a/bridges/bin/rialto/runtime/src/xcm_config.rs b/bridges/bin/rialto/runtime/src/xcm_config.rs index a86593f47f9d..174ece047251 100644 --- a/bridges/bin/rialto/runtime/src/xcm_config.rs +++ b/bridges/bin/rialto/runtime/src/xcm_config.rs @@ -87,13 +87,9 @@ type LocalOriginConverter = ( SignedAccountId32AsNative, ); -/// The amount of weight an XCM operation takes. This is a safe overestimate. -pub const BASE_XCM_WEIGHT: u64 = 1_000_000_000; - parameter_types! { /// The amount of weight an XCM operation takes. This is a safe overestimate. - // TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - check `set_proof_size` 0 or 64*1024 or 1026? - pub const BaseXcmWeight: Weight = Weight::from_parts(BASE_XCM_WEIGHT, 0); + pub const BaseXcmWeight: Weight = Weight::from_parts(1_000_000_000, 64 * 1024); /// Maximum number of instructions in a single XCM fragment. A sanity check against weight /// calculations getting too crazy. pub const MaxInstructions: u32 = 100; @@ -273,17 +269,14 @@ mod tests { }; let dispatch_weight = MessageDispatcher::dispatch_weight(&mut incoming_message); - assert_eq!( - dispatch_weight, - frame_support::weights::Weight::from_ref_time(1_000_000_000) - ); + assert_eq!(dispatch_weight, BaseXcmWeight::get()); let dispatch_result = MessageDispatcher::dispatch(&AccountId::from([0u8; 32]), incoming_message); assert_eq!( dispatch_result, MessageDispatchResult { - unspent_weight: frame_support::weights::Weight::from_ref_time(0), + unspent_weight: frame_support::weights::Weight::zero(), dispatch_level_result: (), } ); diff --git a/bridges/modules/messages/src/lib.rs b/bridges/modules/messages/src/lib.rs index 21e5a6a9a854..eaa681df38f0 100644 --- a/bridges/modules/messages/src/lib.rs +++ b/bridges/modules/messages/src/lib.rs @@ -1271,7 +1271,7 @@ mod tests { TEST_RELAYER_A, Err(()).into(), 1, - Weight::from_ref_time(0), + Weight::zero(), ), Error::::InvalidMessagesProof, ); @@ -1287,7 +1287,7 @@ mod tests { TEST_RELAYER_A, Ok(vec![message(1, REGULAR_PAYLOAD)]).into(), u32::MAX, - Weight::from_ref_time(0), + Weight::zero(), ), Error::::TooManyMessagesInTheProof, ); @@ -1479,8 +1479,8 @@ mod tests { TEST_RELAYER_A, Ok(vec![invalid_message]).into(), 1, - Weight::from_ref_time(0), /* weight may be zero in this case (all messages are - * improperly encoded) */ + Weight::zero(), /* weight may be zero in this case (all messages are + * improperly encoded) */ ),); assert_eq!(InboundLanes::::get(TEST_LANE_ID).last_delivered_nonce(), 1,); @@ -1710,11 +1710,7 @@ mod tests { Pallet::::inbound_message_data( TEST_LANE_ID, REGULAR_PAYLOAD.encode(), - OutboundMessageDetails { - nonce: 0, - dispatch_weight: Weight::from_ref_time(0), - size: 0, - }, + OutboundMessageDetails { nonce: 0, dispatch_weight: Weight::zero(), size: 0 }, ), InboundMessageDetails { dispatch_weight: REGULAR_PAYLOAD.declared_weight }, ); diff --git a/bridges/modules/messages/src/mock.rs b/bridges/modules/messages/src/mock.rs index c628ab2cbb32..bd10de09c7f2 100644 --- a/bridges/modules/messages/src/mock.rs +++ b/bridges/modules/messages/src/mock.rs @@ -374,7 +374,7 @@ impl MessageDispatch for TestMessageDispatch { fn dispatch_weight(message: &mut DispatchMessage) -> Weight { match message.data.payload.as_ref() { Ok(payload) => payload.declared_weight, - Err(_) => Weight::from_ref_time(0), + Err(_) => Weight::zero(), } } diff --git a/bridges/modules/messages/src/weights_ext.rs b/bridges/modules/messages/src/weights_ext.rs index b2133f06460c..c764f5b8f656 100644 --- a/bridges/modules/messages/src/weights_ext.rs +++ b/bridges/modules/messages/src/weights_ext.rs @@ -48,7 +48,7 @@ pub fn ensure_weights_are_correct() { // verify `receive_message_proof` weight let receive_messages_proof_weight = - W::receive_messages_proof_weight(&PreComputedSize(1), 10, Weight::from_ref_time(0)); + W::receive_messages_proof_weight(&PreComputedSize(1), 10, Weight::zero()); assert_ne!(receive_messages_proof_weight.ref_time(), 0); assert_ne!(receive_messages_proof_weight.proof_size(), 0); diff --git a/bridges/primitives/chain-bridge-hub-cumulus/src/lib.rs b/bridges/primitives/chain-bridge-hub-cumulus/src/lib.rs index 74c661827551..dfa5afe2a5b8 100644 --- a/bridges/primitives/chain-bridge-hub-cumulus/src/lib.rs +++ b/bridges/primitives/chain-bridge-hub-cumulus/src/lib.rs @@ -45,7 +45,6 @@ pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); /// time. /// /// This is a copy-paste from the cumulus repo's `parachains-common` crate. -// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - remove `set_proof_size` const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_ref_time(constants::WEIGHT_REF_TIME_PER_SECOND) .saturating_div(2) .set_proof_size(polkadot_primitives::v2::MAX_POV_SIZE as u64); @@ -62,9 +61,12 @@ parameter_types! { NORMAL_DISPATCH_RATIO, ); - pub const BlockExecutionWeight: Weight = Weight::from_ref_time(constants::WEIGHT_REF_TIME_PER_NANOS).saturating_mul(5_000_000); - - pub const ExtrinsicBaseWeight: Weight = Weight::from_ref_time(constants::WEIGHT_REF_TIME_PER_NANOS).saturating_mul(125_000); + /// Importing a block with 0 Extrinsics. + pub const BlockExecutionWeight: Weight = Weight::from_ref_time(constants::WEIGHT_REF_TIME_PER_NANOS) + .saturating_mul(5_000_000); + /// Executing a NO-OP `System::remarks` Extrinsic. + pub const ExtrinsicBaseWeight: Weight = Weight::from_ref_time(constants::WEIGHT_REF_TIME_PER_NANOS) + .saturating_mul(125_000); pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder() .base_block(BlockExecutionWeight::get())