Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Migrate to Weight::from_parts (#2245)
Browse files Browse the repository at this point in the history
* Migrate to from_parts

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix remaining files

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* cargo update -p polkadot-primitives

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* cargo update -p sp-io

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use Master Cargo.lock

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* cargo update -p polkadot-primitives

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* cargo update -p sp-io

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
ggwpez authored Mar 3, 2023
1 parent 1de575d commit 5585023
Show file tree
Hide file tree
Showing 128 changed files with 2,223 additions and 2,223 deletions.
512 changes: 256 additions & 256 deletions Cargo.lock

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions pallets/collator-selection/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,42 @@ pub trait WeightInfo {
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn set_invulnerables(b: u32) -> Weight {
Weight::from_ref_time(18_563_000 as u64)
Weight::from_parts(18_563_000 as u64, 0)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(68_000 as u64).saturating_mul(b as u64))
.saturating_add(Weight::from_parts(68_000 as u64, 0).saturating_mul(b as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
fn set_desired_candidates() -> Weight {
Weight::from_ref_time(16_363_000 as u64).saturating_add(T::DbWeight::get().writes(1 as u64))
Weight::from_parts(16_363_000 as u64, 0).saturating_add(T::DbWeight::get().writes(1 as u64))
}
fn set_candidacy_bond() -> Weight {
Weight::from_ref_time(16_840_000 as u64).saturating_add(T::DbWeight::get().writes(1 as u64))
Weight::from_parts(16_840_000 as u64, 0).saturating_add(T::DbWeight::get().writes(1 as u64))
}
fn register_as_candidate(c: u32) -> Weight {
Weight::from_ref_time(71_196_000 as u64)
Weight::from_parts(71_196_000 as u64, 0)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(198_000 as u64).saturating_mul(c as u64))
.saturating_add(Weight::from_parts(198_000 as u64, 0).saturating_mul(c as u64))
.saturating_add(T::DbWeight::get().reads(4 as u64))
.saturating_add(T::DbWeight::get().writes(2 as u64))
}
fn leave_intent(c: u32) -> Weight {
Weight::from_ref_time(55_336_000 as u64)
Weight::from_parts(55_336_000 as u64, 0)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(151_000 as u64).saturating_mul(c as u64))
.saturating_add(Weight::from_parts(151_000 as u64, 0).saturating_mul(c as u64))
.saturating_add(T::DbWeight::get().reads(1 as u64))
.saturating_add(T::DbWeight::get().writes(2 as u64))
}
fn note_author() -> Weight {
Weight::from_ref_time(71_461_000 as u64)
Weight::from_parts(71_461_000 as u64, 0)
.saturating_add(T::DbWeight::get().reads(3 as u64))
.saturating_add(T::DbWeight::get().writes(4 as u64))
}
fn new_session(r: u32, c: u32) -> Weight {
Weight::from_ref_time(0 as u64)
Weight::from_parts(0 as u64, 0)
// Standard Error: 1_010_000
.saturating_add(Weight::from_ref_time(109_961_000 as u64).saturating_mul(r as u64))
.saturating_add(Weight::from_parts(109_961_000 as u64, 0).saturating_mul(r as u64))
// Standard Error: 1_010_000
.saturating_add(Weight::from_ref_time(151_952_000 as u64).saturating_mul(c as u64))
.saturating_add(Weight::from_parts(151_952_000 as u64, 0).saturating_mul(c as u64))
.saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(r as u64)))
.saturating_add(T::DbWeight::get().reads((2 as u64).saturating_mul(c as u64)))
.saturating_add(T::DbWeight::get().writes((2 as u64).saturating_mul(r as u64)))
Expand All @@ -85,44 +85,44 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// For backwards compatibility and tests
impl WeightInfo for () {
fn set_invulnerables(b: u32) -> Weight {
Weight::from_ref_time(18_563_000 as u64)
Weight::from_parts(18_563_000 as u64, 0)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(68_000 as u64).saturating_mul(b as u64))
.saturating_add(Weight::from_parts(68_000 as u64, 0).saturating_mul(b as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
fn set_desired_candidates() -> Weight {
Weight::from_ref_time(16_363_000 as u64)
Weight::from_parts(16_363_000 as u64, 0)
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
fn set_candidacy_bond() -> Weight {
Weight::from_ref_time(16_840_000 as u64)
Weight::from_parts(16_840_000 as u64, 0)
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
fn register_as_candidate(c: u32) -> Weight {
Weight::from_ref_time(71_196_000 as u64)
Weight::from_parts(71_196_000 as u64, 0)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(198_000 as u64).saturating_mul(c as u64))
.saturating_add(Weight::from_parts(198_000 as u64, 0).saturating_mul(c as u64))
.saturating_add(RocksDbWeight::get().reads(4 as u64))
.saturating_add(RocksDbWeight::get().writes(2 as u64))
}
fn leave_intent(c: u32) -> Weight {
Weight::from_ref_time(55_336_000 as u64)
Weight::from_parts(55_336_000 as u64, 0)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(151_000 as u64).saturating_mul(c as u64))
.saturating_add(Weight::from_parts(151_000 as u64, 0).saturating_mul(c as u64))
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(2 as u64))
}
fn note_author() -> Weight {
Weight::from_ref_time(71_461_000 as u64)
Weight::from_parts(71_461_000 as u64, 0)
.saturating_add(RocksDbWeight::get().reads(3 as u64))
.saturating_add(RocksDbWeight::get().writes(4 as u64))
}
fn new_session(r: u32, c: u32) -> Weight {
Weight::from_ref_time(0 as u64)
Weight::from_parts(0 as u64, 0)
// Standard Error: 1_010_000
.saturating_add(Weight::from_ref_time(109_961_000 as u64).saturating_mul(r as u64))
.saturating_add(Weight::from_parts(109_961_000 as u64, 0).saturating_mul(r as u64))
// Standard Error: 1_010_000
.saturating_add(Weight::from_ref_time(151_952_000 as u64).saturating_mul(c as u64))
.saturating_add(Weight::from_parts(151_952_000 as u64, 0).saturating_mul(c as u64))
.saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(r as u64)))
.saturating_add(RocksDbWeight::get().reads((2 as u64).saturating_mul(c as u64)))
.saturating_add(RocksDbWeight::get().writes((2 as u64).saturating_mul(r as u64)))
Expand Down
4 changes: 2 additions & 2 deletions pallets/dmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
/// Service a single overweight message.
#[pallet::call_index(0)]
#[pallet::weight(weight_limit.saturating_add(Weight::from_ref_time(1_000_000)))]
#[pallet::weight(weight_limit.saturating_add(Weight::from_parts(1_000_000, 0)))]
pub fn service_overweight(
origin: OriginFor<T>,
index: OverweightIndex,
Expand All @@ -167,7 +167,7 @@ pub mod pallet {
.map_err(|_| Error::<T>::OverLimit)?;
Overweight::<T>::remove(index);
Self::deposit_event(Event::OverweightServiced { overweight_index: index, weight_used });
Ok(Some(weight_used.saturating_add(Weight::from_ref_time(1_000_000))).into())
Ok(Some(weight_used.saturating_add(Weight::from_parts(1_000_000, 0))).into())
}
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/xcmp-queue/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use frame_system::RawOrigin;

benchmarks! {
set_config_with_u32 {}: update_resume_threshold(RawOrigin::Root, 100)
set_config_with_weight {}: update_weight_restrict_decay(RawOrigin::Root, Weight::from_ref_time(3_000_000))
set_config_with_weight {}: update_weight_restrict_decay(RawOrigin::Root, Weight::from_parts(3_000_000, 0))
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
8 changes: 4 additions & 4 deletions pallets/xcmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub mod pallet {
/// Events:
/// - `OverweightServiced`: On success.
#[pallet::call_index(0)]
#[pallet::weight((weight_limit.saturating_add(Weight::from_ref_time(1_000_000)), DispatchClass::Operational))]
#[pallet::weight((weight_limit.saturating_add(Weight::from_parts(1_000_000, 0)), DispatchClass::Operational))]
pub fn service_overweight(
origin: OriginFor<T>,
index: OverweightIndex,
Expand All @@ -161,7 +161,7 @@ pub mod pallet {
.map_err(|_| Error::<T>::WeightOverLimit)?;
Overweight::<T>::remove(index);
Self::deposit_event(Event::OverweightServiced { index, used });
Ok(Some(used.saturating_add(Weight::from_ref_time(1_000_000))).into())
Ok(Some(used.saturating_add(Weight::from_parts(1_000_000, 0))).into())
}

/// Suspends all XCM executions for the XCMP queue, regardless of the sender's origin.
Expand Down Expand Up @@ -467,8 +467,8 @@ impl Default for QueueConfigData {
suspend_threshold: 2,
drop_threshold: 5,
resume_threshold: 1,
threshold_weight: Weight::from_ref_time(100_000),
weight_restrict_decay: Weight::from_ref_time(2),
threshold_weight: Weight::from_parts(100_000, 0),
weight_restrict_decay: Weight::from_parts(2, 0),
xcmp_max_individual_weight: Weight::from_parts(
20u64 * WEIGHT_REF_TIME_PER_MILLIS,
DEFAULT_POV_SIZE,
Expand Down
4 changes: 2 additions & 2 deletions pallets/xcmp-queue/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ pub fn migrate_to_v2<T: Config>() -> Weight {
suspend_threshold: pre.suspend_threshold,
drop_threshold: pre.drop_threshold,
resume_threshold: pre.resume_threshold,
threshold_weight: Weight::from_ref_time(pre.threshold_weight),
weight_restrict_decay: Weight::from_ref_time(pre.weight_restrict_decay),
threshold_weight: Weight::from_parts(pre.threshold_weight, 0),
weight_restrict_decay: Weight::from_parts(pre.weight_restrict_decay, 0),
xcmp_max_individual_weight: Weight::from_parts(
pre.xcmp_max_individual_weight,
DEFAULT_POV_SIZE,
Expand Down
34 changes: 17 additions & 17 deletions pallets/xcmp-queue/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ fn bad_message_is_handled() {
1000.into(),
(1, format),
&mut 0,
Weight::from_ref_time(10_000_000_000),
Weight::from_ref_time(10_000_000_000),
Weight::from_parts(10_000_000_000, 0),
Weight::from_parts(10_000_000_000, 0),
);
});
}
Expand All @@ -71,8 +71,8 @@ fn handle_blob_message() {
1000.into(),
(1, format),
&mut 0,
Weight::from_ref_time(10_000_000_000),
Weight::from_ref_time(10_000_000_000),
Weight::from_parts(10_000_000_000, 0),
Weight::from_parts(10_000_000_000, 0),
);
});
}
Expand All @@ -89,8 +89,8 @@ fn handle_invalid_data() {
1000.into(),
(1, format),
&mut 0,
Weight::from_ref_time(10_000_000_000),
Weight::from_ref_time(10_000_000_000),
Weight::from_parts(10_000_000_000, 0),
Weight::from_parts(10_000_000_000, 0),
);
});
}
Expand Down Expand Up @@ -189,43 +189,43 @@ fn update_resume_threshold_works() {
fn update_threshold_weight_works() {
new_test_ext().execute_with(|| {
let data: QueueConfigData = <QueueConfig<Test>>::get();
assert_eq!(data.threshold_weight, Weight::from_ref_time(100_000));
assert_eq!(data.threshold_weight, Weight::from_parts(100_000, 0));
assert_ok!(XcmpQueue::update_threshold_weight(
RuntimeOrigin::root(),
Weight::from_ref_time(10_000)
Weight::from_parts(10_000, 0)
));
assert_noop!(
XcmpQueue::update_threshold_weight(
RuntimeOrigin::signed(5),
Weight::from_ref_time(10_000_000),
Weight::from_parts(10_000_000, 0),
),
BadOrigin
);
let data: QueueConfigData = <QueueConfig<Test>>::get();

assert_eq!(data.threshold_weight, Weight::from_ref_time(10_000));
assert_eq!(data.threshold_weight, Weight::from_parts(10_000, 0));
});
}

#[test]
fn update_weight_restrict_decay_works() {
new_test_ext().execute_with(|| {
let data: QueueConfigData = <QueueConfig<Test>>::get();
assert_eq!(data.weight_restrict_decay, Weight::from_ref_time(2));
assert_eq!(data.weight_restrict_decay, Weight::from_parts(2, 0));
assert_ok!(XcmpQueue::update_weight_restrict_decay(
RuntimeOrigin::root(),
Weight::from_ref_time(5)
Weight::from_parts(5, 0)
));
assert_noop!(
XcmpQueue::update_weight_restrict_decay(
RuntimeOrigin::signed(6),
Weight::from_ref_time(4),
Weight::from_parts(4, 0),
),
BadOrigin
);
let data: QueueConfigData = <QueueConfig<Test>>::get();

assert_eq!(data.weight_restrict_decay, Weight::from_ref_time(5));
assert_eq!(data.weight_restrict_decay, Weight::from_parts(5, 0));
});
}

Expand All @@ -239,20 +239,20 @@ fn update_xcmp_max_individual_weight() {
);
assert_ok!(XcmpQueue::update_xcmp_max_individual_weight(
RuntimeOrigin::root(),
Weight::from_ref_time(30u64 * WEIGHT_REF_TIME_PER_MILLIS)
Weight::from_parts(30u64 * WEIGHT_REF_TIME_PER_MILLIS, 0)
));
assert_noop!(
XcmpQueue::update_xcmp_max_individual_weight(
RuntimeOrigin::signed(3),
Weight::from_ref_time(10u64 * WEIGHT_REF_TIME_PER_MILLIS)
Weight::from_parts(10u64 * WEIGHT_REF_TIME_PER_MILLIS, 0)
),
BadOrigin
);
let data: QueueConfigData = <QueueConfig<Test>>::get();

assert_eq!(
data.xcmp_max_individual_weight,
Weight::from_ref_time(30u64 * WEIGHT_REF_TIME_PER_MILLIS)
Weight::from_parts(30u64 * WEIGHT_REF_TIME_PER_MILLIS, 0)
);
});
}
Expand Down
8 changes: 4 additions & 4 deletions pallets/xcmp-queue/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: XcmpQueue QueueConfig (r:1 w:1)
fn set_config_with_u32() -> Weight {
Weight::from_ref_time(2_717_000 as u64)
Weight::from_parts(2_717_000 as u64, 0)
.saturating_add(T::DbWeight::get().reads(1 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}

// Storage: XcmpQueue QueueConfig (r:1 w:1)
fn set_config_with_weight() -> Weight {
Weight::from_ref_time(2_717_000 as u64)
Weight::from_parts(2_717_000 as u64, 0)
.saturating_add(T::DbWeight::get().reads(1 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
Expand All @@ -34,14 +34,14 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
impl WeightInfo for () {
// Storage: XcmpQueue QueueConfig (r:1 w:1)
fn set_config_with_u32() -> Weight {
Weight::from_ref_time(2_717_000 as u64)
Weight::from_parts(2_717_000 as u64, 0)
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}

// Storage: XcmpQueue QueueConfig (r:1 w:1)
fn set_config_with_weight() -> Weight {
Weight::from_ref_time(2_717_000 as u64)
Weight::from_parts(2_717_000 as u64, 0)
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
Expand Down
4 changes: 2 additions & 2 deletions parachain-template/pallets/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub mod pallet {
/// An example dispatchable that takes a singles value as a parameter, writes the value to
/// storage and emits an event. This function must be dispatched by a signed extrinsic.
#[pallet::call_index(0)]
#[pallet::weight(Weight::from_ref_time(10_000) + T::DbWeight::get().writes(1))]
#[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))]
pub fn do_something(origin: OriginFor<T>, something: u32) -> DispatchResultWithPostInfo {
// Check that the extrinsic was signed and get the signer.
// This function will return an error if the extrinsic is not signed.
Expand All @@ -86,7 +86,7 @@ pub mod pallet {

/// An example dispatchable that may throw a custom error.
#[pallet::call_index(1)]
#[pallet::weight(Weight::from_ref_time(10_000) + T::DbWeight::get().reads_writes(1,1))]
#[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().reads_writes(1,1))]
pub fn cause_error(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let _who = ensure_signed(origin)?;

Expand Down
2 changes: 1 addition & 1 deletion parachain-template/runtime/src/weights/block_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod constants {
parameter_types! {
/// 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));
Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(5_000_000), 0);
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod constants {
parameter_types! {
/// 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));
Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(125_000), 0);
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod constants {
parameter_types! {
/// 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));
Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(5_000_000), 0);
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ impl<T: frame_system::Config> cumulus_pallet_xcmp_queue::WeightInfo for WeightIn
// Measured: `76`
// Estimated: `571`
// Minimum execution time: 4_956 nanoseconds.
Weight::from_ref_time(5_108_000)
.saturating_add(Weight::from_proof_size(571))
Weight::from_parts(5_108_000, 0)
.saturating_add(Weight::from_parts(0, 571))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
Expand All @@ -66,8 +66,8 @@ impl<T: frame_system::Config> cumulus_pallet_xcmp_queue::WeightInfo for WeightIn
// Measured: `76`
// Estimated: `571`
// Minimum execution time: 4_945 nanoseconds.
Weight::from_ref_time(5_080_000)
.saturating_add(Weight::from_proof_size(571))
Weight::from_parts(5_080_000, 0)
.saturating_add(Weight::from_parts(0, 571))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod constants {
parameter_types! {
/// 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));
Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(125_000), 0);
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit 5585023

Please sign in to comment.