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

fix FeeMultiplier minimum

parent f8e51fa3
Branches
No related tags found
1 merge request!268Fix #232
Pipeline #37182 failed
......@@ -25,7 +25,7 @@ use pallet_transaction_payment::{Multiplier, MultiplierUpdate};
use sp_arithmetic::traits::{BaseArithmetic, Unsigned};
use sp_core::Get;
use sp_runtime::{
traits::{Convert, Zero},
traits::{Convert, One},
Perquintill,
};
#[cfg(not(feature = "constant-fees"))]
......@@ -78,7 +78,7 @@ where
if current_block_weight
.get(DispatchClass::Normal)
.all_lt(X::get() * normal_max_weight)
&& fee_multiplier.is_zero()
&& fee_multiplier.is_one()
{
0u32.into()
} else {
......@@ -133,7 +133,7 @@ where
if current_block_weight
.get(DispatchClass::Normal)
.all_lt(X::get() * normal_max_weight)
&& fee_multiplier.is_zero()
&& fee_multiplier.is_one()
{
smallvec![WeightToFeeCoefficient {
degree: 1,
......@@ -189,7 +189,7 @@ where
X: Get<Multiplier>,
{
fn min() -> Multiplier {
0.into()
1.into()
}
fn max() -> Multiplier {
......@@ -215,7 +215,7 @@ where
/// Function to convert the previous fee multiplier to a new fee multiplier.
///
/// This function adjusts the fee multiplier based on the current block weight and target block fullness.
/// - If the current block weight is less than the target, it decreases the multiplier by one, with a minimum of zero.
/// - If the current block weight is less than the target, it decreases the multiplier by one, with a minimum of one.
/// - If the current block weight is more than the target, it increases the multiplier by one, up to the maximum multiplier.
#[cfg(not(feature = "constant-fees"))]
fn convert(previous: Multiplier) -> Multiplier {
......@@ -235,7 +235,7 @@ where
// If the current block weight is less than the target, keep the
// multiplier at the minimum or decrease it by one to slowly
// return to the minimum.
previous.saturating_sub(1.into()).max(0.into())
previous.saturating_sub(1.into()).max(1.into())
} else {
// If the current block weight is more than the target, increase
// the multiplier by one.
......
......@@ -33,7 +33,6 @@ fn test_fees_empty() {
])
.build()
.execute_with(|| {
run_to_block(2);
let call = RuntimeCall::Balances(BalancesCall::transfer_allow_death {
dest: AccountKeyring::Eve.to_account_id().into(),
value: 500,
......@@ -62,7 +61,6 @@ fn test_fees_full() {
])
.build()
.execute_with(|| {
run_to_block(2);
let mut transactions = 0u64;
let weights = BlockWeights::get();
let normal_max_weight = weights
......@@ -132,15 +130,14 @@ fn test_fees_multiplier() {
.max_total
.unwrap_or(weights.max_block);
run_to_block(2);
assert_eq!(
pallet_transaction_payment::Pallet::<Runtime>::next_fee_multiplier(),
0.into()
1.into()
);
// If the block weight is over the target and the previous block was also over the target,
// the fee multiplier is increased by one, up to the MaxMultiplier.
let mut current = 0u128;
for i in 3..20u128 {
for i in 1..20u128 {
System::set_block_consumed_resources(Target::get() * normal_max_weight, 100_usize);
run_to_block(i as u32);
current += 1;
......@@ -151,11 +148,11 @@ fn test_fees_multiplier() {
}
// If the block weight is under the target and the previous block was also under the target,
// the fee multiplier is decreased by one, down to the 0.
// the fee multiplier is decreased by one, down to the one.
let mut current = 10u128;
for i in 20..50u32 {
run_to_block(i);
current = current.saturating_sub(1);
current = current.saturating_sub(1).max(1u128.into());
assert_eq!(
pallet_transaction_payment::Pallet::<Runtime>::next_fee_multiplier(),
current.into()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment