Fix txPool: Limit number of blobs packed into a block(EIP-4844) (#1839)

This commit is contained in:
andri lim 2023-10-22 15:28:28 +07:00 committed by GitHub
parent 4f6cdab641
commit 91106ec6bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import
../../../db/[accounts_cache, core_db], ../../../db/[accounts_cache, core_db],
../../../common/common, ../../../common/common,
../../../utils/utils, ../../../utils/utils,
../../../constants,
"../.."/[dao, executor, validate, eip4844, casper], "../.."/[dao, executor, validate, eip4844, casper],
../../../transaction/call_evm, ../../../transaction/call_evm,
../../../transaction, ../../../transaction,
@ -39,6 +40,7 @@ type
cleanState: bool cleanState: bool
balance: UInt256 balance: UInt256
blobGasUsed: uint64 blobGasUsed: uint64
numBlobPerBlock: int
const const
receiptsExtensionSize = ##\ receiptsExtensionSize = ##\
@ -172,7 +174,9 @@ proc vmExecInit(xp: TxPoolRef): TxPackerStateRef
TxPackerStateRef( # return value TxPackerStateRef( # return value
xp: xp, xp: xp,
tr: newCoreDbRef(LegacyDbMemory).mptPrune, 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] proc vmExecGrabItem(pst: TxPackerStateRef; item: TxItemRef): Result[bool,void]
{.gcsafe,raises: [CatchableError].} = {.gcsafe,raises: [CatchableError].} =
@ -182,6 +186,11 @@ proc vmExecGrabItem(pst: TxPackerStateRef; item: TxItemRef): Result[bool,void]
xp = pst.xp xp = pst.xp
vmState = xp.chain.vmState 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 # Verify we have enough gas in gasPool
if vmState.gasPool < item.tx.gasLimit: if vmState.gasPool < item.tx.gasLimit:
# skip this transaction and # skip this transaction and