From 1f400a4e1d02afa5bf9da6e2ee37e0b3915ceca9 Mon Sep 17 00:00:00 2001 From: Igor Papandinas <26460174+ipapandinas@users.noreply.github.com> Date: Wed, 4 Dec 2024 18:28:31 +0100 Subject: [PATCH] RuntimeAdjustedWeights type to handle weights override --- runtime/shibuya/src/lib.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index 22aa68f38..3adc25697 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -230,6 +230,19 @@ impl_opaque_keys! { } } +// Adjusting the base extrinsic weight to account for the additional database +// read introduced by the `tx-pause` pallet during extrinsic filtering. +// +// TODO: This hardcoded addition is a temporary fix. Replace it with a proper +// benchmark in the future. +pub struct RuntimeAdjustedWeights; +impl RuntimeAdjustedWeights { + pub fn extrinsic_base_weight() -> Weight { + ExtrinsicBaseWeight::get() + .saturating_add(::DbWeight::get().reads(1)) + } +} + /// We assume that ~10% of the block weight is consumed by `on_initalize` handlers. /// This is used to limit the maximal weight of a single extrinsic. const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10); @@ -249,12 +262,7 @@ parameter_types! { pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder() .base_block(BlockExecutionWeight::get()) .for_class(DispatchClass::all(), |weights| { - // Adjusting the base extrinsic weight to account for the additional database - // read introduced by the `tx-pause` pallet during extrinsic filtering. - // - // TODO: This hardcoded addition is a temporary fix. Replace it with a proper - // benchmark in the future. - weights.base_extrinsic = ExtrinsicBaseWeight::get().saturating_add(::DbWeight::get().reads(1)); + weights.base_extrinsic = RuntimeAdjustedWeights::extrinsic_base_weight(); }) .for_class(DispatchClass::Normal, |weights| { weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT); @@ -807,7 +815,7 @@ impl WeightToFeePolynomial for WeightToFee { type Balance = Balance; fn polynomial() -> WeightToFeeCoefficients { let p = WeightFeeFactor::get(); - let q = Balance::from(ExtrinsicBaseWeight::get().ref_time()); + let q = Balance::from(RuntimeAdjustedWeights::extrinsic_base_weight().ref_time()); smallvec::smallvec![WeightToFeeCoefficient { degree: 1, negative: false,