Skip to content
Snippets Groups Projects

Fix #235 allow remark in prod with a limit on extrinsic size for free transaction

Merged Fix #235 allow remark in prod with a limit on extrinsic size for free transaction
Merged Benjamin Gallois requested to merge fix-235 into master
1 file
+ 6
3
Compare changes
  • Side-by-side
  • Inline
@@ -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)
}
}
Loading