From 47605dbdf3d4d86f6779b8f49e5ca0aae6589adc Mon Sep 17 00:00:00 2001 From: andri lim Date: Wed, 24 Apr 2024 07:50:50 +0700 Subject: [PATCH] Fix txPool: excessBlobGas should be calculated before entering EVM, not after (#2149) --- nimbus/beacon/api_handler/api_newpayload.nim | 4 ++-- nimbus/core/tx_pool/tx_chain.nim | 14 ++++++++------ nimbus/core/tx_pool/tx_tasks/tx_packer.nim | 3 +-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/nimbus/beacon/api_handler/api_newpayload.nim b/nimbus/beacon/api_handler/api_newpayload.nim index ccbcbbc16..c3045c704 100644 --- a/nimbus/beacon/api_handler/api_newpayload.nim +++ b/nimbus/beacon/api_handler/api_newpayload.nim @@ -116,9 +116,9 @@ proc newPayload*(ben: BeaconEngineRef, timestamp = ethTime payload.timestamp version = payload.version - validateVersion(com, timestamp, version, apiVersion) validatePayload(apiVersion, version, payload) - + validateVersion(com, timestamp, version, apiVersion) + var header = blockHeader(payload, removeBlobs = true, beaconRoot = ethHash beaconRoot) if apiVersion >= Version.V3: diff --git a/nimbus/core/tx_pool/tx_chain.nim b/nimbus/core/tx_pool/tx_chain.nim index f8b95507c..18d442dea 100644 --- a/nimbus/core/tx_pool/tx_chain.nim +++ b/nimbus/core/tx_pool/tx_chain.nim @@ -19,6 +19,7 @@ import ../../utils/utils, ../../vm_state, ../../vm_types, + ../eip4844, ../clique/[clique_sealer, clique_desc, clique_cfg], ../pow/difficulty, ../executor, @@ -131,12 +132,13 @@ proc resetTxEnv(dh: TxChainRef; parent: BlockHeader; fee: Option[UInt256]) # we don't consider PoS difficulty here # because that is handled in vmState let blockCtx = BlockContext( - timestamp : dh.prepHeader.timestamp, - gasLimit : (if dh.maxMode: dh.limits.maxLimit else: dh.limits.trgLimit), - fee : fee, - prevRandao: dh.prepHeader.prevRandao, - difficulty: dh.prepHeader.difficulty, - coinbase : dh.feeRecipient, + timestamp : dh.prepHeader.timestamp, + gasLimit : (if dh.maxMode: dh.limits.maxLimit else: dh.limits.trgLimit), + fee : fee, + prevRandao : dh.prepHeader.prevRandao, + difficulty : dh.prepHeader.difficulty, + coinbase : dh.feeRecipient, + excessBlobGas: calcExcessBlobGas(parent), ) dh.txEnv.vmState = BaseVMState.new( diff --git a/nimbus/core/tx_pool/tx_tasks/tx_packer.nim b/nimbus/core/tx_pool/tx_tasks/tx_packer.nim index 090760968..25df1d0aa 100644 --- a/nimbus/core/tx_pool/tx_tasks/tx_packer.nim +++ b/nimbus/core/tx_pool/tx_tasks/tx_packer.nim @@ -275,8 +275,7 @@ proc vmExecCommit(pst: TxPackerStateRef) if vmState.com.forkGTE(Cancun): # EIP-4844 - let excessBlobGas = calcExcessBlobGas(vmState.parent) - xp.chain.excessBlobGas = some(excessBlobGas) + xp.chain.excessBlobGas = some(vmState.blockCtx.excessBlobGas) xp.chain.blobGasUsed = some(pst.blobGasUsed) proc balanceDelta: UInt256 =