Skip to content

Commit 25a47f5

Browse files
committed
evm: Handle evm gas fee properly
1 parent b2ac04f commit 25a47f5

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

standalone/runtime/src/evm_currency.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use super::{Balances, Runtime, Treasury};
1+
use super::{Authorship, Balances, Runtime, Treasury};
22
use frame_support::traits::{fungible::Inspect, Currency, Imbalance, OnUnbalanced};
33
use node_primitives::{AccountId, Balance};
44
use pallet_balances::{NegativeImbalance, PositiveImbalance};
5+
use pallet_evm::{EVMCurrencyAdapter, OnChargeEVMTransaction};
56

67
pub struct EvmCurrency;
78

@@ -51,6 +52,44 @@ impl OnUnbalanced<NegativeImbalance<Runtime>> for EvmDealWithFees {
5152
}
5253
}
5354

55+
impl OnChargeEVMTransaction<Runtime> for EvmDealWithFees {
56+
type LiquidityInfo = Option<NegativeImbalance<Runtime>>;
57+
58+
fn withdraw_fee(
59+
who: &sp_core::H160,
60+
fee: sp_core::U256,
61+
) -> Result<Self::LiquidityInfo, pallet_evm::Error<Runtime>> {
62+
<EVMCurrencyAdapter<EvmCurrency, Self> as OnChargeEVMTransaction<Runtime>>::withdraw_fee(
63+
who, fee,
64+
)
65+
}
66+
67+
fn correct_and_deposit_fee(
68+
who: &sp_core::H160,
69+
corrected_fee: sp_core::U256,
70+
base_fee: sp_core::U256,
71+
already_withdrawn: Self::LiquidityInfo,
72+
) -> Self::LiquidityInfo {
73+
<EVMCurrencyAdapter<EvmCurrency, Self> as OnChargeEVMTransaction<Runtime>>::correct_and_deposit_fee(
74+
who,
75+
corrected_fee,
76+
base_fee,
77+
already_withdrawn,
78+
)
79+
}
80+
81+
fn pay_priority_fee(tip: Self::LiquidityInfo) {
82+
if let Some(tip) = tip {
83+
match Authorship::author() {
84+
Some(author) => {
85+
let _ = EvmCurrency::deposit_creating(&author, tip.peek());
86+
}
87+
None => Self::on_unbalanced(tip),
88+
}
89+
}
90+
}
91+
}
92+
5493
impl Currency<AccountId> for EvmCurrency {
5594
type Balance = Balance;
5695

standalone/runtime/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ use pallet_ethereum::{
127127
Call::transact, PostLogContent, Transaction as EthereumTransaction, TransactionAction,
128128
TransactionData,
129129
};
130-
use pallet_evm::{Account as EVMAccount, EVMCurrencyAdapter, FeeCalculator, Runner};
130+
use pallet_evm::{Account as EVMAccount, FeeCalculator, Runner};
131131
use precompiles::FrontierPrecompiles;
132132
mod precompiles;
133133

@@ -1667,7 +1667,7 @@ impl pallet_evm::Config for Runtime {
16671667
type ChainId = EVMChainId;
16681668
type BlockGasLimit = BlockGasLimit;
16691669
type Runner = pallet_evm::runner::stack::Runner<Self>;
1670-
type OnChargeTransaction = EVMCurrencyAdapter<EvmCurrency, EvmDealWithFees>;
1670+
type OnChargeTransaction = EvmDealWithFees;
16711671
type OnCreate = ();
16721672
type FindAuthor = TruncatedTreasuryAsAuthor;
16731673
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;

0 commit comments

Comments
 (0)