From 15a3dc9fd75ead7b18da2c75d48a9aabd70334d4 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Fri, 9 Jun 2023 17:59:33 +0200 Subject: [PATCH 1/9] pallet-glutton: over-unity consumption --- frame/glutton/src/benchmarking.rs | 13 +++++----- frame/glutton/src/lib.rs | 43 +++++++++++++++---------------- frame/glutton/src/tests.rs | 37 +++++++++++++------------- primitives/arithmetic/src/lib.rs | 4 ++- primitives/runtime/src/lib.rs | 2 +- 5 files changed, 51 insertions(+), 48 deletions(-) diff --git a/frame/glutton/src/benchmarking.rs b/frame/glutton/src/benchmarking.rs index 13576ae2f3d98..587207587456a 100644 --- a/frame/glutton/src/benchmarking.rs +++ b/frame/glutton/src/benchmarking.rs @@ -25,6 +25,7 @@ use super::*; use frame_benchmarking::benchmarks; use frame_support::{pallet_prelude::*, weights::constants::*}; use frame_system::RawOrigin as SystemOrigin; +use sp_runtime::{traits::One, Perbill}; use crate::Pallet as Glutton; use frame_system::Pallet as System; @@ -67,8 +68,8 @@ benchmarks! { // For manual verification only. on_idle_high_proof_waste { (0..5000).for_each(|i| TrashData::::insert(i, [i as u8; 1024])); - let _ = Glutton::::set_compute(SystemOrigin::Root.into(), Perbill::from_percent(100)); - let _ = Glutton::::set_storage(SystemOrigin::Root.into(), Perbill::from_percent(100)); + let _ = Glutton::::set_compute(SystemOrigin::Root.into(), One::one()); + let _ = Glutton::::set_storage(SystemOrigin::Root.into(), One::one()); }: { let weight = Glutton::::on_idle(System::::block_number(), Weight::from_parts(WEIGHT_REF_TIME_PER_MILLIS * 100, WEIGHT_PROOF_SIZE_PER_MB * 5)); } @@ -76,8 +77,8 @@ benchmarks! { // For manual verification only. on_idle_low_proof_waste { (0..5000).for_each(|i| TrashData::::insert(i, [i as u8; 1024])); - let _ = Glutton::::set_compute(SystemOrigin::Root.into(), Perbill::from_percent(100)); - let _ = Glutton::::set_storage(SystemOrigin::Root.into(), Perbill::from_percent(100)); + let _ = Glutton::::set_compute(SystemOrigin::Root.into(), One::one()); + let _ = Glutton::::set_storage(SystemOrigin::Root.into(), One::one()); }: { let weight = Glutton::::on_idle(System::::block_number(), Weight::from_parts(WEIGHT_REF_TIME_PER_MILLIS * 100, WEIGHT_PROOF_SIZE_PER_KB * 20)); } @@ -89,10 +90,10 @@ benchmarks! { } set_compute { - }: _(SystemOrigin::Root, Perbill::from_percent(50)) + }: _(SystemOrigin::Root, FixedU64::from_perbill(Perbill::from_percent(50))) set_storage { - }: _(SystemOrigin::Root, Perbill::from_percent(50)) + }: _(SystemOrigin::Root, FixedU64::from_perbill(Perbill::from_percent(50))) impl_benchmark_test_suite!(Glutton, crate::mock::new_test_ext(), crate::mock::Test); } diff --git a/frame/glutton/src/lib.rs b/frame/glutton/src/lib.rs index 50a26a495f794..16a9db7b7f1c2 100644 --- a/frame/glutton/src/lib.rs +++ b/frame/glutton/src/lib.rs @@ -32,10 +32,10 @@ mod tests; pub mod weights; use blake2::{Blake2b512, Digest}; -use frame_support::{pallet_prelude::*, weights::WeightMeter}; +use frame_support::{pallet_prelude::*, weights::WeightMeter, DefaultNoBound}; use frame_system::pallet_prelude::*; use sp_io::hashing::twox_256; -use sp_runtime::{traits::Zero, Perbill}; +use sp_runtime::{traits::Zero, FixedPointNumber, FixedU64}; use sp_std::{vec, vec::Vec}; pub use pallet::*; @@ -52,6 +52,7 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { + /// The overarching event type. type RuntimeEvent: From + IsType<::RuntimeEvent>; /// The admin origin that can set computational limits and initialize the pallet. @@ -70,9 +71,9 @@ pub mod pallet { /// The pallet has been (re)initialized. PalletInitialized { reinit: bool }, /// The computation limit has been updated. - ComputationLimitSet { compute: Perbill }, + ComputationLimitSet { compute: FixedU64 }, /// The storage limit has been updated. - StorageLimitSet { storage: Perbill }, + StorageLimitSet { storage: FixedU64 }, } #[pallet::error] @@ -81,17 +82,19 @@ pub mod pallet { /// /// Set `witness_count` to `Some` to bypass this error. AlreadyInitialized, + /// The limit was over 10,000%. + InsaneLimit, } /// Storage value used to specify what percentage of the left over `ref_time` /// to consume during `on_idle`. #[pallet::storage] - pub(crate) type Compute = StorageValue<_, Perbill, ValueQuery>; + pub(crate) type Compute = StorageValue<_, FixedU64, ValueQuery>; /// Storage value used the specify what percentage of left over `proof_size` /// to consume during `on_idle`. #[pallet::storage] - pub(crate) type Storage = StorageValue<_, Perbill, ValueQuery>; + pub(crate) type Storage = StorageValue<_, FixedU64, ValueQuery>; /// Storage map used for wasting proof size. /// @@ -115,22 +118,13 @@ pub mod pallet { pub(crate) type TrashDataCount = StorageValue<_, u32, ValueQuery>; #[pallet::genesis_config] + #[derive(DefaultNoBound)] pub struct GenesisConfig { - pub compute: Perbill, - pub storage: Perbill, + pub compute: FixedU64, + pub storage: FixedU64, pub trash_data_count: u32, } - impl Default for GenesisConfig { - fn default() -> Self { - Self { - compute: Default::default(), - storage: Default::default(), - trash_data_count: Default::default(), - } - } - } - #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { @@ -169,9 +163,10 @@ pub mod pallet { return T::WeightInfo::empty_on_idle() } - let proof_size_limit = Storage::::get().mul_floor(meter.remaining().proof_size()); + let proof_size_limit = + Storage::::get().saturating_mul_int(meter.remaining().proof_size()); let computation_weight_limit = - Compute::::get().mul_floor(meter.remaining().ref_time()); + Compute::::get().saturating_mul_int(meter.remaining().ref_time()); let mut meter = WeightMeter::from_limit(Weight::from_parts( computation_weight_limit, proof_size_limit, @@ -228,8 +223,10 @@ pub mod pallet { /// Only callable by Root or `AdminOrigin`. #[pallet::call_index(1)] #[pallet::weight(T::WeightInfo::set_compute())] - pub fn set_compute(origin: OriginFor, compute: Perbill) -> DispatchResult { + pub fn set_compute(origin: OriginFor, compute: FixedU64) -> DispatchResult { T::AdminOrigin::try_origin(origin).map(|_| ()).or_else(|o| ensure_root(o))?; + // Ensure that it is <= 10,000%. + ensure!(compute <= FixedU64::from_u32(100), Error::::InsaneLimit); Compute::::set(compute); @@ -247,8 +244,10 @@ pub mod pallet { /// Only callable by Root or `AdminOrigin`. #[pallet::call_index(2)] #[pallet::weight(T::WeightInfo::set_storage())] - pub fn set_storage(origin: OriginFor, storage: Perbill) -> DispatchResult { + pub fn set_storage(origin: OriginFor, storage: FixedU64) -> DispatchResult { T::AdminOrigin::try_origin(origin).map(|_| ()).or_else(|o| ensure_root(o))?; + // Ensure that it is <= 10,000%. + ensure!(storage <= FixedU64::from_u32(100), Error::::InsaneLimit); Storage::::set(storage); diff --git a/frame/glutton/src/tests.rs b/frame/glutton/src/tests.rs index ba215e1eea1c3..3f76dac620521 100644 --- a/frame/glutton/src/tests.rs +++ b/frame/glutton/src/tests.rs @@ -21,6 +21,7 @@ use super::*; use mock::{new_test_ext, Glutton, RuntimeOrigin, System, Test}; use frame_support::{assert_err, assert_noop, assert_ok, weights::constants::*}; +use sp_runtime::{traits::One, Perbill}; #[test] fn initialize_pallet_works() { @@ -86,20 +87,20 @@ fn expand_and_shrink_trash_data_works() { #[test] fn setting_compute_works() { new_test_ext().execute_with(|| { - assert_eq!(Compute::::get(), Perbill::from_percent(0)); + assert_eq!(Compute::::get(), Zero::zero()); - assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), Perbill::from_percent(70))); - assert_eq!(Compute::::get(), Perbill::from_percent(70)); + assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_float(0.3))); + assert_eq!(Compute::::get(), FixedU64::from_float(0.3)); System::assert_last_event( - Event::ComputationLimitSet { compute: Perbill::from_percent(70) }.into(), + Event::ComputationLimitSet { compute: FixedU64::from_float(0.3) }.into(), ); assert_noop!( - Glutton::set_compute(RuntimeOrigin::signed(1), Perbill::from_percent(30)), + Glutton::set_compute(RuntimeOrigin::signed(1), FixedU64::from_float(0.3)), DispatchError::BadOrigin ); assert_noop!( - Glutton::set_compute(RuntimeOrigin::none(), Perbill::from_percent(30)), + Glutton::set_compute(RuntimeOrigin::none(), FixedU64::from_float(0.3)), DispatchError::BadOrigin ); }); @@ -108,20 +109,20 @@ fn setting_compute_works() { #[test] fn setting_storage_works() { new_test_ext().execute_with(|| { - assert_eq!(Storage::::get(), Perbill::from_percent(0)); + assert!(Storage::::get().is_zero()); - assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), Perbill::from_percent(30))); - assert_eq!(Storage::::get(), Perbill::from_percent(30)); + assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), FixedU64::from_float(0.3))); + assert_eq!(Storage::::get(), FixedU64::from_float(0.3)); System::assert_last_event( - Event::StorageLimitSet { storage: Perbill::from_percent(30) }.into(), + Event::StorageLimitSet { storage: FixedU64::from_float(0.3) }.into(), ); assert_noop!( - Glutton::set_storage(RuntimeOrigin::signed(1), Perbill::from_percent(90)), + Glutton::set_storage(RuntimeOrigin::signed(1), FixedU64::from_float(0.3)), DispatchError::BadOrigin ); assert_noop!( - Glutton::set_storage(RuntimeOrigin::none(), Perbill::from_percent(90)), + Glutton::set_storage(RuntimeOrigin::none(), FixedU64::from_float(0.3)), DispatchError::BadOrigin ); }); @@ -130,8 +131,8 @@ fn setting_storage_works() { #[test] fn on_idle_works() { new_test_ext().execute_with(|| { - assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), Perbill::from_percent(100))); - assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), Perbill::from_percent(100))); + assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), One::one())); + assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), One::one())); Glutton::on_idle(1, Weight::from_parts(20_000_000, 0)); }); @@ -141,8 +142,8 @@ fn on_idle_works() { #[test] fn on_idle_weight_high_proof_is_close_enough_works() { new_test_ext().execute_with(|| { - assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), Perbill::from_percent(100))); - assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), Perbill::from_percent(100))); + assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), One::one())); + assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), One::one())); let should = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, WEIGHT_PROOF_SIZE_PER_MB * 5); let got = Glutton::on_idle(1, should); @@ -167,8 +168,8 @@ fn on_idle_weight_high_proof_is_close_enough_works() { #[test] fn on_idle_weight_low_proof_is_close_enough_works() { new_test_ext().execute_with(|| { - assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), Perbill::from_percent(100))); - assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), Perbill::from_percent(100))); + assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::one())); + assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), FixedU64::one())); let should = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, WEIGHT_PROOF_SIZE_PER_KB * 20); let got = Glutton::on_idle(1, should); diff --git a/primitives/arithmetic/src/lib.rs b/primitives/arithmetic/src/lib.rs index d2eceafab5ed0..900f0b75c3bf4 100644 --- a/primitives/arithmetic/src/lib.rs +++ b/primitives/arithmetic/src/lib.rs @@ -40,7 +40,9 @@ pub mod per_things; pub mod rational; pub mod traits; -pub use fixed_point::{FixedI128, FixedI64, FixedPointNumber, FixedPointOperand, FixedU128}; +pub use fixed_point::{ + FixedI128, FixedI64, FixedPointNumber, FixedPointOperand, FixedU128, FixedU64, +}; pub use per_things::{ InnerOf, MultiplyArg, PerThing, PerU16, Perbill, Percent, Permill, Perquintill, RationalArg, ReciprocalArg, Rounding, SignedRounding, UpperOf, diff --git a/primitives/runtime/src/lib.rs b/primitives/runtime/src/lib.rs index 363881e431e0e..56e4efcad2c05 100644 --- a/primitives/runtime/src/lib.rs +++ b/primitives/runtime/src/lib.rs @@ -96,7 +96,7 @@ pub use sp_arithmetic::helpers_128bit; /// Re-export top-level arithmetic stuff. pub use sp_arithmetic::{ traits::SaturatedConversion, ArithmeticError, FixedI128, FixedI64, FixedPointNumber, - FixedPointOperand, FixedU128, InnerOf, PerThing, PerU16, Perbill, Percent, Permill, + FixedPointOperand, FixedU128, FixedU64, InnerOf, PerThing, PerU16, Perbill, Percent, Permill, Perquintill, Rational128, Rounding, UpperOf, }; From f265a1296bc5a7da05b864c2b6a4a6e29c3f5f67 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Sat, 10 Jun 2023 16:07:55 +0200 Subject: [PATCH 2/9] Add hard limit Signed-off-by: Oliver Tale-Yazdi --- frame/glutton/src/lib.rs | 13 ++++++++----- frame/glutton/src/tests.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/frame/glutton/src/lib.rs b/frame/glutton/src/lib.rs index 16a9db7b7f1c2..6908a7a6bd343 100644 --- a/frame/glutton/src/lib.rs +++ b/frame/glutton/src/lib.rs @@ -45,6 +45,8 @@ pub use weights::WeightInfo; pub const VALUE_SIZE: usize = 1024; /// Max number of entries for `TrashData` storage item pub const MAX_TRASH_DATA_ENTRIES: u32 = 65_000; +/// Hard limit for any other resource limit (in units). +pub const RESOURCE_HARD_LIMIT: FixedU64 = FixedU64::from_u32(10); #[frame_support::pallet] pub mod pallet { @@ -82,7 +84,7 @@ pub mod pallet { /// /// Set `witness_count` to `Some` to bypass this error. AlreadyInitialized, - /// The limit was over 10,000%. + /// The limit was over [`crate::RESOURCE_HARD_LIMIT`]. InsaneLimit, } @@ -139,7 +141,10 @@ pub mod pallet { TrashDataCount::::set(self.trash_data_count); + assert!(self.compute <= RESOURCE_HARD_LIMIT, "Compute limit is insane"); >::put(self.compute); + + assert!(self.storage <= RESOURCE_HARD_LIMIT, "Storage limit is insane"); >::put(self.storage); } } @@ -225,8 +230,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::set_compute())] pub fn set_compute(origin: OriginFor, compute: FixedU64) -> DispatchResult { T::AdminOrigin::try_origin(origin).map(|_| ()).or_else(|o| ensure_root(o))?; - // Ensure that it is <= 10,000%. - ensure!(compute <= FixedU64::from_u32(100), Error::::InsaneLimit); + ensure!(compute <= RESOURCE_HARD_LIMIT, Error::::InsaneLimit); Compute::::set(compute); @@ -246,8 +250,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::set_storage())] pub fn set_storage(origin: OriginFor, storage: FixedU64) -> DispatchResult { T::AdminOrigin::try_origin(origin).map(|_| ()).or_else(|o| ensure_root(o))?; - // Ensure that it is <= 10,000%. - ensure!(storage <= FixedU64::from_u32(100), Error::::InsaneLimit); + ensure!(storage <= RESOURCE_HARD_LIMIT, Error::::InsaneLimit); Storage::::set(storage); diff --git a/frame/glutton/src/tests.rs b/frame/glutton/src/tests.rs index 3f76dac620521..91ccdfb33c339 100644 --- a/frame/glutton/src/tests.rs +++ b/frame/glutton/src/tests.rs @@ -106,6 +106,21 @@ fn setting_compute_works() { }); } +#[test] +fn setting_compute_respects_limit() { + new_test_ext().execute_with(|| { + // < 1000% is fine + assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_float(9.99)),); + // == 1000% is fine + assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_u32(10)),); + // > 1000% is not + assert_noop!( + Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_float(10.01)), + Error::::InsaneLimit + ); + }); +} + #[test] fn setting_storage_works() { new_test_ext().execute_with(|| { @@ -128,6 +143,21 @@ fn setting_storage_works() { }); } +#[test] +fn setting_storage_respects_limit() { + new_test_ext().execute_with(|| { + // < 1000% is fine + assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), FixedU64::from_float(9.99)),); + // == 1000% is fine + assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), FixedU64::from_u32(10)),); + // > 1000% is not + assert_noop!( + Glutton::set_storage(RuntimeOrigin::root(), FixedU64::from_float(10.01)), + Error::::InsaneLimit + ); + }); +} + #[test] fn on_idle_works() { new_test_ext().execute_with(|| { From f1b4198b79e3a38e66d79f6d61b36eb820e6c763 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Sat, 10 Jun 2023 16:15:22 +0200 Subject: [PATCH 3/9] Tests Signed-off-by: Oliver Tale-Yazdi --- frame/glutton/src/tests.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/frame/glutton/src/tests.rs b/frame/glutton/src/tests.rs index 91ccdfb33c339..d70714948d102 100644 --- a/frame/glutton/src/tests.rs +++ b/frame/glutton/src/tests.rs @@ -23,6 +23,8 @@ use mock::{new_test_ext, Glutton, RuntimeOrigin, System, Test}; use frame_support::{assert_err, assert_noop, assert_ok, weights::constants::*}; use sp_runtime::{traits::One, Perbill}; +const CALIBRATION_ERROR: &'static str = "Weight calibration failed. Please re-run the benchmarks on the same hardware."; + #[test] fn initialize_pallet_works() { new_test_ext().execute_with(|| { @@ -182,14 +184,14 @@ fn on_idle_weight_high_proof_is_close_enough_works() { let ratio = Perbill::from_rational(got.proof_size(), should.proof_size()); assert!( ratio >= Perbill::from_percent(99), - "Too few proof size consumed, was only {:?} of expected", + "{CALIBRATION_ERROR}\nToo few proof size consumed, was only {:?} of expected", ratio ); - + let ratio = Perbill::from_rational(got.ref_time(), should.ref_time()); assert!( ratio >= Perbill::from_percent(99), - "Too few ref time consumed, was only {:?} of expected", + "{CALIBRATION_ERROR}\nToo few ref time consumed, was only {:?} of expected", ratio ); }); @@ -206,7 +208,7 @@ fn on_idle_weight_low_proof_is_close_enough_works() { assert!(got.all_lte(should), "Consumed too much weight"); let ratio = Perbill::from_rational(got.proof_size(), should.proof_size()); - // Just a sanity check here. + // Just a sanity check here for > 0 assert!( ratio >= Perbill::from_percent(50), "Too few proof size consumed, was only {:?} of expected", @@ -216,7 +218,7 @@ fn on_idle_weight_low_proof_is_close_enough_works() { let ratio = Perbill::from_rational(got.ref_time(), should.ref_time()); assert!( ratio >= Perbill::from_percent(99), - "Too few ref time consumed, was only {:?} of expected", + "{CALIBRATION_ERROR}\nToo few ref time consumed, was only {:?} of expected", ratio ); }); @@ -233,7 +235,7 @@ fn waste_at_most_ref_time_weight_close_enough() { // We require it to be under-spend by at most 1%. assert!( meter.consumed_ratio() >= Perbill::from_percent(99), - "Consumed too few: {:?}", + "{CALIBRATION_ERROR}\nConsumed too few: {:?}", meter.consumed_ratio() ); }); @@ -250,7 +252,7 @@ fn waste_at_most_proof_size_weight_close_enough() { // We require it to be under-spend by at most 1%. assert!( meter.consumed_ratio() >= Perbill::from_percent(99), - "Consumed too few: {:?}", + "{CALIBRATION_ERROR}\nConsumed too few: {:?}", meter.consumed_ratio() ); }); From 8b243f32d5e8b60d62937ecfdc1ac60fa4ee8ffa Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Sat, 10 Jun 2023 16:33:35 +0200 Subject: [PATCH 4/9] Cleanup Signed-off-by: Oliver Tale-Yazdi --- frame/glutton/src/lib.rs | 20 ++++++------- frame/glutton/src/mock.rs | 13 ++++++++- frame/glutton/src/tests.rs | 60 ++++++++++++++++++++++++++------------ 3 files changed, 64 insertions(+), 29 deletions(-) diff --git a/frame/glutton/src/lib.rs b/frame/glutton/src/lib.rs index 6908a7a6bd343..7684e885e1bb4 100644 --- a/frame/glutton/src/lib.rs +++ b/frame/glutton/src/lib.rs @@ -43,7 +43,7 @@ pub use weights::WeightInfo; /// The size of each value in the `TrashData` storage in bytes. pub const VALUE_SIZE: usize = 1024; -/// Max number of entries for `TrashData` storage item +/// Max number of entries for the `TrashData` map. pub const MAX_TRASH_DATA_ENTRIES: u32 = 65_000; /// Hard limit for any other resource limit (in units). pub const RESOURCE_HARD_LIMIT: FixedU64 = FixedU64::from_u32(10); @@ -88,13 +88,15 @@ pub mod pallet { InsaneLimit, } - /// Storage value used to specify what percentage of the left over `ref_time` - /// to consume during `on_idle`. + /// What ratio of the remaining `ref_time` to consume during `on_idle`. + /// + /// `1.0` is mapped to `100%`. Must be at most [`crate::RESOURCE_HARD_LIMIT`]. #[pallet::storage] pub(crate) type Compute = StorageValue<_, FixedU64, ValueQuery>; - /// Storage value used the specify what percentage of left over `proof_size` - /// to consume during `on_idle`. + /// What ratio of the remaining `proof_size` to consume during `on_idle`. + /// + /// `1.0` is mapped to `100%`. Must be at most [`crate::RESOURCE_HARD_LIMIT`]. #[pallet::storage] pub(crate) type Storage = StorageValue<_, FixedU64, ValueQuery>; @@ -184,7 +186,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = T::WeightInfo)] impl Pallet { /// Initializes the pallet by writing into `TrashData`. /// @@ -227,11 +229,10 @@ pub mod pallet { /// /// Only callable by Root or `AdminOrigin`. #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::set_compute())] pub fn set_compute(origin: OriginFor, compute: FixedU64) -> DispatchResult { T::AdminOrigin::try_origin(origin).map(|_| ()).or_else(|o| ensure_root(o))?; - ensure!(compute <= RESOURCE_HARD_LIMIT, Error::::InsaneLimit); + ensure!(compute <= RESOURCE_HARD_LIMIT, Error::::InsaneLimit); Compute::::set(compute); Self::deposit_event(Event::ComputationLimitSet { compute }); @@ -247,11 +248,10 @@ pub mod pallet { /// /// Only callable by Root or `AdminOrigin`. #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::set_storage())] pub fn set_storage(origin: OriginFor, storage: FixedU64) -> DispatchResult { T::AdminOrigin::try_origin(origin).map(|_| ()).or_else(|o| ensure_root(o))?; - ensure!(storage <= RESOURCE_HARD_LIMIT, Error::::InsaneLimit); + ensure!(storage <= RESOURCE_HARD_LIMIT, Error::::InsaneLimit); Storage::::set(storage); Self::deposit_event(Event::StorageLimitSet { storage }); diff --git a/frame/glutton/src/mock.rs b/frame/glutton/src/mock.rs index 8c331dc97ab2b..f2ce53b206fa8 100644 --- a/frame/glutton/src/mock.rs +++ b/frame/glutton/src/mock.rs @@ -18,7 +18,10 @@ use super::*; use crate as pallet_glutton; -use frame_support::traits::{ConstU32, ConstU64}; +use frame_support::{ + assert_ok, + traits::{ConstU32, ConstU64}, +}; use sp_core::H256; use sp_runtime::{ testing::Header, @@ -79,3 +82,11 @@ pub fn new_test_ext() -> sp_io::TestExternalities { ext.execute_with(|| System::set_block_number(1)); ext } + +/// Set the `compute` and `storage` limits. +/// +/// `1.0` corresponds to `100%`. +pub fn set_limits(compute: f64, storage: f64) { + assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_float(compute))); + assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), FixedU64::from_float(storage))); +} diff --git a/frame/glutton/src/tests.rs b/frame/glutton/src/tests.rs index d70714948d102..8b6779667d85f 100644 --- a/frame/glutton/src/tests.rs +++ b/frame/glutton/src/tests.rs @@ -17,13 +17,13 @@ //! Tests for the glutton pallet. -use super::*; -use mock::{new_test_ext, Glutton, RuntimeOrigin, System, Test}; +use super::{mock::*, *}; use frame_support::{assert_err, assert_noop, assert_ok, weights::constants::*}; use sp_runtime::{traits::One, Perbill}; -const CALIBRATION_ERROR: &'static str = "Weight calibration failed. Please re-run the benchmarks on the same hardware."; +const CALIBRATION_ERROR: &'static str = + "Weight calibration failed. Please re-run the benchmarks on the same hardware."; #[test] fn initialize_pallet_works() { @@ -163,8 +163,7 @@ fn setting_storage_respects_limit() { #[test] fn on_idle_works() { new_test_ext().execute_with(|| { - assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), One::one())); - assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), One::one())); + set_limits(One::one(), One::one()); Glutton::on_idle(1, Weight::from_parts(20_000_000, 0)); }); @@ -174,8 +173,7 @@ fn on_idle_works() { #[test] fn on_idle_weight_high_proof_is_close_enough_works() { new_test_ext().execute_with(|| { - assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), One::one())); - assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), One::one())); + set_limits(One::one(), One::one()); let should = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, WEIGHT_PROOF_SIZE_PER_MB * 5); let got = Glutton::on_idle(1, should); @@ -184,15 +182,13 @@ fn on_idle_weight_high_proof_is_close_enough_works() { let ratio = Perbill::from_rational(got.proof_size(), should.proof_size()); assert!( ratio >= Perbill::from_percent(99), - "{CALIBRATION_ERROR}\nToo few proof size consumed, was only {:?} of expected", - ratio + "Too few proof size consumed, was only {ratio:?} of expected", ); - + let ratio = Perbill::from_rational(got.ref_time(), should.ref_time()); assert!( ratio >= Perbill::from_percent(99), - "{CALIBRATION_ERROR}\nToo few ref time consumed, was only {:?} of expected", - ratio + "Too few ref time consumed, was only {ratio:?} of expected", ); }); } @@ -200,8 +196,7 @@ fn on_idle_weight_high_proof_is_close_enough_works() { #[test] fn on_idle_weight_low_proof_is_close_enough_works() { new_test_ext().execute_with(|| { - assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::one())); - assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), FixedU64::one())); + set_limits(One::one(), One::one()); let should = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, WEIGHT_PROOF_SIZE_PER_KB * 20); let got = Glutton::on_idle(1, should); @@ -211,15 +206,44 @@ fn on_idle_weight_low_proof_is_close_enough_works() { // Just a sanity check here for > 0 assert!( ratio >= Perbill::from_percent(50), - "Too few proof size consumed, was only {:?} of expected", - ratio + "Too few proof size consumed, was only {ratio:?} of expected", ); let ratio = Perbill::from_rational(got.ref_time(), should.ref_time()); assert!( ratio >= Perbill::from_percent(99), - "{CALIBRATION_ERROR}\nToo few ref time consumed, was only {:?} of expected", - ratio + "Too few ref time consumed, was only {ratio:?} of expected", + ); + }); +} + +#[test] +fn on_idle_weight_over_unity_is_close_enough_works() { + new_test_ext().execute_with(|| { + // Para blocks get ~500ms compute and ~5MB proof size. + let max_block = + Weight::from_parts(500 * WEIGHT_REF_TIME_PER_MILLIS, 5 * WEIGHT_PROOF_SIZE_PER_MB); + // But now we tell it to consume more than that. + set_limits(1.75, 1.5); + let want = Weight::from_parts( + (1.75 * max_block.ref_time() as f64) as u64, + (1.5 * max_block.proof_size() as f64) as u64, + ); + + let consumed = Glutton::on_idle(1, max_block); + assert!(consumed.all_gt(max_block), "Must consume more than the block limit"); + assert!(consumed.all_lte(want), "Consumed more than the requested weight"); + + let ratio = Perbill::from_rational(consumed.proof_size(), want.proof_size()); + assert!( + ratio >= Perbill::from_percent(99), + "Too few proof size consumed, was only {ratio:?} of expected", + ); + + let ratio = Perbill::from_rational(consumed.ref_time(), want.ref_time()); + assert!( + ratio >= Perbill::from_percent(99), + "Too few ref time consumed, was only {ratio:?} of expected", ); }); } From aa10a0ccca44a723b628e0ebc1c68e3a08b13b08 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Sat, 10 Jun 2023 16:38:47 +0200 Subject: [PATCH 5/9] Highlight warning Signed-off-by: Oliver Tale-Yazdi --- frame/glutton/README.md | 2 +- frame/glutton/src/lib.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/frame/glutton/README.md b/frame/glutton/README.md index bcd6c51a6fced..8ad4f79171820 100644 --- a/frame/glutton/README.md +++ b/frame/glutton/README.md @@ -1,6 +1,6 @@ # WARNING -Do not use on value-bearing chains. This pallet is **only** intended for usage on test-chains. +**DO NOT USE ON VALUE-BEARING CHAINS. THIS PALLET IS ONLY INTENDED FOR TESTING USAGE.** # Glutton Pallet diff --git a/frame/glutton/src/lib.rs b/frame/glutton/src/lib.rs index 7684e885e1bb4..7dc62c306c0ac 100644 --- a/frame/glutton/src/lib.rs +++ b/frame/glutton/src/lib.rs @@ -15,6 +15,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +//! # WARNING +//! +//! **DO NOT USE ON VALUE-BEARING CHAINS. THIS PALLET IS ONLY INTENDED FOR TESTING USAGE.** +//! //! # Glutton Pallet //! //! Pallet that consumes `ref_time` and `proof_size` of a block. Based on the From 56ca72dabe9200c1f88d9ed0478eb617e2e28be8 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Sat, 10 Jun 2023 18:42:11 +0200 Subject: [PATCH 6/9] Fix docs --- frame/glutton/src/lib.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/frame/glutton/src/lib.rs b/frame/glutton/src/lib.rs index 7dc62c306c0ac..c02a14810d0b2 100644 --- a/frame/glutton/src/lib.rs +++ b/frame/glutton/src/lib.rs @@ -88,19 +88,22 @@ pub mod pallet { /// /// Set `witness_count` to `Some` to bypass this error. AlreadyInitialized, + /// The limit was over [`crate::RESOURCE_HARD_LIMIT`]. InsaneLimit, } - /// What ratio of the remaining `ref_time` to consume during `on_idle`. + /// The proportion of the remaining `ref_time` to consume during `on_idle`. /// - /// `1.0` is mapped to `100%`. Must be at most [`crate::RESOURCE_HARD_LIMIT`]. + /// `1.0` is mapped to `100%`. Must be at most [`crate::RESOURCE_HARD_LIMIT`]. Setting this to + /// over `1.0` could stall the chain. #[pallet::storage] pub(crate) type Compute = StorageValue<_, FixedU64, ValueQuery>; - /// What ratio of the remaining `proof_size` to consume during `on_idle`. + /// The proportion of the remaining `proof_size` to consume during `on_idle`. /// - /// `1.0` is mapped to `100%`. Must be at most [`crate::RESOURCE_HARD_LIMIT`]. + /// `1.0` is mapped to `100%`. Must be at most [`crate::RESOURCE_HARD_LIMIT`]. Setting this to + /// over `1.0` could stall the chain. #[pallet::storage] pub(crate) type Storage = StorageValue<_, FixedU64, ValueQuery>; @@ -192,13 +195,12 @@ pub mod pallet { #[pallet::call(weight = T::WeightInfo)] impl Pallet { - /// Initializes the pallet by writing into `TrashData`. + /// Initialize the pallet. Should be called once, if no genesis state was provided. /// /// `current_count` is the current number of elements in `TrashData`. This can be set to /// `None` when the pallet is first initialized. /// - /// Only callable by Root or `AdminOrigin`. A good default for `new_count` is - /// `5_000`. + /// Only callable by Root or `AdminOrigin`. A good default for `new_count` is `5_000`. #[pallet::call_index(0)] #[pallet::weight( T::WeightInfo::initialize_pallet_grow(witness_count.unwrap_or_default()) @@ -245,10 +247,9 @@ pub mod pallet { /// Set how much of the remaining `proof_size` weight should be consumed by `on_idle`. // - /// 100% means that all remaining `proof_size` will be consumed. The PoV benchmarking + /// `1.0` means that all remaining `proof_size` will be consumed. The PoV benchmarking /// results that are used here are likely an over-estimation. 100% intended consumption will - /// therefore translate to less than 100% actual consumption. In the future, this could be - /// counter-acted by allowing the glutton to specify over-unity consumption ratios. + /// therefore translate to less than 100% actual consumption. /// /// Only callable by Root or `AdminOrigin`. #[pallet::call_index(2)] From 4b23ede6f543f1ea45faa988814c8a8a6f932535 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Sun, 11 Jun 2023 12:57:35 +0200 Subject: [PATCH 7/9] Review test fixes Co-authored-by: Guillaume Yu Thiolliere --- frame/glutton/src/tests.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/glutton/src/tests.rs b/frame/glutton/src/tests.rs index 8b6779667d85f..1897ff63a70fb 100644 --- a/frame/glutton/src/tests.rs +++ b/frame/glutton/src/tests.rs @@ -98,11 +98,11 @@ fn setting_compute_works() { ); assert_noop!( - Glutton::set_compute(RuntimeOrigin::signed(1), FixedU64::from_float(0.3)), + Glutton::set_compute(RuntimeOrigin::signed(1), FixedU64::from_float(0.5)), DispatchError::BadOrigin ); assert_noop!( - Glutton::set_compute(RuntimeOrigin::none(), FixedU64::from_float(0.3)), + Glutton::set_compute(RuntimeOrigin::none(), FixedU64::from_float(0.5)), DispatchError::BadOrigin ); }); @@ -135,11 +135,11 @@ fn setting_storage_works() { ); assert_noop!( - Glutton::set_storage(RuntimeOrigin::signed(1), FixedU64::from_float(0.3)), + Glutton::set_storage(RuntimeOrigin::signed(1), FixedU64::from_float(0.5)), DispatchError::BadOrigin ); assert_noop!( - Glutton::set_storage(RuntimeOrigin::none(), FixedU64::from_float(0.3)), + Glutton::set_storage(RuntimeOrigin::none(), FixedU64::from_float(0.5)), DispatchError::BadOrigin ); }); From 5cf2bad13090f7582bbff042e2b7c7a78549c41c Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 13 Jun 2023 13:25:16 +0000 Subject: [PATCH 8/9] ".git/.scripts/commands/bench/bench.sh" pallet dev pallet-glutton --- frame/glutton/src/weights.rs | 180 ++++++++++++++++++----------------- 1 file changed, 91 insertions(+), 89 deletions(-) diff --git a/frame/glutton/src/weights.rs b/frame/glutton/src/weights.rs index 82bac91c6d785..f858681dedb16 100644 --- a/frame/glutton/src/weights.rs +++ b/frame/glutton/src/weights.rs @@ -18,33 +18,35 @@ //! Autogenerated weights for pallet_glutton //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-04-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-06-13, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `bm2`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: -// ./target/production/substrate +// target/production/substrate // benchmark // pallet -// --chain=dev // --steps=50 // --repeat=20 -// --pallet=pallet_glutton // --extrinsic=* // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --output=./frame/glutton/src/weights.rs +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/substrate/.git/.artifacts/bench.json +// --pallet=pallet-glutton +// --chain=dev // --header=./HEADER-APACHE2 +// --output=./frame/glutton/src/weights.rs // --template=./.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] +#![allow(missing_docs)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use sp_std::marker::PhantomData; +use core::marker::PhantomData; /// Weight functions needed for pallet_glutton. pub trait WeightInfo { @@ -69,12 +71,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `n` is `[0, 1000]`. fn initialize_pallet_grow(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `4` + // Measured: `86` // Estimated: `1489` - // Minimum execution time: 10_410_000 picoseconds. - Weight::from_parts(10_515_000, 1489) - // Standard Error: 1_069 - .saturating_add(Weight::from_parts(1_513_013, 0).saturating_mul(n.into())) + // Minimum execution time: 11_433_000 picoseconds. + Weight::from_parts(24_871_470, 1489) + // Standard Error: 18_763 + .saturating_add(Weight::from_parts(9_090_388, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) @@ -86,12 +88,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `n` is `[0, 1000]`. fn initialize_pallet_shrink(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `65` + // Measured: `119` // Estimated: `1489` - // Minimum execution time: 11_105_000 picoseconds. - Weight::from_parts(584_850, 1489) - // Standard Error: 1_417 - .saturating_add(Weight::from_parts(1_054_988, 0).saturating_mul(n.into())) + // Minimum execution time: 11_248_000 picoseconds. + Weight::from_parts(11_507_000, 1489) + // Standard Error: 1_070 + .saturating_add(Weight::from_parts(1_054_130, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) @@ -101,83 +103,83 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 709_000 picoseconds. - Weight::from_parts(7_409_096, 0) - // Standard Error: 23 - .saturating_add(Weight::from_parts(95_342, 0).saturating_mul(i.into())) + // Minimum execution time: 775_000 picoseconds. + Weight::from_parts(791_000, 0) + // Standard Error: 17 + .saturating_add(Weight::from_parts(86_451, 0).saturating_mul(i.into())) } /// Storage: Glutton TrashData (r:5000 w:0) /// Proof: Glutton TrashData (max_values: Some(65000), max_size: Some(1036), added: 3016, mode: MaxEncodedLen) /// The range of component `i` is `[0, 5000]`. fn waste_proof_size_some(i: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `119036 + i * (1022 ±0)` + // Measured: `119114 + i * (1022 ±0)` // Estimated: `990 + i * (3016 ±0)` - // Minimum execution time: 584_000 picoseconds. - Weight::from_parts(674_000, 990) - // Standard Error: 1_802 - .saturating_add(Weight::from_parts(5_360_522, 0).saturating_mul(i.into())) + // Minimum execution time: 581_000 picoseconds. + Weight::from_parts(637_000, 990) + // Standard Error: 2_336 + .saturating_add(Weight::from_parts(5_424_580, 0).saturating_mul(i.into())) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(i.into()))) .saturating_add(Weight::from_parts(0, 3016).saturating_mul(i.into())) } /// Storage: Glutton Storage (r:1 w:0) - /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Glutton Compute (r:1 w:0) - /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Glutton TrashData (r:1737 w:0) /// Proof: Glutton TrashData (max_values: Some(65000), max_size: Some(1036), added: 3016, mode: MaxEncodedLen) fn on_idle_high_proof_waste() -> Weight { // Proof Size summary in bytes: - // Measured: `1900466` + // Measured: `1900497` // Estimated: `5239782` - // Minimum execution time: 57_124_610_000 picoseconds. - Weight::from_parts(57_256_059_000, 5239782) + // Minimum execution time: 51_818_267_000 picoseconds. + Weight::from_parts(52_075_493_000, 5239782) .saturating_add(T::DbWeight::get().reads(1739_u64)) } /// Storage: Glutton Storage (r:1 w:0) - /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Glutton Compute (r:1 w:0) - /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Glutton TrashData (r:5 w:0) /// Proof: Glutton TrashData (max_values: Some(65000), max_size: Some(1036), added: 3016, mode: MaxEncodedLen) fn on_idle_low_proof_waste() -> Weight { // Proof Size summary in bytes: - // Measured: `9516` + // Measured: `9547` // Estimated: `16070` - // Minimum execution time: 101_500_066_000 picoseconds. - Weight::from_parts(101_621_640_000, 16070) + // Minimum execution time: 90_225_582_000 picoseconds. + Weight::from_parts(90_549_840_000, 16070) .saturating_add(T::DbWeight::get().reads(7_u64)) } /// Storage: Glutton Storage (r:1 w:0) - /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Glutton Compute (r:1 w:0) - /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) fn empty_on_idle() -> Weight { // Proof Size summary in bytes: - // Measured: `4` - // Estimated: `1489` - // Minimum execution time: 4_164_000 picoseconds. - Weight::from_parts(4_378_000, 1489) + // Measured: `86` + // Estimated: `1493` + // Minimum execution time: 6_091_000 picoseconds. + Weight::from_parts(6_268_000, 1493) .saturating_add(T::DbWeight::get().reads(2_u64)) } /// Storage: Glutton Compute (r:0 w:1) - /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) fn set_compute() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_795_000 picoseconds. - Weight::from_parts(9_076_000, 0) + // Minimum execution time: 8_748_000 picoseconds. + Weight::from_parts(8_896_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: Glutton Storage (r:0 w:1) - /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) fn set_storage() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_979_000 picoseconds. - Weight::from_parts(9_195_000, 0) + // Minimum execution time: 8_836_000 picoseconds. + Weight::from_parts(9_067_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } } @@ -191,12 +193,12 @@ impl WeightInfo for () { /// The range of component `n` is `[0, 1000]`. fn initialize_pallet_grow(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `4` + // Measured: `86` // Estimated: `1489` - // Minimum execution time: 10_410_000 picoseconds. - Weight::from_parts(10_515_000, 1489) - // Standard Error: 1_069 - .saturating_add(Weight::from_parts(1_513_013, 0).saturating_mul(n.into())) + // Minimum execution time: 11_433_000 picoseconds. + Weight::from_parts(24_871_470, 1489) + // Standard Error: 18_763 + .saturating_add(Weight::from_parts(9_090_388, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(n.into()))) @@ -208,12 +210,12 @@ impl WeightInfo for () { /// The range of component `n` is `[0, 1000]`. fn initialize_pallet_shrink(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `65` + // Measured: `119` // Estimated: `1489` - // Minimum execution time: 11_105_000 picoseconds. - Weight::from_parts(584_850, 1489) - // Standard Error: 1_417 - .saturating_add(Weight::from_parts(1_054_988, 0).saturating_mul(n.into())) + // Minimum execution time: 11_248_000 picoseconds. + Weight::from_parts(11_507_000, 1489) + // Standard Error: 1_070 + .saturating_add(Weight::from_parts(1_054_130, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(n.into()))) @@ -223,83 +225,83 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 709_000 picoseconds. - Weight::from_parts(7_409_096, 0) - // Standard Error: 23 - .saturating_add(Weight::from_parts(95_342, 0).saturating_mul(i.into())) + // Minimum execution time: 775_000 picoseconds. + Weight::from_parts(791_000, 0) + // Standard Error: 17 + .saturating_add(Weight::from_parts(86_451, 0).saturating_mul(i.into())) } /// Storage: Glutton TrashData (r:5000 w:0) /// Proof: Glutton TrashData (max_values: Some(65000), max_size: Some(1036), added: 3016, mode: MaxEncodedLen) /// The range of component `i` is `[0, 5000]`. fn waste_proof_size_some(i: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `119036 + i * (1022 ±0)` + // Measured: `119114 + i * (1022 ±0)` // Estimated: `990 + i * (3016 ±0)` - // Minimum execution time: 584_000 picoseconds. - Weight::from_parts(674_000, 990) - // Standard Error: 1_802 - .saturating_add(Weight::from_parts(5_360_522, 0).saturating_mul(i.into())) + // Minimum execution time: 581_000 picoseconds. + Weight::from_parts(637_000, 990) + // Standard Error: 2_336 + .saturating_add(Weight::from_parts(5_424_580, 0).saturating_mul(i.into())) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(i.into()))) .saturating_add(Weight::from_parts(0, 3016).saturating_mul(i.into())) } /// Storage: Glutton Storage (r:1 w:0) - /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Glutton Compute (r:1 w:0) - /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Glutton TrashData (r:1737 w:0) /// Proof: Glutton TrashData (max_values: Some(65000), max_size: Some(1036), added: 3016, mode: MaxEncodedLen) fn on_idle_high_proof_waste() -> Weight { // Proof Size summary in bytes: - // Measured: `1900466` + // Measured: `1900497` // Estimated: `5239782` - // Minimum execution time: 57_124_610_000 picoseconds. - Weight::from_parts(57_256_059_000, 5239782) + // Minimum execution time: 51_818_267_000 picoseconds. + Weight::from_parts(52_075_493_000, 5239782) .saturating_add(RocksDbWeight::get().reads(1739_u64)) } /// Storage: Glutton Storage (r:1 w:0) - /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Glutton Compute (r:1 w:0) - /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Glutton TrashData (r:5 w:0) /// Proof: Glutton TrashData (max_values: Some(65000), max_size: Some(1036), added: 3016, mode: MaxEncodedLen) fn on_idle_low_proof_waste() -> Weight { // Proof Size summary in bytes: - // Measured: `9516` + // Measured: `9547` // Estimated: `16070` - // Minimum execution time: 101_500_066_000 picoseconds. - Weight::from_parts(101_621_640_000, 16070) + // Minimum execution time: 90_225_582_000 picoseconds. + Weight::from_parts(90_549_840_000, 16070) .saturating_add(RocksDbWeight::get().reads(7_u64)) } /// Storage: Glutton Storage (r:1 w:0) - /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Glutton Compute (r:1 w:0) - /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) fn empty_on_idle() -> Weight { // Proof Size summary in bytes: - // Measured: `4` - // Estimated: `1489` - // Minimum execution time: 4_164_000 picoseconds. - Weight::from_parts(4_378_000, 1489) + // Measured: `86` + // Estimated: `1493` + // Minimum execution time: 6_091_000 picoseconds. + Weight::from_parts(6_268_000, 1493) .saturating_add(RocksDbWeight::get().reads(2_u64)) } /// Storage: Glutton Compute (r:0 w:1) - /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Compute (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) fn set_compute() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_795_000 picoseconds. - Weight::from_parts(9_076_000, 0) + // Minimum execution time: 8_748_000 picoseconds. + Weight::from_parts(8_896_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: Glutton Storage (r:0 w:1) - /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Proof: Glutton Storage (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) fn set_storage() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_979_000 picoseconds. - Weight::from_parts(9_195_000, 0) + // Minimum execution time: 8_836_000 picoseconds. + Weight::from_parts(9_067_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } } From 987cf125312776c03881ac0a7e5c63987eae8111 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 13 Jun 2023 13:56:46 +0000 Subject: [PATCH 9/9] ".git/.scripts/commands/bench/bench.sh" pallet dev pallet-glutton --- frame/glutton/src/weights.rs | 104 +++++++++++++++++------------------ 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/frame/glutton/src/weights.rs b/frame/glutton/src/weights.rs index f858681dedb16..8d66dfe8fccff 100644 --- a/frame/glutton/src/weights.rs +++ b/frame/glutton/src/weights.rs @@ -73,10 +73,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `86` // Estimated: `1489` - // Minimum execution time: 11_433_000 picoseconds. - Weight::from_parts(24_871_470, 1489) - // Standard Error: 18_763 - .saturating_add(Weight::from_parts(9_090_388, 0).saturating_mul(n.into())) + // Minimum execution time: 11_620_000 picoseconds. + Weight::from_parts(18_662_404, 1489) + // Standard Error: 8_342 + .saturating_add(Weight::from_parts(8_453_895, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) @@ -90,10 +90,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `119` // Estimated: `1489` - // Minimum execution time: 11_248_000 picoseconds. - Weight::from_parts(11_507_000, 1489) - // Standard Error: 1_070 - .saturating_add(Weight::from_parts(1_054_130, 0).saturating_mul(n.into())) + // Minimum execution time: 11_128_000 picoseconds. + Weight::from_parts(11_404_000, 1489) + // Standard Error: 1_098 + .saturating_add(Weight::from_parts(1_007_030, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) @@ -103,10 +103,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 775_000 picoseconds. - Weight::from_parts(791_000, 0) - // Standard Error: 17 - .saturating_add(Weight::from_parts(86_451, 0).saturating_mul(i.into())) + // Minimum execution time: 598_000 picoseconds. + Weight::from_parts(607_000, 0) + // Standard Error: 18 + .saturating_add(Weight::from_parts(85_323, 0).saturating_mul(i.into())) } /// Storage: Glutton TrashData (r:5000 w:0) /// Proof: Glutton TrashData (max_values: Some(65000), max_size: Some(1036), added: 3016, mode: MaxEncodedLen) @@ -115,10 +115,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `119114 + i * (1022 ±0)` // Estimated: `990 + i * (3016 ±0)` - // Minimum execution time: 581_000 picoseconds. - Weight::from_parts(637_000, 990) - // Standard Error: 2_336 - .saturating_add(Weight::from_parts(5_424_580, 0).saturating_mul(i.into())) + // Minimum execution time: 503_000 picoseconds. + Weight::from_parts(589_000, 990) + // Standard Error: 2_971 + .saturating_add(Weight::from_parts(5_347_659, 0).saturating_mul(i.into())) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(i.into()))) .saturating_add(Weight::from_parts(0, 3016).saturating_mul(i.into())) } @@ -132,8 +132,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1900497` // Estimated: `5239782` - // Minimum execution time: 51_818_267_000 picoseconds. - Weight::from_parts(52_075_493_000, 5239782) + // Minimum execution time: 55_496_326_000 picoseconds. + Weight::from_parts(55_707_517_000, 5239782) .saturating_add(T::DbWeight::get().reads(1739_u64)) } /// Storage: Glutton Storage (r:1 w:0) @@ -146,8 +146,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `9547` // Estimated: `16070` - // Minimum execution time: 90_225_582_000 picoseconds. - Weight::from_parts(90_549_840_000, 16070) + // Minimum execution time: 98_314_570_000 picoseconds. + Weight::from_parts(98_702_199_000, 16070) .saturating_add(T::DbWeight::get().reads(7_u64)) } /// Storage: Glutton Storage (r:1 w:0) @@ -158,8 +158,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `86` // Estimated: `1493` - // Minimum execution time: 6_091_000 picoseconds. - Weight::from_parts(6_268_000, 1493) + // Minimum execution time: 5_853_000 picoseconds. + Weight::from_parts(6_055_000, 1493) .saturating_add(T::DbWeight::get().reads(2_u64)) } /// Storage: Glutton Compute (r:0 w:1) @@ -168,8 +168,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_748_000 picoseconds. - Weight::from_parts(8_896_000, 0) + // Minimum execution time: 8_741_000 picoseconds. + Weight::from_parts(8_962_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: Glutton Storage (r:0 w:1) @@ -178,8 +178,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_836_000 picoseconds. - Weight::from_parts(9_067_000, 0) + // Minimum execution time: 8_585_000 picoseconds. + Weight::from_parts(8_789_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } } @@ -195,10 +195,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `86` // Estimated: `1489` - // Minimum execution time: 11_433_000 picoseconds. - Weight::from_parts(24_871_470, 1489) - // Standard Error: 18_763 - .saturating_add(Weight::from_parts(9_090_388, 0).saturating_mul(n.into())) + // Minimum execution time: 11_620_000 picoseconds. + Weight::from_parts(18_662_404, 1489) + // Standard Error: 8_342 + .saturating_add(Weight::from_parts(8_453_895, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(n.into()))) @@ -212,10 +212,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `119` // Estimated: `1489` - // Minimum execution time: 11_248_000 picoseconds. - Weight::from_parts(11_507_000, 1489) - // Standard Error: 1_070 - .saturating_add(Weight::from_parts(1_054_130, 0).saturating_mul(n.into())) + // Minimum execution time: 11_128_000 picoseconds. + Weight::from_parts(11_404_000, 1489) + // Standard Error: 1_098 + .saturating_add(Weight::from_parts(1_007_030, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(n.into()))) @@ -225,10 +225,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 775_000 picoseconds. - Weight::from_parts(791_000, 0) - // Standard Error: 17 - .saturating_add(Weight::from_parts(86_451, 0).saturating_mul(i.into())) + // Minimum execution time: 598_000 picoseconds. + Weight::from_parts(607_000, 0) + // Standard Error: 18 + .saturating_add(Weight::from_parts(85_323, 0).saturating_mul(i.into())) } /// Storage: Glutton TrashData (r:5000 w:0) /// Proof: Glutton TrashData (max_values: Some(65000), max_size: Some(1036), added: 3016, mode: MaxEncodedLen) @@ -237,10 +237,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `119114 + i * (1022 ±0)` // Estimated: `990 + i * (3016 ±0)` - // Minimum execution time: 581_000 picoseconds. - Weight::from_parts(637_000, 990) - // Standard Error: 2_336 - .saturating_add(Weight::from_parts(5_424_580, 0).saturating_mul(i.into())) + // Minimum execution time: 503_000 picoseconds. + Weight::from_parts(589_000, 990) + // Standard Error: 2_971 + .saturating_add(Weight::from_parts(5_347_659, 0).saturating_mul(i.into())) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(i.into()))) .saturating_add(Weight::from_parts(0, 3016).saturating_mul(i.into())) } @@ -254,8 +254,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1900497` // Estimated: `5239782` - // Minimum execution time: 51_818_267_000 picoseconds. - Weight::from_parts(52_075_493_000, 5239782) + // Minimum execution time: 55_496_326_000 picoseconds. + Weight::from_parts(55_707_517_000, 5239782) .saturating_add(RocksDbWeight::get().reads(1739_u64)) } /// Storage: Glutton Storage (r:1 w:0) @@ -268,8 +268,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `9547` // Estimated: `16070` - // Minimum execution time: 90_225_582_000 picoseconds. - Weight::from_parts(90_549_840_000, 16070) + // Minimum execution time: 98_314_570_000 picoseconds. + Weight::from_parts(98_702_199_000, 16070) .saturating_add(RocksDbWeight::get().reads(7_u64)) } /// Storage: Glutton Storage (r:1 w:0) @@ -280,8 +280,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `86` // Estimated: `1493` - // Minimum execution time: 6_091_000 picoseconds. - Weight::from_parts(6_268_000, 1493) + // Minimum execution time: 5_853_000 picoseconds. + Weight::from_parts(6_055_000, 1493) .saturating_add(RocksDbWeight::get().reads(2_u64)) } /// Storage: Glutton Compute (r:0 w:1) @@ -290,8 +290,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_748_000 picoseconds. - Weight::from_parts(8_896_000, 0) + // Minimum execution time: 8_741_000 picoseconds. + Weight::from_parts(8_962_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: Glutton Storage (r:0 w:1) @@ -300,8 +300,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_836_000 picoseconds. - Weight::from_parts(9_067_000, 0) + // Minimum execution time: 8_585_000 picoseconds. + Weight::from_parts(8_789_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } }