diff --git a/execution_chain/constants.nim b/execution_chain/constants.nim index a6d0d3762..b6759a608 100644 --- a/execution_chain/constants.nim +++ b/execution_chain/constants.nim @@ -107,4 +107,8 @@ const HISTORY_STORAGE_ADDRESS* = address"0x0000F90827F1C53a10cb7A02335B175320002935" WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS* = address"0x00000961Ef480Eb55e80D19ad83579A64c007002" CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS* = address"0x0000BBdDc7CE488642fb579F8B00f3a590007251" + + MAX_BLOCK_SIZE* = 10_485_760 # 10 MiB + SAFETY_MARGIN* = 2_097_152 # 2 MiB + MAX_RLP_BLOCK_SIZE* = MAX_BLOCK_SIZE - SAFETY_MARGIN # End diff --git a/execution_chain/core/executor/process_block.nim b/execution_chain/core/executor/process_block.nim index fe4f4cc99..73737ac8a 100644 --- a/execution_chain/core/executor/process_block.nim +++ b/execution_chain/core/executor/process_block.nim @@ -12,6 +12,7 @@ import ../../common/common, + ../../constants, ../../utils/utils, ../../constants, ../../db/ledger, @@ -118,6 +119,10 @@ proc procBlkPreamble( if blk.transactions.calcTxRoot != header.txRoot: return err("Mismatched txRoot") + if com.isOsakaOrLater(header.timestamp): + if rlp.getEncodedLength(blk) > MAX_RLP_BLOCK_SIZE: + return err("Post-Osaka block exceeded MAX_RLP_BLOCK_SIZE") + if com.isPragueOrLater(header.timestamp): if header.requestsHash.isNone: return err("Post-Prague block header must have requestsHash") diff --git a/execution_chain/core/tx_pool.nim b/execution_chain/core/tx_pool.nim index ac2403cc4..c1f3bd6fd 100644 --- a/execution_chain/core/tx_pool.nim +++ b/execution_chain/core/tx_pool.nim @@ -160,9 +160,13 @@ proc assembleBlock*( blobsBundle = BlobsBundle( wrapperVersion: getWrapperVersion(com, blk.header.timestamp) ) + currentRlpSize = rlp.getEncodedLength(blk.header) + rlp.getEncodedLength(blk.withdrawals) for item in pst.packedTxs: let tx = item.pooledTx + if currentRlpSize > MAX_RLP_BLOCK_SIZE - 7: + break + currentRlpSize = currentRlpSize + rlp.getEncodedLength(tx.tx) blk.txs.add tx.tx if tx.blobsBundle != nil: doAssert(tx.blobsBundle.wrapperVersion == blobsBundle.wrapperVersion)