Skip to content

Commit

Permalink
Divides min gas price by 4 (#3058)
Browse files Browse the repository at this point in the history
* Divides min gas price by 4

* format

* Updates rust tests to match new min gas price

* fmt

* Temp fix for tests

* fix dev tests

* Fixes last tests

* fix left debug logs

* fix gas price constants

* more constants

* fmt
  • Loading branch information
crystalin authored Nov 29, 2024
1 parent 58bb0c5 commit c8cc4ed
Show file tree
Hide file tree
Showing 22 changed files with 231 additions and 170 deletions.
2 changes: 1 addition & 1 deletion runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl FeeCalculator for TransactionPaymentAsGasPrice {
// There's still some precision loss when the final `gas_price` (used_gas * min_gas_price)
// is computed in frontier, but that's currently unavoidable.
let min_gas_price = TransactionPayment::next_fee_multiplier()
.saturating_mul_int((currency::WEIGHT_FEE * 4).saturating_mul(WEIGHT_PER_GAS as u128));
.saturating_mul_int((currency::WEIGHT_FEE).saturating_mul(WEIGHT_PER_GAS as u128));
(
min_gas_price.into(),
<Runtime as frame_system::Config>::DbWeight::get().reads(1),
Expand Down
18 changes: 8 additions & 10 deletions runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type XcmTransactorV2PCall =
pallet_evm_precompile_xcm_transactor::v2::XcmTransactorPrecompileV2Call<Runtime>;

// TODO: can we construct a const U256...?
const BASE_FEE_GENISIS: u128 = 10 * GIGAWEI;
const BASE_FEE_GENISIS: u128 = 10 * GIGAWEI / 4;

#[test]
fn xcmp_queue_controller_origin_is_root() {
Expand Down Expand Up @@ -1864,7 +1864,7 @@ fn initial_gas_fee_is_correct() {
assert_eq!(
TransactionPaymentAsGasPrice::min_gas_price(),
(
10_000_000_000u128.into(),
2_500_000_000u128.into(),
Weight::from_parts(41_742_000u64, 0)
)
);
Expand Down Expand Up @@ -3035,9 +3035,7 @@ mod fee_tests {
pallet_transaction_payment::NextFeeMultiplier::<Runtime>::set(multiplier);
let actual = TransactionPaymentAsGasPrice::min_gas_price().0;
let expected: U256 = multiplier
.saturating_mul_int(
(currency::WEIGHT_FEE * 4).saturating_mul(WEIGHT_PER_GAS as u128),
)
.saturating_mul_int(currency::WEIGHT_FEE.saturating_mul(WEIGHT_PER_GAS as u128))
.into();

assert_eq!(expected, actual);
Expand Down Expand Up @@ -3074,8 +3072,7 @@ mod fee_tests {
.unwrap()
.into();
t.execute_with(|| {
let weight_fee_per_gas =
(currency::WEIGHT_FEE * 4).saturating_mul(WEIGHT_PER_GAS as u128);
let weight_fee_per_gas = (currency::WEIGHT_FEE).saturating_mul(WEIGHT_PER_GAS as u128);
let sim = |start_gas_price: u128, fullness: Perbill, num_blocks: u64| -> U256 {
let start_multiplier =
FixedU128::from_rational(start_gas_price, weight_fee_per_gas);
Expand Down Expand Up @@ -3136,19 +3133,20 @@ mod fee_tests {
// 1 "real" day (at 6-second blocks)
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(0), 14400),
U256::from(125_000_000), // lower bound enforced
U256::from(31_250_000), // lower bound enforced
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(25), 14400),
U256::from(125_000_000),
U256::from(31_250_000), // lower bound enforced if threshold not reached
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(50), 14400),
U256::from(5_653_326_895_069u128),
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(100), 14400),
U256::from(125_000_000_000_000u128), // upper bound enforced
U256::from(31_250_000_000_000u128),
// upper bound enforced (min_gas_price * MaximumMultiplier)
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ impl FeeCalculator for TransactionPaymentAsGasPrice {
// There's still some precision loss when the final `gas_price` (used_gas * min_gas_price)
// is computed in frontier, but that's currently unavoidable.
let min_gas_price = TransactionPayment::next_fee_multiplier()
.saturating_mul_int((currency::WEIGHT_FEE * 4).saturating_mul(WEIGHT_PER_GAS as u128));
.saturating_mul_int((currency::WEIGHT_FEE).saturating_mul(WEIGHT_PER_GAS as u128));
(
min_gas_price.into(),
<Runtime as frame_system::Config>::DbWeight::get().reads(1),
Expand Down
41 changes: 19 additions & 22 deletions runtime/moonbeam/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ fn initial_gas_fee_is_correct() {
assert_eq!(
TransactionPaymentAsGasPrice::min_gas_price(),
(
125_000_000_000u128.into(),
31_250_000_000u128.into(),
Weight::from_parts(41_742_000u64, 0)
)
);
Expand All @@ -1407,7 +1407,7 @@ fn min_gas_fee_is_correct() {
assert_eq!(
TransactionPaymentAsGasPrice::min_gas_price(),
(
125_000_000_000u128.into(),
31_250_000_000u128.into(),
Weight::from_parts(41_742_000u64, 0)
)
);
Expand Down Expand Up @@ -1554,16 +1554,16 @@ fn total_issuance_after_evm_transaction_with_priority_fee() {
input: Vec::new(),
value: (1 * GLMR).into(),
gas_limit: 21_000u64,
max_fee_per_gas: U256::from(200 * GIGAWEI),
max_fee_per_gas: U256::from(125 * GIGAWEI),
max_priority_fee_per_gas: Some(U256::from(100 * GIGAWEI)),
nonce: Some(U256::from(0)),
access_list: Vec::new(),
})
.dispatch(<Runtime as frame_system::Config>::RuntimeOrigin::root()));

let issuance_after = <Runtime as pallet_evm::Config>::Currency::total_issuance();
// Fee is 100 GWEI base fee + 100 GWEI tip.
let fee = ((200 * GIGAWEI) * 21_000) as f64;
// Fee is 25 GWEI base fee + 100 GWEI tip.
let fee = ((125 * GIGAWEI) * 21_000) as f64;
// 80% was burned.
let expected_burn = (fee * 0.8) as u128;
assert_eq!(issuance_after, issuance_before - expected_burn,);
Expand Down Expand Up @@ -2821,9 +2821,7 @@ mod fee_tests {
pallet_transaction_payment::NextFeeMultiplier::<Runtime>::set(multiplier);
let actual = TransactionPaymentAsGasPrice::min_gas_price().0;
let expected: U256 = multiplier
.saturating_mul_int(
(currency::WEIGHT_FEE * 4).saturating_mul(WEIGHT_PER_GAS as u128),
)
.saturating_mul_int(currency::WEIGHT_FEE.saturating_mul(WEIGHT_PER_GAS as u128))
.into();

assert_eq!(expected, actual);
Expand Down Expand Up @@ -2860,8 +2858,7 @@ mod fee_tests {
.unwrap()
.into();
t.execute_with(|| {
let weight_fee_per_gas =
(currency::WEIGHT_FEE * 4).saturating_mul(WEIGHT_PER_GAS as u128);
let weight_fee_per_gas = (currency::WEIGHT_FEE).saturating_mul(WEIGHT_PER_GAS as u128);
let sim = |start_gas_price: u128, fullness: Perbill, num_blocks: u64| -> U256 {
let start_multiplier =
FixedU128::from_rational(start_gas_price, weight_fee_per_gas);
Expand All @@ -2886,55 +2883,55 @@ mod fee_tests {

assert_eq!(
sim(1_000_000_000, Perbill::from_percent(0), 1),
U256::from(125_000_000_000u128),
U256::from(31_250_000_000u128), // lower bound enforced
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(25), 1),
U256::from(125_000_000_000u128),
U256::from(31_250_000_000u128),
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(50), 1),
U256::from(125_075_022_500u128),
U256::from(31_268_755_625u128), // slightly higher than lower bound
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(100), 1),
U256::from(125_325_422_500u128),
U256::from(31_331_355_625u128), // a bit higher than before
);

// 1 "real" hour (at 12-second blocks)
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(0), 600),
U256::from(125_000_000_000u128),
U256::from(31_250_000_000u128), // lower bound enforced
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(25), 600),
U256::from(125_000_000_000u128),
U256::from(31_250_000_000u128),
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(50), 600),
U256::from(179_166_172_951u128),
U256::from(44_791_543_237u128), // a bit higher than lower bound
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(100), 600),
U256::from(594_851_612_166u128),
U256::from(148_712_903_041u128), // a lot more
);

// 1 "real" day (at 12-second blocks)
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(0), 14400),
U256::from(125_000_000_000u128), // lower bound enforced
U256::from(31_250_000_000u128), // lower bound enforced
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(25), 14400),
U256::from(125_000_000_000u128),
U256::from(31_250_000_000u128),
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(50), 14400),
U256::from(706_665_861_883_635u128),
U256::from(176_666_465_470_908u128), // significantly higher
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(100), 14400),
U256::from(12_500_000_000_000_000u128), // upper bound enforced
U256::from(3_125_000_000_000_000u128), // upper bound enforced
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ impl FeeCalculator for TransactionPaymentAsGasPrice {
// There's still some precision loss when the final `gas_price` (used_gas * min_gas_price)
// is computed in frontier, but that's currently unavoidable.
let min_gas_price = TransactionPayment::next_fee_multiplier()
.saturating_mul_int((currency::WEIGHT_FEE * 4).saturating_mul(WEIGHT_PER_GAS as u128));
.saturating_mul_int((currency::WEIGHT_FEE).saturating_mul(WEIGHT_PER_GAS as u128));
(
min_gas_price.into(),
<Runtime as frame_system::Config>::DbWeight::get().reads(1),
Expand Down
62 changes: 28 additions & 34 deletions runtime/moonriver/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ fn initial_gas_fee_is_correct() {
assert_eq!(
TransactionPaymentAsGasPrice::min_gas_price(),
(
12_500_000_000u128.into(),
3_125_000_000u128.into(),
Weight::from_parts(41_742_000u64, 0)
)
);
Expand All @@ -1393,10 +1393,7 @@ fn min_gas_fee_is_correct() {

assert_eq!(
TransactionPaymentAsGasPrice::min_gas_price(),
(
1_250_000_000u128.into(),
Weight::from_parts(41_742_000u64, 0)
)
(312_500_000u128.into(), Weight::from_parts(41_742_000u64, 0))
);
});
}
Expand Down Expand Up @@ -2719,9 +2716,7 @@ mod fee_tests {
pallet_transaction_payment::NextFeeMultiplier::<Runtime>::set(multiplier);
let actual = TransactionPaymentAsGasPrice::min_gas_price().0;
let expected: U256 = multiplier
.saturating_mul_int(
(currency::WEIGHT_FEE * 4).saturating_mul(WEIGHT_PER_GAS as u128),
)
.saturating_mul_int(currency::WEIGHT_FEE.saturating_mul(WEIGHT_PER_GAS as u128))
.into();

assert_eq!(expected, actual);
Expand Down Expand Up @@ -2758,8 +2753,7 @@ mod fee_tests {
.unwrap()
.into();
t.execute_with(|| {
let weight_fee_per_gas =
(currency::WEIGHT_FEE * 4).saturating_mul(WEIGHT_PER_GAS as u128);
let weight_fee_per_gas = (currency::WEIGHT_FEE).saturating_mul(WEIGHT_PER_GAS as u128);
let sim = |start_gas_price: u128, fullness: Perbill, num_blocks: u64| -> U256 {
let start_multiplier =
FixedU128::from_rational(start_gas_price, weight_fee_per_gas);
Expand All @@ -2783,56 +2777,56 @@ mod fee_tests {
// it may indicate an unexpected collateral effect and should be investigated

assert_eq!(
sim(1_000_000_000, Perbill::from_percent(0), 1),
U256::from(1_250_000_000u128),
sim(100_000_000, Perbill::from_percent(0), 1),
U256::from(312_500_000u128), // lower bound enforced
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(25), 1),
U256::from(1_250_000_000u128),
sim(100_000_000, Perbill::from_percent(25), 1),
U256::from(312_500_000u128),
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(50), 1),
U256::from(1_250_750_225u128),
sim(100_000_000, Perbill::from_percent(50), 1),
U256::from(312_687_556u128), // slightly higher than lower bound
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(100), 1),
U256::from(1_253_254_225u128),
sim(100_000_000, Perbill::from_percent(100), 1),
U256::from(313_313_556u128),
);

// 1 "real" hour (at 6-second blocks)
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(0), 600),
U256::from(1_250_000_000u128),
sim(100_000_000, Perbill::from_percent(0), 600),
U256::from(312_500_000u128),
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(25), 600),
U256::from(1_250_000_000u128),
sim(100_000_000, Perbill::from_percent(25), 600),
U256::from(312_500_000u128),
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(50), 600),
U256::from(1_791_661_729u128),
sim(100_000_000, Perbill::from_percent(50), 600),
U256::from(447_915_432u128),
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(100), 600),
U256::from(5_948_516_121u128),
sim(100_000_000, Perbill::from_percent(100), 600),
U256::from(1_487_129_030u128),
);

// 1 "real" day (at 6-second blocks)
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(0), 14400),
U256::from(1_250_000_000u128), // lower bound enforced
sim(100_000_000, Perbill::from_percent(0), 14400),
U256::from(312_500_000u128), // lower bound enforced
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(25), 14400),
U256::from(1_250_000_000u128),
sim(100_000_000, Perbill::from_percent(25), 14400),
U256::from(312_500_000u128),
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(50), 14400),
U256::from(7_066_658_618_836u128),
sim(100_000_000, Perbill::from_percent(50), 14400),
U256::from(1_766_664_654_709u128),
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(100), 14400),
U256::from(125_000_000_000_000u128), // upper bound enforced
sim(100_000_000, Perbill::from_percent(100), 14400),
U256::from(31_250_000_000_000u128), // upper bound enforced
);
});
}
Expand Down
Loading

0 comments on commit c8cc4ed

Please sign in to comment.