From a0a9ae34f26d128a0aa2fb69cbf99705762d1ada Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Thu, 16 Mar 2023 11:13:09 -0600 Subject: [PATCH 1/9] Initial mods for dynamic fee on moonbeam --- runtime/moonbeam/src/lib.rs | 27 ++++++++++++++++++++------ runtime/moonbeam/tests/common/mod.rs | 6 +++--- runtime/moonbeam/tests/runtime_apis.rs | 2 +- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 6ea2527d89..3a5bc364cb 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -369,13 +369,13 @@ parameter_types! { pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25); /// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to /// change the fees more rapidly. This low value causes changes to occur slowly over time. - pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000); + pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(4, 1_000); /// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure /// that combined with `AdjustmentVariable`, we can recover from the minimum. /// See `multiplier_can_grow_from_zero` in integration_tests.rs. /// This value is currently only used by pallet-transaction-payment as an assertion that the /// next multiplier is always > min value. - pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000u128); + pub MinimumMultiplier: Multiplier = Multiplier::from(1u128); /// Maximum multiplier. We pick a value that is expensive but not impossibly so; it should act /// as a safety net. pub MaximumMultiplier: Multiplier = Multiplier::from(100_000u128); @@ -383,11 +383,26 @@ parameter_types! { pub WeightPerGas: Weight = Weight::from_ref_time(WEIGHT_PER_GAS); } -pub struct FixedGasPrice; -impl FeeCalculator for FixedGasPrice { +pub struct TransactionPaymentAsGasPrice; +impl FeeCalculator for TransactionPaymentAsGasPrice { fn min_gas_price() -> (U256, Weight) { + // note: transaction-payment differs from EIP-1559 in that its tip and length fees are not + // scaled by the multiplier, which means its multiplier will be overstated when + // applied to an ethereum transaction + // note: transaction-payment uses both a congestion modifier (next_fee_multiplier, which is + // updated once per block in on_finalize) and a 'WeightToFee' implementation. Our + // runtime implements this as a 'ConstantModifier', so we can get away with a simple + // multiplication here. + // It is imperative that `saturating_mul_int` be performed as late as possible in the + // expression since it involves fixed point multiplication with a division by a fixed + // divisor. This leads to truncation and subsequent precision loss if performed too early. + // This can lead to min_gas_price being same across blocks even if the multiplier changes. + // 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.saturating_mul(WEIGHT_PER_GAS as u128)); ( - (1 * currency::GIGAWEI * currency::SUPPLY_FACTOR).into(), + min_gas_price.into(), ::DbWeight::get().reads(1), ) } @@ -435,7 +450,7 @@ where moonbeam_runtime_common::impl_on_charge_evm_transaction!(); impl pallet_evm::Config for Runtime { - type FeeCalculator = FixedGasPrice; + type FeeCalculator = TransactionPaymentAsGasPrice; type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping; diff --git a/runtime/moonbeam/tests/common/mod.rs b/runtime/moonbeam/tests/common/mod.rs index 0753dec9e3..5874860946 100644 --- a/runtime/moonbeam/tests/common/mod.rs +++ b/runtime/moonbeam/tests/common/mod.rs @@ -28,9 +28,9 @@ pub use moonbeam_runtime::{ currency::{GIGAWEI, GLMR, SUPPLY_FACTOR, WEI}, xcm_config::AssetType, AccountId, AssetId, AssetManager, Assets, AuthorInherent, Balance, Balances, CrowdloanRewards, - Ethereum, Executive, FixedGasPrice, InflationInfo, LocalAssets, ParachainStaking, Range, - Runtime, RuntimeCall, RuntimeEvent, System, TransactionConverter, UncheckedExtrinsic, HOURS, - WEEKS, + Ethereum, Executive, InflationInfo, LocalAssets, ParachainStaking, Range, Runtime, RuntimeCall, + RuntimeEvent, System, TransactionConverter, TransactionPaymentAsGasPrice, UncheckedExtrinsic, + HOURS, WEEKS, }; use nimbus_primitives::{NimbusId, NIMBUS_ENGINE_ID}; use sp_core::{Encode, H160}; diff --git a/runtime/moonbeam/tests/runtime_apis.rs b/runtime/moonbeam/tests/runtime_apis.rs index 0be83be2fb..05d0a80408 100644 --- a/runtime/moonbeam/tests/runtime_apis.rs +++ b/runtime/moonbeam/tests/runtime_apis.rs @@ -54,7 +54,7 @@ fn ethereum_runtime_rpc_api_account_basic() { #[test] fn ethereum_runtime_rpc_api_gas_price() { ExtBuilder::default().build().execute_with(|| { - assert_eq!(Runtime::gas_price(), FixedGasPrice::min_gas_price().0); + assert_eq!(Runtime::gas_price(), TransactionPaymentAsGasPrice::min_gas_price().0); }); } From 300f9407657fcb429ba2c7ed897959d5d8e1d07d Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Thu, 16 Mar 2023 13:42:32 -0600 Subject: [PATCH 2/9] Update tests to use increase fee --- runtime/moonbeam/tests/integration_test.rs | 43 +++++++++------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/runtime/moonbeam/tests/integration_test.rs b/runtime/moonbeam/tests/integration_test.rs index 8c81697127..fc4c3e9942 100644 --- a/runtime/moonbeam/tests/integration_test.rs +++ b/runtime/moonbeam/tests/integration_test.rs @@ -75,6 +75,8 @@ type LocalAssetsPCall = pallet_evm_precompileset_assets_erc20::Erc20AssetsPrecom type XcmTransactorV1PCall = pallet_evm_precompile_xcm_transactor::v1::XcmTransactorPrecompileV1Call; +const BASE_FEE_GENESIS: u128 = 10000 * GIGAWEI; + #[test] fn xcmp_queue_controller_origin_is_root() { // important for the XcmExecutionManager impl of PauseExecution which uses root origin @@ -434,7 +436,7 @@ fn transfer_through_evm_to_stake() { assert_eq!(Balances::free_balance(AccountId::from(BOB)), 200_000 * GLMR); let gas_limit = 100000u64; - let gas_price: U256 = (100 * GIGAWEI).into(); + let gas_price: U256 = BASE_FEE_GENESIS.into(); // Bob transfers 100_000 GLMR to Charlie via EVM assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { source: H160::from(BOB), @@ -855,7 +857,7 @@ fn claim_via_precompile() { // Alice uses the crowdloan precompile to claim through the EVM let gas_limit = 100000u64; - let gas_price: U256 = 100_000_000_000u64.into(); + let gas_price: U256 = BASE_FEE_GENESIS.into(); // Construct the call data (selector, amount) let mut call_data = Vec::::from([0u8; 4]); @@ -1101,7 +1103,7 @@ fn update_reward_address_via_precompile() { // Charlie uses the crowdloan precompile to update address through the EVM let gas_limit = 100000u64; - let gas_price: U256 = 100_000_000_000u64.into(); + let gas_price: U256 = BASE_FEE_GENESIS.into(); // Construct the input data to check if Bob is a contributor let mut call_data = Vec::::from([0u8; 36]); @@ -1246,7 +1248,7 @@ fn transfer_ed_0_evm() { .with_balances(vec![ ( AccountId::from(ALICE), - ((1 * GLMR) + (21_000 * (100 * GIGAWEI))) + (1 * WEI), + ((1 * GLMR) + (21_000 * BASE_FEE_GENESIS)) + (1 * WEI), ), (AccountId::from(BOB), 0), ]) @@ -1259,8 +1261,8 @@ fn transfer_ed_0_evm() { input: Vec::new(), value: (1 * GLMR).into(), gas_limit: 21_000u64, - max_fee_per_gas: U256::from(100 * GIGAWEI), - max_priority_fee_per_gas: None, + max_fee_per_gas: BASE_FEE_GENESIS.into(), + max_priority_fee_per_gas: Some(BASE_FEE_GENESIS.into()), nonce: Some(U256::from(0)), access_list: Vec::new(), }) @@ -1276,7 +1278,7 @@ fn refund_ed_0_evm() { .with_balances(vec![ ( AccountId::from(ALICE), - ((1 * GLMR) + (21_777 * (100 * GIGAWEI))), + ((1 * GLMR) + (21_777 * BASE_FEE_GENESIS)), ), (AccountId::from(BOB), 0), ]) @@ -1289,8 +1291,8 @@ fn refund_ed_0_evm() { input: Vec::new(), value: (1 * GLMR).into(), gas_limit: 21_777u64, - max_fee_per_gas: U256::from(100 * GIGAWEI), - max_priority_fee_per_gas: None, + max_fee_per_gas: BASE_FEE_GENESIS.into(), + max_priority_fee_per_gas: Some(BASE_FEE_GENESIS.into()), nonce: Some(U256::from(0)), access_list: Vec::new(), }) @@ -1298,7 +1300,7 @@ fn refund_ed_0_evm() { // ALICE is refunded assert_eq!( Balances::free_balance(AccountId::from(ALICE)), - 777 * (100 * GIGAWEI), + 777 * BASE_FEE_GENESIS, ); }); } @@ -1378,7 +1380,7 @@ fn total_issuance_after_evm_transaction_without_priority_fee() { ExtBuilder::default() .with_balances(vec![( AccountId::from(BOB), - (1 * GLMR) + (21_000 * (200 * GIGAWEI)), + (1 * GLMR) + (21_000 * BASE_FEE_GENESIS), )]) .build() .execute_with(|| { @@ -1390,8 +1392,8 @@ fn total_issuance_after_evm_transaction_without_priority_fee() { input: Vec::new(), value: (1 * GLMR).into(), gas_limit: 21_000u64, - max_fee_per_gas: U256::from(100 * GIGAWEI), - max_priority_fee_per_gas: None, + max_fee_per_gas: BASE_FEE_GENESIS.into(), + max_priority_fee_per_gas: Some(BASE_FEE_GENESIS.into()), nonce: Some(U256::from(0)), access_list: Vec::new(), }) @@ -1399,7 +1401,7 @@ fn total_issuance_after_evm_transaction_without_priority_fee() { let issuance_after = ::Currency::total_issuance(); // Fee is 100 GWEI base fee. - let fee = ((100 * GIGAWEI) * 21_000) as f64; + let fee = (BASE_FEE_GENESIS * 21_000) as f64; // 80% was burned. let expected_burn = (fee * 0.8) as u128; assert_eq!(issuance_after, issuance_before - expected_burn,); @@ -2878,15 +2880,6 @@ fn precompile_existence() { }); } -#[test] -fn base_fee_should_default_to_associate_type_value() { - ExtBuilder::default().build().execute_with(|| { - let (base_fee, _) = - ::FeeCalculator::min_gas_price(); - assert_eq!(base_fee, (1 * GIGAWEI * SUPPLY_FACTOR).into()); - }); -} - #[test] fn evm_revert_substrate_events() { ExtBuilder::default() @@ -2910,7 +2903,7 @@ fn evm_revert_substrate_events() { .into(), value: U256::zero(), // No value sent in EVM gas_limit: 500_000, - max_fee_per_gas: U256::from(100 * GIGAWEI), + max_fee_per_gas: BASE_FEE_GENESIS.into(), max_priority_fee_per_gas: None, nonce: Some(U256::from(0)), access_list: Vec::new(), @@ -2949,7 +2942,7 @@ fn evm_success_keeps_substrate_events() { .into(), value: U256::zero(), // No value sent in EVM gas_limit: 500_000, - max_fee_per_gas: U256::from(100 * GIGAWEI), + max_fee_per_gas: BASE_FEE_GENESIS.into(), max_priority_fee_per_gas: None, nonce: Some(U256::from(0)), access_list: Vec::new(), From 19ff82ddd0e1bedc40fbcef6a35b30a42cbf1f98 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Thu, 16 Mar 2023 14:55:46 -0600 Subject: [PATCH 3/9] Bump gas price in test --- tests/tests/test-precompile/test-precompile-xcm-utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests/test-precompile/test-precompile-xcm-utils.ts b/tests/tests/test-precompile/test-precompile-xcm-utils.ts index 188e4efed2..397d9c81e0 100644 --- a/tests/tests/test-precompile/test-precompile-xcm-utils.ts +++ b/tests/tests/test-precompile/test-precompile-xcm-utils.ts @@ -276,7 +276,7 @@ describeDevMoonbeam( const { result } = await context.createBlock( createTransaction(context, { ...ALITH_TRANSACTION_TEMPLATE, - gasPrice: 100_000_000_000, + gasPrice: 1_000_000_000_000, to: PRECOMPILE_XCM_UTILS_ADDRESS, data: XCM_UTILSTRANSACTOR_INTERFACE.encodeFunctionData("xcmExecute", [ receivedMessage.toU8a(), From 31dba39abaa806e87177439e3cab90c9a0273b96 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Thu, 16 Mar 2023 16:39:59 -0600 Subject: [PATCH 4/9] Comment out failing test (temporarily) --- runtime/moonbeam/tests/common/mod.rs | 7 ++++--- runtime/moonbeam/tests/runtime_apis.rs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/runtime/moonbeam/tests/common/mod.rs b/runtime/moonbeam/tests/common/mod.rs index 5874860946..5212c7a30f 100644 --- a/runtime/moonbeam/tests/common/mod.rs +++ b/runtime/moonbeam/tests/common/mod.rs @@ -42,9 +42,10 @@ use fp_rpc::ConvertTransaction; // A valid signed Alice transfer. pub const VALID_ETH_TX: &str = - "f8648085174876e8008252089412cb274aad8251c875c0bf6872b67d9983e53fdd01801ba05deb036\ - 17e9c2d82e0f4e897ef8fbb01c91244abfc4bd9c3206bc87f9fc71a01a0719f146637fe2b462ccae80\ - e462ecefa560635d933257ec117a1f7701b178c93"; + "02f86b820504808087038d7ea4c68000825208943cd0a705a2dc65e5b1e1205896baa2be8a07c6e080\ + 80c080a0932bca8e518f16759c782e5403e3fe55902ecb1b988c8499f015a6617b636e1ca05f6659d0f9\ + 943cf29b611ef1a46b1e4ccc56df524e1f4f08607132142fec0ff0"; + // An invalid signed Alice transfer with a gas limit artifically set to 0. pub const INVALID_ETH_TX: &str = diff --git a/runtime/moonbeam/tests/runtime_apis.rs b/runtime/moonbeam/tests/runtime_apis.rs index 05d0a80408..ff7a28572d 100644 --- a/runtime/moonbeam/tests/runtime_apis.rs +++ b/runtime/moonbeam/tests/runtime_apis.rs @@ -214,7 +214,7 @@ fn ethereum_runtime_rpc_api_current_transaction_statuses() { rpc_run_to_block(2); let statuses = Runtime::current_transaction_statuses().expect("Transaction statuses result."); - assert_eq!(statuses.len(), 1); + // assert_eq!(statuses.len(), 1); }); } @@ -274,7 +274,7 @@ fn ethereum_runtime_rpc_api_current_receipts() { rpc_run_to_block(2); let receipts = Runtime::current_receipts().expect("Receipts result."); - assert_eq!(receipts.len(), 1); + // assert_eq!(receipts.len(), 1); }); } From 3068dbbaeb17925abe86b0ed61e08eb2c2cacdfa Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Thu, 16 Mar 2023 16:48:46 -0600 Subject: [PATCH 5/9] fmt --- runtime/moonbeam/tests/common/mod.rs | 1 - runtime/moonbeam/tests/runtime_apis.rs | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/moonbeam/tests/common/mod.rs b/runtime/moonbeam/tests/common/mod.rs index 5212c7a30f..f59adb0568 100644 --- a/runtime/moonbeam/tests/common/mod.rs +++ b/runtime/moonbeam/tests/common/mod.rs @@ -46,7 +46,6 @@ pub const VALID_ETH_TX: &str = 80c080a0932bca8e518f16759c782e5403e3fe55902ecb1b988c8499f015a6617b636e1ca05f6659d0f9\ 943cf29b611ef1a46b1e4ccc56df524e1f4f08607132142fec0ff0"; - // An invalid signed Alice transfer with a gas limit artifically set to 0. pub const INVALID_ETH_TX: &str = "f8628085174876e800809412cb274aad8251c875c0bf6872b67d9983e53fdd01801ba011110796057\ diff --git a/runtime/moonbeam/tests/runtime_apis.rs b/runtime/moonbeam/tests/runtime_apis.rs index ff7a28572d..d9620cfe94 100644 --- a/runtime/moonbeam/tests/runtime_apis.rs +++ b/runtime/moonbeam/tests/runtime_apis.rs @@ -54,7 +54,10 @@ fn ethereum_runtime_rpc_api_account_basic() { #[test] fn ethereum_runtime_rpc_api_gas_price() { ExtBuilder::default().build().execute_with(|| { - assert_eq!(Runtime::gas_price(), TransactionPaymentAsGasPrice::min_gas_price().0); + assert_eq!( + Runtime::gas_price(), + TransactionPaymentAsGasPrice::min_gas_price().0 + ); }); } From 817fbac3d6fbe40df990c455b5839d12febef61a Mon Sep 17 00:00:00 2001 From: notlesh Date: Thu, 30 Mar 2023 20:24:05 +0000 Subject: [PATCH 6/9] Some actually VALID_ETH_TX bytes! --- runtime/moonbeam/tests/common/mod.rs | 6 +++--- runtime/moonbeam/tests/runtime_apis.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/runtime/moonbeam/tests/common/mod.rs b/runtime/moonbeam/tests/common/mod.rs index f59adb0568..4a298ebe02 100644 --- a/runtime/moonbeam/tests/common/mod.rs +++ b/runtime/moonbeam/tests/common/mod.rs @@ -42,9 +42,9 @@ use fp_rpc::ConvertTransaction; // A valid signed Alice transfer. pub const VALID_ETH_TX: &str = - "02f86b820504808087038d7ea4c68000825208943cd0a705a2dc65e5b1e1205896baa2be8a07c6e080\ - 80c080a0932bca8e518f16759c782e5403e3fe55902ecb1b988c8499f015a6617b636e1ca05f6659d0f9\ - 943cf29b611ef1a46b1e4ccc56df524e1f4f08607132142fec0ff0"; + "02f869820501808085e8d4a51000825208943cd0a705a2dc65e5b1e1205896baa2be8a07c6e00180c\ + 001a061087911e877a5802142a89a40d231d50913db399eb50839bb2d04e612b22ec8a01aa313efdf2\ + 793bea76da6813bda611444af16a6207a8cfef2d9c8aa8f8012f7"; // An invalid signed Alice transfer with a gas limit artifically set to 0. pub const INVALID_ETH_TX: &str = diff --git a/runtime/moonbeam/tests/runtime_apis.rs b/runtime/moonbeam/tests/runtime_apis.rs index d9620cfe94..4f9e549f68 100644 --- a/runtime/moonbeam/tests/runtime_apis.rs +++ b/runtime/moonbeam/tests/runtime_apis.rs @@ -189,7 +189,7 @@ fn ethereum_runtime_rpc_api_create() { #[test] fn ethereum_runtime_rpc_api_current_transaction_statuses() { let alith = ::AddressMapping::into_account_id( - H160::from_str("6be02d1d3665660d22ff9624b7be0551ee1ac91b") + H160::from_str("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac") .expect("internal H160 is valid; qed"), ); ExtBuilder::default() @@ -217,7 +217,7 @@ fn ethereum_runtime_rpc_api_current_transaction_statuses() { rpc_run_to_block(2); let statuses = Runtime::current_transaction_statuses().expect("Transaction statuses result."); - // assert_eq!(statuses.len(), 1); + assert_eq!(statuses.len(), 1); }); } @@ -250,7 +250,7 @@ fn ethereum_runtime_rpc_api_current_block() { #[test] fn ethereum_runtime_rpc_api_current_receipts() { let alith = ::AddressMapping::into_account_id( - H160::from_str("6be02d1d3665660d22ff9624b7be0551ee1ac91b") + H160::from_str("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac") .expect("internal H160 is valid; qed"), ); ExtBuilder::default() @@ -277,7 +277,7 @@ fn ethereum_runtime_rpc_api_current_receipts() { rpc_run_to_block(2); let receipts = Runtime::current_receipts().expect("Receipts result."); - // assert_eq!(receipts.len(), 1); + assert_eq!(receipts.len(), 1); }); } From 77dbf45a94d72ce4a17b832da19741d4b0e2732c Mon Sep 17 00:00:00 2001 From: notlesh Date: Fri, 31 Mar 2023 16:13:54 +0000 Subject: [PATCH 7/9] Remove unused import --- runtime/moonbeam/tests/integration_test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/moonbeam/tests/integration_test.rs b/runtime/moonbeam/tests/integration_test.rs index 1a7f61b620..6bf318af2c 100644 --- a/runtime/moonbeam/tests/integration_test.rs +++ b/runtime/moonbeam/tests/integration_test.rs @@ -21,7 +21,7 @@ mod common; use common::*; -use fp_evm::{Context, FeeCalculator}; +use fp_evm::Context; use frame_support::{ assert_noop, assert_ok, dispatch::{DispatchClass, Dispatchable}, From 3d4da476e412dab2a6bbe45fb6738e559607150e Mon Sep 17 00:00:00 2001 From: notlesh Date: Mon, 3 Apr 2023 16:30:39 +0000 Subject: [PATCH 8/9] Add multiplier tests --- runtime/moonbeam/tests/integration_test.rs | 45 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/runtime/moonbeam/tests/integration_test.rs b/runtime/moonbeam/tests/integration_test.rs index 6bf318af2c..8760c5b4f1 100644 --- a/runtime/moonbeam/tests/integration_test.rs +++ b/runtime/moonbeam/tests/integration_test.rs @@ -38,14 +38,15 @@ use moonbeam_runtime::{ currency::GLMR, xcm_config::{CurrencyId, SelfReserve, UnitWeightCost}, AccountId, Balances, CrowdloanRewards, ParachainStaking, PolkadotXcm, Precompiles, Runtime, - RuntimeBlockWeights, RuntimeCall, RuntimeEvent, System, XTokens, XcmTransactor, - FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, LOCAL_ASSET_PRECOMPILE_ADDRESS_PREFIX, + RuntimeBlockWeights, RuntimeCall, RuntimeEvent, System, TransactionPayment, XTokens, + XcmTransactor, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, LOCAL_ASSET_PRECOMPILE_ADDRESS_PREFIX, }; use nimbus_primitives::NimbusId; use pallet_evm::PrecompileSet; use pallet_evm_precompileset_assets_erc20::{ AccountIdAssetIdConversion, IsLocal, SELECTOR_LOG_APPROVAL, SELECTOR_LOG_TRANSFER, }; +use pallet_transaction_payment::Multiplier; use pallet_xcm_transactor::{Currency, CurrencyPayment, TransactWeights}; use parity_scale_codec::Encode; use polkadot_parachain::primitives::Sibling; @@ -1222,6 +1223,46 @@ fn ethereum_invalid_transaction() { }); } +#[test] +fn initial_gas_fee_is_correct() { + use fp_evm::FeeCalculator; + + ExtBuilder::default().build().execute_with(|| { + let multiplier = TransactionPayment::next_fee_multiplier(); + assert_eq!(multiplier, Multiplier::from(1u128)); + + assert_eq!( + TransactionPaymentAsGasPrice::min_gas_price(), + ( + 125_000_000_000u128.into(), + Weight::from_ref_time(25_000_000u64) + ) + ); + }); +} + +#[test] +fn min_gas_fee_is_correct() { + use fp_evm::FeeCalculator; + use frame_support::traits::Hooks; + + ExtBuilder::default().build().execute_with(|| { + pallet_transaction_payment::NextFeeMultiplier::::put(Multiplier::from(0)); + TransactionPayment::on_finalize(System::block_number()); // should trigger min to kick in + + let multiplier = TransactionPayment::next_fee_multiplier(); + assert_eq!(multiplier, Multiplier::from(1u128)); + + assert_eq!( + TransactionPaymentAsGasPrice::min_gas_price(), + ( + 125_000_000_000u128.into(), + Weight::from_ref_time(25_000_000u64) + ) + ); + }); +} + #[test] fn transfer_ed_0_substrate() { ExtBuilder::default() From 5d509562358b97d8d0512441572ee132efe2f1b2 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Tue, 11 Apr 2023 20:21:13 +0100 Subject: [PATCH 9/9] Enabled dynamic fees smoketest for MB --- tests/smoke-tests/test-dynamic-fees.ts | 7 +++++-- tests/util/constants.ts | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/smoke-tests/test-dynamic-fees.ts b/tests/smoke-tests/test-dynamic-fees.ts index 0db27345c8..b8fc017093 100644 --- a/tests/smoke-tests/test-dynamic-fees.ts +++ b/tests/smoke-tests/test-dynamic-fees.ts @@ -116,8 +116,11 @@ describeSmokeSuite( this.skip(); } - if (specName.toString() == "moonbeam") { - debug(`Runtime ${specName.toString()} not supported by these tests, skipping.`); + if (specVersion.toNumber() < 2300 && specName.toString() == "moonbeam") { + debug( + `Runtime ${specName.toString()} version ` + + `${specVersion.toString()} is less than 2300, skipping test suite.` + ); this.skip(); } diff --git a/tests/util/constants.ts b/tests/util/constants.ts index 64531ac7f1..b911959b5a 100644 --- a/tests/util/constants.ts +++ b/tests/util/constants.ts @@ -127,9 +127,9 @@ export const RUNTIME_CONSTANTS = { MAX_BASE_FEE_IN_WEI: "125000000000000", }, MOONBEAM: { - MIN_FEE_MULTIPLIER: "1000000000000", - MAX_FEE_MULTIPLIER: "100000000000000000", - MIN_BASE_FEE_IN_WEI: "", - MAX_BASE_FEE_IN_WEI: "", + MIN_FEE_MULTIPLIER: "1000000000000000000", + MAX_FEE_MULTIPLIER: "100000000000000000000000", + MIN_BASE_FEE_IN_WEI: "125000000000", + MAX_BASE_FEE_IN_WEI: "12500000000000000", }, };