Skip to content
Snippets Groups Projects
Unverified Commit a89130eb authored by bgallois's avatar bgallois
Browse files

add extrinsic length limit

parent 8779d52b
No related branches found
No related tags found
No related merge requests found
Pipeline #38005 failed
...@@ -61,8 +61,8 @@ where ...@@ -61,8 +61,8 @@ where
/// Function to convert weight to fee when "constant-fees" feature is not enabled. /// 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. /// 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, /// If the current block weight and length are less than a fraction of the max block weight and length, the fee multiplier is one,
/// it returns a zero fee. Otherwise, it calculates the fee based on the length in bytes. /// 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"))] #[cfg(not(feature = "constant-fees"))]
fn weight_to_fee(length_in_bytes: &Weight) -> Self::Balance { fn weight_to_fee(length_in_bytes: &Weight) -> Self::Balance {
let weights = Runtime::BlockWeights::get(); let weights = Runtime::BlockWeights::get();
...@@ -76,16 +76,19 @@ where ...@@ -76,16 +76,19 @@ where
let length = Runtime::BlockLength::get(); let length = Runtime::BlockLength::get();
let normal_max_length = *length.max.get(DispatchClass::Normal) as u64; let normal_max_length = *length.max.get(DispatchClass::Normal) as u64;
let current_block_length = <frame_system::Pallet<Runtime>>::all_extrinsics_len() 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 if current_block_weight
.get(DispatchClass::Normal) .get(DispatchClass::Normal)
.all_lt(Target::get() * normal_max_weight) .all_lt(Target::get() * normal_max_weight)
&& current_block_length < (Target::get() * normal_max_length) && current_block_length < (Target::get() * normal_max_length)
&& fee_multiplier.is_one() && fee_multiplier.is_one()
&& length_in_bytes.ref_time() < max_extrinsic_length
{ {
0u32.into() 0u32.into()
} else { } else {
Self::Balance::saturated_from(length_in_bytes.ref_time() / 100u64) Self::Balance::saturated_from(length_in_bytes.ref_time() / 10u64)
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment