From a89130eb289fbb1b5972890b4ed07e357e7dd17f Mon Sep 17 00:00:00 2001 From: bgallois <benjamin@gallois.cc> Date: Mon, 23 Sep 2024 16:26:04 +0200 Subject: [PATCH] add extrinsic length limit --- runtime/common/src/fees.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/runtime/common/src/fees.rs b/runtime/common/src/fees.rs index 9d7a166bb..aa4f24fe3 100644 --- a/runtime/common/src/fees.rs +++ b/runtime/common/src/fees.rs @@ -61,8 +61,8 @@ where /// Function to convert weight to fee when "constant-fees" feature is not enabled. /// /// This function calculates the fee based on the length of the transaction in bytes. - /// If the current block weight and length are less than a fraction of the max block weight and length and the fee multiplier is one, - /// it returns a zero fee. Otherwise, it calculates the fee based on the length in bytes. + /// If the current block weight and length are less than a fraction of the max block weight and length, the fee multiplier is one, + /// and the extrinsic length is less than 256 bytes, no fees are applied. Otherwise, it calculates the fee based on the length in bytes. #[cfg(not(feature = "constant-fees"))] fn weight_to_fee(length_in_bytes: &Weight) -> Self::Balance { let weights = Runtime::BlockWeights::get(); @@ -76,16 +76,19 @@ where let length = Runtime::BlockLength::get(); let normal_max_length = *length.max.get(DispatchClass::Normal) as u64; let current_block_length = <frame_system::Pallet<Runtime>>::all_extrinsics_len() as u64; + // One remark extrinsic overhead is approximately 110 bytes + let max_extrinsic_length = 256; if current_block_weight .get(DispatchClass::Normal) .all_lt(Target::get() * normal_max_weight) && current_block_length < (Target::get() * normal_max_length) && fee_multiplier.is_one() + && length_in_bytes.ref_time() < max_extrinsic_length { 0u32.into() } else { - Self::Balance::saturated_from(length_in_bytes.ref_time() / 100u64) + Self::Balance::saturated_from(length_in_bytes.ref_time() / 10u64) } } -- GitLab