-
Notifications
You must be signed in to change notification settings - Fork 383
Add Dynamic Fee support for Moonbeam #2166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a0a9ae3
Initial mods for dynamic fee on moonbeam
notlesh 300f940
Update tests to use increase fee
notlesh 19ff82d
Bump gas price in test
notlesh 31dba39
Comment out failing test (temporarily)
notlesh 3068dbb
fmt
notlesh 08390e7
Merge branch 'master' into notlesh-dynamic-fee-moonbeam
notlesh 817fbac
Some actually VALID_ETH_TX bytes!
notlesh 77dbf45
Remove unused import
notlesh 3d4da47
Add multiplier tests
notlesh 5d50956
Enabled dynamic fees smoketest for MB
timbrinded 3067174
Merge branch 'master' into notlesh-dynamic-fee-moonbeam
notlesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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}, | ||
|
|
@@ -39,14 +39,15 @@ use moonbeam_runtime::{ | |
| xcm_config::{CurrencyId, SelfReserve, UnitWeightCost}, | ||
| AccountId, Balances, CouncilCollective, CrowdloanRewards, ParachainStaking, PolkadotXcm, | ||
| Precompiles, Runtime, RuntimeBlockWeights, RuntimeCall, RuntimeEvent, System, | ||
| TechCommitteeCollective, TreasuryCouncilCollective, XTokens, XcmTransactor, | ||
| TechCommitteeCollective, TransactionPayment, TreasuryCouncilCollective, 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; | ||
|
|
@@ -76,6 +77,8 @@ type LocalAssetsPCall = pallet_evm_precompileset_assets_erc20::Erc20AssetsPrecom | |
| type XcmTransactorV2PCall = | ||
| pallet_evm_precompile_xcm_transactor::v2::XcmTransactorPrecompileV2Call<Runtime>; | ||
|
|
||
| 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 | ||
|
|
@@ -496,7 +499,7 @@ fn transfer_through_evm_to_stake() { | |
| ); | ||
|
|
||
| let gas_limit = 100000u64; | ||
| let gas_price: U256 = (100 * GIGAWEI).into(); | ||
| let gas_price: U256 = BASE_FEE_GENESIS.into(); | ||
| // Bob transfers 2_000_000 GLMR to Charlie via EVM | ||
| assert_ok!(RuntimeCall::EVM(pallet_evm::Call::<Runtime>::call { | ||
| source: H160::from(BOB), | ||
|
|
@@ -917,7 +920,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::<u8>::from([0u8; 4]); | ||
|
|
@@ -1163,7 +1166,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::<u8>::from([0u8; 36]); | ||
|
|
@@ -1282,6 +1285,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::<Runtime>::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) | ||
| ) | ||
| ); | ||
|
Comment on lines
+1318
to
+1324
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tgmichel this should address your earlier comment. It is indeed Does |
||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn transfer_ed_0_substrate() { | ||
| ExtBuilder::default() | ||
|
|
@@ -1308,7 +1351,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), | ||
| ]) | ||
|
|
@@ -1321,8 +1364,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(), | ||
| }) | ||
|
|
@@ -1338,7 +1381,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), | ||
| ]) | ||
|
|
@@ -1351,16 +1394,16 @@ 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(), | ||
| }) | ||
| .dispatch(<Runtime as frame_system::Config>::RuntimeOrigin::root())); | ||
| // ALICE is refunded | ||
| assert_eq!( | ||
| Balances::free_balance(AccountId::from(ALICE)), | ||
| 777 * (100 * GIGAWEI), | ||
| 777 * BASE_FEE_GENESIS, | ||
| ); | ||
| }); | ||
| } | ||
|
|
@@ -1440,7 +1483,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(|| { | ||
|
|
@@ -1452,16 +1495,16 @@ 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(), | ||
| }) | ||
| .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. | ||
| 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,); | ||
|
|
@@ -2875,15 +2918,6 @@ fn removed_precompiles() { | |
| }) | ||
| } | ||
|
|
||
| #[test] | ||
| fn base_fee_should_default_to_associate_type_value() { | ||
| ExtBuilder::default().build().execute_with(|| { | ||
| let (base_fee, _) = | ||
| <moonbeam_runtime::Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price(); | ||
| assert_eq!(base_fee, (1 * GIGAWEI * SUPPLY_FACTOR).into()); | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn evm_revert_substrate_events() { | ||
| ExtBuilder::default() | ||
|
|
@@ -2907,7 +2941,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(), | ||
|
|
@@ -2946,7 +2980,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(), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.