Skip to content

Commit

Permalink
RuntimeAdjustedWeights type to handle weights override
Browse files Browse the repository at this point in the history
  • Loading branch information
ipapandinas committed Dec 4, 2024
1 parent 6218b74 commit 1f400a4
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Runtime as frame_system::Config>::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);
Expand All @@ -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(<Runtime as frame_system::Config>::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);
Expand Down Expand Up @@ -807,7 +815,7 @@ impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
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,
Expand Down

0 comments on commit 1f400a4

Please sign in to comment.