From 91106ec6bfa50247d3350e2e438b41faa4d53952 Mon Sep 17 00:00:00 2001 From: andri lim Date: Sun, 22 Oct 2023 15:28:28 +0700 Subject: [PATCH] Fix txPool: Limit number of blobs packed into a block(EIP-4844) (#1839) --- nimbus/core/tx_pool/tx_tasks/tx_packer.nim | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/nimbus/core/tx_pool/tx_tasks/tx_packer.nim b/nimbus/core/tx_pool/tx_tasks/tx_packer.nim index 101ec8047..549fb0ccf 100644 --- a/nimbus/core/tx_pool/tx_tasks/tx_packer.nim +++ b/nimbus/core/tx_pool/tx_tasks/tx_packer.nim @@ -21,6 +21,7 @@ import ../../../db/[accounts_cache, core_db], ../../../common/common, ../../../utils/utils, + ../../../constants, "../.."/[dao, executor, validate, eip4844, casper], ../../../transaction/call_evm, ../../../transaction, @@ -39,6 +40,7 @@ type cleanState: bool balance: UInt256 blobGasUsed: uint64 + numBlobPerBlock: int const receiptsExtensionSize = ##\ @@ -172,7 +174,9 @@ proc vmExecInit(xp: TxPoolRef): TxPackerStateRef TxPackerStateRef( # return value xp: xp, tr: newCoreDbRef(LegacyDbMemory).mptPrune, - balance: xp.chain.vmState.readOnlyStateDB.getBalance(xp.chain.feeRecipient)) + balance: xp.chain.vmState.readOnlyStateDB.getBalance(xp.chain.feeRecipient), + numBlobPerBlock: 0, + ) proc vmExecGrabItem(pst: TxPackerStateRef; item: TxItemRef): Result[bool,void] {.gcsafe,raises: [CatchableError].} = @@ -182,6 +186,11 @@ proc vmExecGrabItem(pst: TxPackerStateRef; item: TxItemRef): Result[bool,void] xp = pst.xp vmState = xp.chain.vmState + # EIP-4844 + if pst.numBlobPerBlock + item.tx.versionedHashes.len > MAX_BLOBS_PER_BLOCK: + return err() # stop collecting + pst.numBlobPerBlock += item.tx.versionedHashes.len + # Verify we have enough gas in gasPool if vmState.gasPool < item.tx.gasLimit: # skip this transaction and