Deprecate Weight::from_{ref_time, proof_size} (#13475)

* Deprecate Weight::from_{ref_time, proof_size}

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

* Update templates

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

* Use from_parts

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

* Use from_parts

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

* Dont revert comment 🤦

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

* ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_balances

* Update weight files

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

* More fixes

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

* Adapt to Master changes

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

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: command-bot <>
This commit is contained in:
Oliver Tale-Yazdi
2023-03-02 22:28:17 +01:00
committed by GitHub
parent 7981d4aa59
commit 9e56e1acdd
101 changed files with 2695 additions and 2857 deletions
@@ -130,7 +130,7 @@ mod tests {
fn signed_ext_check_era_should_change_longevity() {
new_test_ext().execute_with(|| {
let normal = DispatchInfo {
weight: Weight::from_ref_time(100),
weight: Weight::from_parts(100, 0),
class: DispatchClass::Normal,
pays_fee: Pays::Yes,
};
@@ -308,7 +308,7 @@ mod tests {
new_test_ext().execute_with(|| {
let max = DispatchInfo {
weight: block_weights().get(DispatchClass::Normal).max_extrinsic.unwrap() +
Weight::from_ref_time(1),
Weight::from_parts(1, 0),
class: DispatchClass::Normal,
..Default::default()
};
@@ -334,7 +334,7 @@ mod tests {
let okay =
DispatchInfo { weight, class: DispatchClass::Operational, ..Default::default() };
let max = DispatchInfo {
weight: weight + Weight::from_ref_time(1),
weight: weight + Weight::from_parts(1, 0),
class: DispatchClass::Operational,
..Default::default()
};
@@ -366,9 +366,9 @@ mod tests {
// So normal extrinsic can be 758 weight (-5 for base extrinsic weight)
// And Operational can be 246 to produce a full block (-10 for base)
let max_normal =
DispatchInfo { weight: Weight::from_ref_time(753), ..Default::default() };
DispatchInfo { weight: Weight::from_parts(753, 0), ..Default::default() };
let rest_operational = DispatchInfo {
weight: Weight::from_ref_time(246),
weight: Weight::from_parts(246, 0),
class: DispatchClass::Operational,
..Default::default()
};
@@ -376,9 +376,9 @@ mod tests {
let len = 0_usize;
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
assert_eq!(System::block_weight().total(), Weight::from_ref_time(768));
assert_eq!(System::block_weight().total(), Weight::from_parts(768, 0));
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&rest_operational, len));
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024).set_proof_size(u64::MAX));
assert_eq!(block_weight_limit(), Weight::from_parts(1024, u64::MAX));
assert_eq!(System::block_weight().total(), block_weight_limit().set_proof_size(0));
// Checking single extrinsic should not take current block weight into account.
assert_eq!(CheckWeight::<Test>::check_extrinsic_weight(&rest_operational), Ok(()));
@@ -390,9 +390,9 @@ mod tests {
new_test_ext().execute_with(|| {
// We switch the order of `full_block_with_normal_and_operational`
let max_normal =
DispatchInfo { weight: Weight::from_ref_time(753), ..Default::default() };
DispatchInfo { weight: Weight::from_parts(753, 0), ..Default::default() };
let rest_operational = DispatchInfo {
weight: Weight::from_ref_time(246),
weight: Weight::from_parts(246, 0),
class: DispatchClass::Operational,
..Default::default()
};
@@ -401,9 +401,9 @@ mod tests {
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&rest_operational, len));
// Extra 20 here from block execution + base extrinsic weight
assert_eq!(System::block_weight().total(), Weight::from_ref_time(266));
assert_eq!(System::block_weight().total(), Weight::from_parts(266, 0));
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024).set_proof_size(u64::MAX));
assert_eq!(block_weight_limit(), Weight::from_parts(1024, u64::MAX));
assert_eq!(System::block_weight().total(), block_weight_limit().set_proof_size(0));
});
}
@@ -414,12 +414,12 @@ mod tests {
// An on_initialize takes up the whole block! (Every time!)
System::register_extra_weight_unchecked(Weight::MAX, DispatchClass::Mandatory);
let dispatch_normal = DispatchInfo {
weight: Weight::from_ref_time(251),
weight: Weight::from_parts(251, 0),
class: DispatchClass::Normal,
..Default::default()
};
let dispatch_operational = DispatchInfo {
weight: Weight::from_ref_time(246),
weight: Weight::from_parts(246, 0),
class: DispatchClass::Operational,
..Default::default()
};
@@ -445,9 +445,9 @@ mod tests {
#[test]
fn signed_ext_check_weight_works_operational_tx() {
new_test_ext().execute_with(|| {
let normal = DispatchInfo { weight: Weight::from_ref_time(100), ..Default::default() };
let normal = DispatchInfo { weight: Weight::from_parts(100, 0), ..Default::default() };
let op = DispatchInfo {
weight: Weight::from_ref_time(100),
weight: Weight::from_parts(100, 0),
class: DispatchClass::Operational,
pays_fee: Pays::Yes,
};
@@ -513,12 +513,12 @@ mod tests {
fn signed_ext_check_weight_works_normal_tx() {
new_test_ext().execute_with(|| {
let normal_limit = normal_weight_limit();
let small = DispatchInfo { weight: Weight::from_ref_time(100), ..Default::default() };
let small = DispatchInfo { weight: Weight::from_parts(100, 0), ..Default::default() };
let base_extrinsic = block_weights().get(DispatchClass::Normal).base_extrinsic;
let medium =
DispatchInfo { weight: normal_limit - base_extrinsic, ..Default::default() };
let big = DispatchInfo {
weight: normal_limit - base_extrinsic + Weight::from_ref_time(1),
weight: normal_limit - base_extrinsic + Weight::from_parts(1, 0),
..Default::default()
};
let len = 0_usize;
@@ -537,7 +537,7 @@ mod tests {
reset_check_weight(&small, false, Weight::zero());
reset_check_weight(&medium, false, Weight::zero());
reset_check_weight(&big, true, Weight::from_ref_time(1));
reset_check_weight(&big, true, Weight::from_parts(1, 0));
})
}
@@ -545,9 +545,9 @@ mod tests {
fn signed_ext_check_weight_refund_works() {
new_test_ext().execute_with(|| {
// This is half of the max block weight
let info = DispatchInfo { weight: Weight::from_ref_time(512), ..Default::default() };
let info = DispatchInfo { weight: Weight::from_parts(512, 0), ..Default::default() };
let post_info = PostDispatchInfo {
actual_weight: Some(Weight::from_ref_time(128)),
actual_weight: Some(Weight::from_parts(128, 0)),
pays_fee: Default::default(),
};
let len = 0_usize;
@@ -557,13 +557,13 @@ mod tests {
BlockWeight::<Test>::mutate(|current_weight| {
current_weight.set(Weight::zero(), DispatchClass::Mandatory);
current_weight
.set(Weight::from_ref_time(256) - base_extrinsic, DispatchClass::Normal);
.set(Weight::from_parts(256, 0) - base_extrinsic, DispatchClass::Normal);
});
let pre = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &info, len).unwrap();
assert_eq!(
BlockWeight::<Test>::get().total(),
info.weight + Weight::from_ref_time(256)
info.weight + Weight::from_parts(256, 0)
);
assert_ok!(CheckWeight::<Test>::post_dispatch(
@@ -575,7 +575,7 @@ mod tests {
));
assert_eq!(
BlockWeight::<Test>::get().total(),
post_info.actual_weight.unwrap() + Weight::from_ref_time(256)
post_info.actual_weight.unwrap() + Weight::from_parts(256, 0)
);
})
}
@@ -583,23 +583,23 @@ mod tests {
#[test]
fn signed_ext_check_weight_actual_weight_higher_than_max_is_capped() {
new_test_ext().execute_with(|| {
let info = DispatchInfo { weight: Weight::from_ref_time(512), ..Default::default() };
let info = DispatchInfo { weight: Weight::from_parts(512, 0), ..Default::default() };
let post_info = PostDispatchInfo {
actual_weight: Some(Weight::from_ref_time(700)),
actual_weight: Some(Weight::from_parts(700, 0)),
pays_fee: Default::default(),
};
let len = 0_usize;
BlockWeight::<Test>::mutate(|current_weight| {
current_weight.set(Weight::zero(), DispatchClass::Mandatory);
current_weight.set(Weight::from_ref_time(128), DispatchClass::Normal);
current_weight.set(Weight::from_parts(128, 0), DispatchClass::Normal);
});
let pre = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &info, len).unwrap();
assert_eq!(
BlockWeight::<Test>::get().total(),
info.weight +
Weight::from_ref_time(128) +
Weight::from_parts(128, 0) +
block_weights().get(DispatchClass::Normal).base_extrinsic,
);
@@ -613,7 +613,7 @@ mod tests {
assert_eq!(
BlockWeight::<Test>::get().total(),
info.weight +
Weight::from_ref_time(128) +
Weight::from_parts(128, 0) +
block_weights().get(DispatchClass::Normal).base_extrinsic,
);
})
@@ -643,9 +643,9 @@ mod tests {
// Max normal is 768 (75%)
// Max mandatory is unlimited
let max_normal =
DispatchInfo { weight: Weight::from_ref_time(753), ..Default::default() };
DispatchInfo { weight: Weight::from_parts(753, 0), ..Default::default() };
let mandatory = DispatchInfo {
weight: Weight::from_ref_time(1019),
weight: Weight::from_parts(1019, 0),
class: DispatchClass::Mandatory,
..Default::default()
};
@@ -653,10 +653,10 @@ mod tests {
let len = 0_usize;
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
assert_eq!(System::block_weight().total(), Weight::from_ref_time(768));
assert_eq!(System::block_weight().total(), Weight::from_parts(768, 0));
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&mandatory, len));
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024).set_proof_size(u64::MAX));
assert_eq!(System::block_weight().total(), Weight::from_ref_time(1024 + 768));
assert_eq!(block_weight_limit(), Weight::from_parts(1024, u64::MAX));
assert_eq!(System::block_weight().total(), Weight::from_parts(1024 + 768, 0));
assert_eq!(CheckWeight::<Test>::check_extrinsic_weight(&mandatory), Ok(()));
});
}
@@ -668,30 +668,30 @@ mod tests {
.base_block(Weight::zero())
.for_class(DispatchClass::non_mandatory(), |w| {
w.base_extrinsic = Weight::zero();
w.max_total = Some(Weight::from_ref_time(20).set_proof_size(u64::MAX));
w.max_total = Some(Weight::from_parts(20, u64::MAX));
})
.for_class(DispatchClass::Mandatory, |w| {
w.base_extrinsic = Weight::zero();
w.reserved = Some(Weight::from_ref_time(5).set_proof_size(u64::MAX));
w.reserved = Some(Weight::from_parts(5, u64::MAX));
w.max_total = None;
})
.build_or_panic();
let all_weight = crate::ConsumedWeight::new(|class| match class {
DispatchClass::Normal => Weight::from_ref_time(10),
DispatchClass::Operational => Weight::from_ref_time(10),
DispatchClass::Normal => Weight::from_parts(10, 0),
DispatchClass::Operational => Weight::from_parts(10, 0),
DispatchClass::Mandatory => Weight::zero(),
});
assert_eq!(maximum_weight.max_block, all_weight.total().set_proof_size(u64::MAX));
// fits into reserved
let mandatory1 = DispatchInfo {
weight: Weight::from_ref_time(5),
weight: Weight::from_parts(5, 0),
class: DispatchClass::Mandatory,
..Default::default()
};
// does not fit into reserved and the block is full.
let mandatory2 = DispatchInfo {
weight: Weight::from_ref_time(6),
weight: Weight::from_parts(6, 0),
class: DispatchClass::Mandatory,
..Default::default()
};