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

Split Operational and Normal weight #5954

Merged
merged 12 commits into from
May 12, 2020
9 changes: 5 additions & 4 deletions bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pub struct TargetedFeeAdjustment<T>(sp_std::marker::PhantomData<T>);

impl<T: Get<Perquintill>> Convert<Fixed128, Fixed128> for TargetedFeeAdjustment<T> {
fn convert(multiplier: Fixed128) -> Fixed128 {
let block_weight = System::all_extrinsics_weight();
let max_weight = MaximumBlockWeight::get();
let block_weight = System::all_extrinsics_weight().total().min(max_weight);
let target_weight = (T::get() * max_weight) as u128;
let block_weight = block_weight as u128;

Expand Down Expand Up @@ -132,11 +132,12 @@ mod tests {

// poc reference implementation.
fn fee_multiplier_update(block_weight: Weight, previous: Fixed128) -> Fixed128 {
let block_weight = block_weight as f64;
let v: f64 = 0.00004;

// maximum tx weight
let m = max() as f64;
// block weight always truncated to max weight
let block_weight = (block_weight as f64).min(m);
let v: f64 = 0.00004;

// Ideal saturation in terms of weight
let ss = target() as f64;
// Current saturation in terms of weight
Expand Down
18 changes: 9 additions & 9 deletions frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@

use sp_std::{prelude::*, marker::PhantomData};
use frame_support::{
storage::StorageValue, weights::{GetDispatchInfo, DispatchInfo},
storage::StorageValue, weights::{GetDispatchInfo, DispatchInfo, DispatchClass},
traits::{OnInitialize, OnFinalize, OnRuntimeUpgrade, OffchainWorker},
};
use sp_runtime::{
Expand Down Expand Up @@ -235,7 +235,7 @@ where
let mut weight = <frame_system::Module::<System> as OnRuntimeUpgrade>::on_runtime_upgrade();
weight = weight.saturating_add(COnRuntimeUpgrade::on_runtime_upgrade());
weight = weight.saturating_add(<AllModules as OnRuntimeUpgrade>::on_runtime_upgrade());
<frame_system::Module<System>>::register_extra_weight_unchecked(weight);
<frame_system::Module<System>>::register_extra_weight_unchecked(weight, DispatchClass::Mandatory);
}
<frame_system::Module<System>>::initialize(
block_number,
Expand All @@ -247,7 +247,7 @@ where
<frame_system::Module<System> as OnInitialize<System::BlockNumber>>::on_initialize(*block_number);
let weight = <AllModules as OnInitialize<System::BlockNumber>>::on_initialize(*block_number)
.saturating_add(<System::BlockExecutionWeight as frame_support::traits::Get<_>>::get());
<frame_system::Module::<System>>::register_extra_weight_unchecked(weight);
<frame_system::Module::<System>>::register_extra_weight_unchecked(weight, DispatchClass::Mandatory);

frame_system::Module::<System>::note_finished_initialize();
}
Expand Down Expand Up @@ -785,7 +785,7 @@ mod tests {
Digest::default(),
));
// Base block execution weight + `on_initialize` weight from the custom module.
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_weight(), base_block_weight);
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_weight().total(), base_block_weight);

for nonce in 0..=num_to_exhaust_block {
let xt = TestXt::new(
Expand All @@ -795,7 +795,7 @@ mod tests {
if nonce != num_to_exhaust_block {
assert!(res.is_ok());
assert_eq!(
<frame_system::Module<Runtime>>::all_extrinsics_weight(),
<frame_system::Module<Runtime>>::all_extrinsics_weight().total(),
//--------------------- on_initialize + block_execution + extrinsic_base weight
(encoded_len + 5) * (nonce + 1) + base_block_weight,
);
Expand All @@ -815,7 +815,7 @@ mod tests {
let len = xt.clone().encode().len() as u32;
let mut t = new_test_ext(1);
t.execute_with(|| {
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_weight(), 0);
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_weight().total(), 0);
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_len(), 0);

assert!(Executive::apply_extrinsic(xt.clone()).unwrap().is_ok());
Expand All @@ -824,14 +824,14 @@ mod tests {

// default weight for `TestXt` == encoded length.
assert_eq!(
<frame_system::Module<Runtime>>::all_extrinsics_weight(),
<frame_system::Module<Runtime>>::all_extrinsics_weight().total(),
3 * (len as Weight + <Runtime as frame_system::Trait>::ExtrinsicBaseWeight::get()),
);
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_len(), 3 * len);

let _ = <frame_system::Module<Runtime>>::finalize();

assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_weight(), 0);
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_weight().total(), 0);
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_len(), 0);
});
}
Expand Down Expand Up @@ -903,7 +903,7 @@ mod tests {
// NOTE: might need updates over time if new weights are introduced.
// For now it only accounts for the base block execution weight and
// the `on_initialize` weight defined in the custom test module.
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_weight(), 175 + 10);
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_weight().total(), 175 + 10);
})
}

Expand Down
Loading