diff --git a/nimbus/p2p/executor/process_transaction.nim b/nimbus/p2p/executor/process_transaction.nim index 356a66158..eb6141d42 100644 --- a/nimbus/p2p/executor/process_transaction.nim +++ b/nimbus/p2p/executor/process_transaction.nim @@ -13,6 +13,7 @@ import ../../db/accounts_cache, ../../forks, ../../transaction/call_evm, + ../../transaction, ../../vm_state, ../../vm_types, ../validate, @@ -27,12 +28,6 @@ import # Private functions # ------------------------------------------------------------------------------ -proc eip1559TxNormalization(tx: Transaction): Transaction = - result = tx - if tx.txType < TxEip1559: - result.maxPriorityFee = tx.gasPrice - result.maxFee = tx.gasPrice - proc eip1559BaseFee(header: BlockHeader; fork: Fork): UInt256 = ## Actually, `baseFee` should be 0 for pre-London headers already. But this ## function just plays safe. In particular, the `test_general_state_json.nim` @@ -54,18 +49,13 @@ proc processTransactionImpl( #trace "Sender", sender #trace "txHash", rlpHash = ty.rlpHash - var - tx = eip1559TxNormalization(tx) let roDB = vmState.readOnlyStateDB baseFee256 = header.eip1559BaseFee(fork) - baseFee = baseFee256.truncate(int64) + baseFee = baseFee256.truncate(GasInt) + tx = eip1559TxNormalization(tx, baseFee, fork) priorityFee = min(tx.maxPriorityFee, tx.maxFee - baseFee) miner = vmState.coinbase() - if FkLondon <= fork: - # The signer pays both the priority fee and the base fee. So tx.gasPrice - # now is the effective gasPrice which also effects the `stateRoot` value. - tx.gasPrice = priorityFee + baseFee # Return failure unless explicitely set `ok()` result = err() diff --git a/nimbus/transaction.nim b/nimbus/transaction.nim index 19eff2058..add01f335 100644 --- a/nimbus/transaction.nim +++ b/nimbus/transaction.nim @@ -153,3 +153,15 @@ proc signTransaction*(tx: Transaction, privateKey: PrivateKey, chainId: ChainId, result.R = Uint256.fromBytesBE(sig[0..31]) result.S = Uint256.fromBytesBE(sig[32..63]) + +func eip1559TxNormalization*(tx: Transaction; + baseFee: GasInt; fork: Fork): Transaction = + ## This function adjusts a legacy transaction to EIP-1559 standard. This + ## is needed particularly when using the `validateTransaction()` utility + ## with legacy transactions. + result = tx + if tx.txType < TxEip1559: + result.maxPriorityFee = tx.gasPrice + result.maxFee = tx.gasPrice + if FkLondon <= fork: + result.gasPrice = baseFee + min(result.maxPriorityFee, result.maxFee - baseFee) diff --git a/nimbus/utils/tx_pool/tx_tasks/tx_classify.nim b/nimbus/utils/tx_pool/tx_tasks/tx_classify.nim index 119bba383..4f398cecf 100644 --- a/nimbus/utils/tx_pool/tx_tasks/tx_classify.nim +++ b/nimbus/utils/tx_pool/tx_tasks/tx_classify.nim @@ -173,22 +173,6 @@ proc txPostLondonAcceptableTipAndFees(xp: TxPoolRef; item: TxItemRef): bool = return false true -# ------------------------------------------------------------------------------ -# Public helper function, needed here and in the packer -# ------------------------------------------------------------------------------ - -func eip1559TxNormalization*(tx: Transaction; - baseFee: GasPrice; fork: Fork): Transaction = - ## This function adjusts a legacy transaction to EIP-1559 standard. This - ## is needed particularly when using the `validateTransaction()` utility - ## with legacy transactions. - result = tx - if tx.txType < TxEip1559: - result.maxPriorityFee = tx.gasPrice - result.maxFee = tx.gasPrice - if FkLondon <= fork: - result.gasPrice = min(result.maxPriorityFee + baseFee.int64, result.maxFee) - # ------------------------------------------------------------------------------ # Public functionss # ------------------------------------------------------------------------------ @@ -248,7 +232,7 @@ proc classifyValidatePacked*(xp: TxPoolRef; xp.chain.limits.maxLimit else: xp.chain.limits.trgLimit - tx = item.tx.eip1559TxNormalization(xp.chain.baseFee, fork) + tx = item.tx.eip1559TxNormalization(xp.chain.baseFee.GasInt, fork) roDB.validateTransaction(tx, item.sender, gasLimit, baseFee, fork) diff --git a/nimbus/utils/tx_pool/tx_tasks/tx_packer.nim b/nimbus/utils/tx_pool/tx_tasks/tx_packer.nim index 2d6485a0c..a4fe82d06 100644 --- a/nimbus/utils/tx_pool/tx_tasks/tx_packer.nim +++ b/nimbus/utils/tx_pool/tx_tasks/tx_packer.nim @@ -18,6 +18,7 @@ import ../../../forks, ../../../p2p/[dao, executor, validate], ../../../transaction/call_evm, + ../../../transaction, ../../../vm_state, ../../../vm_types, ../tx_chain, @@ -84,7 +85,7 @@ proc runTx(pst: TxPackerStateRef; item: TxItemRef): GasInt let fork = pst.xp.chain.nextFork baseFee = pst.xp.chain.baseFee - tx = item.tx.eip1559TxNormalization(baseFee, fork) + tx = item.tx.eip1559TxNormalization(baseFee.GasInt, fork) safeExecutor "tx_packer.runTx": # Execute transaction, may return a wildcard `Exception`