From 1302578c6c102daa884db5324b8e787ce94e3365 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 9 Jun 2025 13:41:48 +0200 Subject: [PATCH 01/16] core,miner,params: implement EIP-7934 - RLP Execution Block Size Limit --- core/block_validator.go | 3 +++ core/error.go | 4 ++++ miner/worker.go | 12 ++++++++++++ params/protocol_params.go | 2 ++ 4 files changed, 21 insertions(+) diff --git a/core/block_validator.go b/core/block_validator.go index 591e472bc1b0..a25fb7e69e37 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -49,6 +49,9 @@ func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain) *Bloc // header's transaction and uncle roots. The headers are assumed to be already // validated at this point. func (v *BlockValidator) ValidateBody(block *types.Block) error { + if v.config.IsOsaka(block.Number(), block.Time()) && block.Size() > params.BlockRLPSizeCap { + return ErrBlockOversized + } // Check whether the block is already imported. if v.bc.HasBlockAndState(block.Hash(), block.NumberU64()) { return ErrKnownBlock diff --git a/core/error.go b/core/error.go index de95e6463620..e50780bf1b48 100644 --- a/core/error.go +++ b/core/error.go @@ -28,6 +28,10 @@ var ( // ErrNoGenesis is returned when there is no Genesis Block. ErrNoGenesis = errors.New("genesis not found in chain") + + // ErrBlockOversized is returned if the size of the RLP-encoded block + // exceeds the cap established by EIP 7934 + ErrBlockOversized = errors.New("block RLP-encoded size exceeds maximum") ) // List of evm-call-message pre-checking errors. All state transition messages will diff --git a/miner/worker.go b/miner/worker.go index 198745ad2785..09cd94aa4650 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -19,6 +19,7 @@ package miner import ( "errors" "fmt" + "github.com/ethereum/go-ethereum/trie" "math/big" "sync/atomic" "time" @@ -94,6 +95,13 @@ type generateParams struct { noTxs bool // Flag whether an empty block without any transaction is expected } +func (env *environment) encodedSizeWithTxAndReceipt(tx *types.Transaction) uint64 { + body := types.Body{Transactions: append(env.txs, tx), Withdrawals: make([]*types.Withdrawal, 0)} + env.header.RequestsHash = &common.Hash{} + block := types.NewBlock(env.header, &body, env.receipts, trie.NewStackTrie(nil)) + return block.Size() +} + // generateWork generates a sealing block based on the given parameters. func (miner *Miner) generateWork(params *generateParams, witness bool) *newPayloadResult { work, err := miner.prepareWork(params, witness) @@ -391,6 +399,10 @@ func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *tran continue } + if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) && env.encodedSizeWithTxAndReceipt(tx) > params.BlockRLPSizeCap { + break + } + // Make sure all transactions after osaka have cell proofs if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) { if sidecar := tx.BlobTxSidecar(); sidecar != nil { diff --git a/params/protocol_params.go b/params/protocol_params.go index 6b06dadaef17..f6114ca2b54c 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -175,6 +175,8 @@ const ( BlobTxPointEvaluationPrecompileGas = 50000 // Gas price for the point evaluation precompile. HistoryServeWindow = 8192 // Number of blocks to serve historical block hashes for, EIP-2935. + + BlockRLPSizeCap = 9_961_472 // maximum size of an RLP-encoded block ) // Bls12381G1MultiExpDiscountTable is the gas discount table for BLS12-381 G1 multi exponentiation operation From c690d88810f0aeed13afc042881861e9dff068f2 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 9 Jun 2025 13:47:58 +0200 Subject: [PATCH 02/16] rename func --- miner/worker.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index 09cd94aa4650..16a3b9e81a7e 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -95,7 +95,7 @@ type generateParams struct { noTxs bool // Flag whether an empty block without any transaction is expected } -func (env *environment) encodedSizeWithTxAndReceipt(tx *types.Transaction) uint64 { +func (env *environment) encodedSizeWithTx(tx *types.Transaction) uint64 { body := types.Body{Transactions: append(env.txs, tx), Withdrawals: make([]*types.Withdrawal, 0)} env.header.RequestsHash = &common.Hash{} block := types.NewBlock(env.header, &body, env.receipts, trie.NewStackTrie(nil)) @@ -399,7 +399,7 @@ func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *tran continue } - if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) && env.encodedSizeWithTxAndReceipt(tx) > params.BlockRLPSizeCap { + if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) && env.encodedSizeWithTx(tx) > params.BlockRLPSizeCap { break } From 3a68e26a602f838f50b9e150b7dc2e7cbf298082 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 9 Jun 2025 13:54:10 +0200 Subject: [PATCH 03/16] goimports --- miner/worker.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/miner/worker.go b/miner/worker.go index 16a3b9e81a7e..6e1a7fe3051f 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -19,11 +19,12 @@ package miner import ( "errors" "fmt" - "github.com/ethereum/go-ethereum/trie" "math/big" "sync/atomic" "time" + "github.com/ethereum/go-ethereum/trie" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus/misc/eip1559" "github.com/ethereum/go-ethereum/consensus/misc/eip4844" From d91afe4d35ace5f56932456bd76253fece79c6a4 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 9 Jun 2025 15:31:15 +0200 Subject: [PATCH 04/16] simplification --- miner/worker.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/miner/worker.go b/miner/worker.go index 6e1a7fe3051f..87b6f9d734da 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -52,6 +52,7 @@ type environment struct { signer types.Signer state *state.StateDB // apply state changes here tcount int // tx count in cycle + size uint64 // size of the block we are building gasPool *core.GasPool // available gas used to pack transactions coinbase common.Address evm *vm.EVM @@ -265,6 +266,7 @@ func (miner *Miner) makeEnv(parent *types.Header, header *types.Header, coinbase return &environment{ signer: types.MakeSigner(miner.chainConfig, header.Number, header.Time), state: state, + size: uint64(header.Size()), coinbase: coinbase, header: header, witness: state.Witness(), @@ -282,6 +284,7 @@ func (miner *Miner) commitTransaction(env *environment, tx *types.Transaction) e } env.txs = append(env.txs, tx) env.receipts = append(env.receipts, receipt) + env.size += tx.Size() env.tcount++ return nil } @@ -400,6 +403,10 @@ func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *tran continue } + if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) && env.size+tx.Size() > params.BlockRLPSizeCap { + break + } + if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) && env.encodedSizeWithTx(tx) > params.BlockRLPSizeCap { break } From abf77074c3696463273ccf1d844976e43985eb48 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 9 Jun 2025 15:32:09 +0200 Subject: [PATCH 05/16] remove outdated change --- core/error.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/error.go b/core/error.go index e50780bf1b48..de95e6463620 100644 --- a/core/error.go +++ b/core/error.go @@ -28,10 +28,6 @@ var ( // ErrNoGenesis is returned when there is no Genesis Block. ErrNoGenesis = errors.New("genesis not found in chain") - - // ErrBlockOversized is returned if the size of the RLP-encoded block - // exceeds the cap established by EIP 7934 - ErrBlockOversized = errors.New("block RLP-encoded size exceeds maximum") ) // List of evm-call-message pre-checking errors. All state transition messages will From b92396bb49ae94e324e060f365e39f71ff47f9c3 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 9 Jun 2025 15:33:35 +0200 Subject: [PATCH 06/16] more updates --- miner/worker.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index 87b6f9d734da..506e8960fd8b 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -23,8 +23,6 @@ import ( "sync/atomic" "time" - "github.com/ethereum/go-ethereum/trie" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus/misc/eip1559" "github.com/ethereum/go-ethereum/consensus/misc/eip4844" @@ -97,13 +95,6 @@ type generateParams struct { noTxs bool // Flag whether an empty block without any transaction is expected } -func (env *environment) encodedSizeWithTx(tx *types.Transaction) uint64 { - body := types.Body{Transactions: append(env.txs, tx), Withdrawals: make([]*types.Withdrawal, 0)} - env.header.RequestsHash = &common.Hash{} - block := types.NewBlock(env.header, &body, env.receipts, trie.NewStackTrie(nil)) - return block.Size() -} - // generateWork generates a sealing block based on the given parameters. func (miner *Miner) generateWork(params *generateParams, witness bool) *newPayloadResult { work, err := miner.prepareWork(params, witness) @@ -407,10 +398,6 @@ func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *tran break } - if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) && env.encodedSizeWithTx(tx) > params.BlockRLPSizeCap { - break - } - // Make sure all transactions after osaka have cell proofs if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) { if sidecar := tx.BlobTxSidecar(); sidecar != nil { From 5f12e63e2847b246dcf62713196577937778e109 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 9 Jun 2025 15:38:32 +0200 Subject: [PATCH 07/16] add back some changes that were deleted --- core/error.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/error.go b/core/error.go index de95e6463620..e50780bf1b48 100644 --- a/core/error.go +++ b/core/error.go @@ -28,6 +28,10 @@ var ( // ErrNoGenesis is returned when there is no Genesis Block. ErrNoGenesis = errors.New("genesis not found in chain") + + // ErrBlockOversized is returned if the size of the RLP-encoded block + // exceeds the cap established by EIP 7934 + ErrBlockOversized = errors.New("block RLP-encoded size exceeds maximum") ) // List of evm-call-message pre-checking errors. All state transition messages will From 2bb5c3451e60898429a31a16d19ab0dc769bb906 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 9 Jun 2025 18:21:28 +0200 Subject: [PATCH 08/16] fix withdrawal inclusion --- miner/worker.go | 30 ++++++++++++++++++++++++++---- params/protocol_params.go | 1 + 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index 506e8960fd8b..118931135e2b 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -96,12 +96,12 @@ type generateParams struct { } // generateWork generates a sealing block based on the given parameters. -func (miner *Miner) generateWork(params *generateParams, witness bool) *newPayloadResult { - work, err := miner.prepareWork(params, witness) +func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPayloadResult { + work, err := miner.prepareWork(genParam, witness) if err != nil { return &newPayloadResult{err: err} } - if !params.noTxs { + if !genParam.noTxs { interrupt := new(atomic.Int32) timer := time.AfterFunc(miner.config.Recommit, func() { interrupt.Store(commitInterruptTimeout) @@ -114,7 +114,29 @@ func (miner *Miner) generateWork(params *generateParams, witness bool) *newPaylo } } - body := types.Body{Transactions: work.txs, Withdrawals: params.withdrawals} + body := types.Body{Transactions: work.txs} + + var includedWithdrawals types.Withdrawals + if miner.chainConfig.IsOsaka(work.header.Number, work.header.Time) { + // cap the size of blocks we will produce below the cap allowed by + // EIP-7934. This gives us buffer room if the estimated size of the + // block we are building is somewhat off. + maxBlockSize := params.BlockRLPSizeCap - 1_000_000 + + for _, withdrawal := range genParam.withdrawals { + if int(work.size)+params.WithdrawalSize > maxBlockSize { + break + } + + includedWithdrawals = append(includedWithdrawals, withdrawal) + work.size += params.WithdrawalSize + } + + } else { + includedWithdrawals = genParam.withdrawals + } + body.Withdrawals = includedWithdrawals + allLogs := make([]*types.Log, 0) for _, r := range work.receipts { allLogs = append(allLogs, r.Logs...) diff --git a/params/protocol_params.go b/params/protocol_params.go index f6114ca2b54c..f5da6a7df4b9 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -176,6 +176,7 @@ const ( HistoryServeWindow = 8192 // Number of blocks to serve historical block hashes for, EIP-2935. + WithdrawalSize = 23 // size of a withdrawal BlockRLPSizeCap = 9_961_472 // maximum size of an RLP-encoded block ) From 80f88d77ca550003f124f489b7b9a039a44e72f4 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 9 Jun 2025 18:25:09 +0200 Subject: [PATCH 09/16] fix lint --- miner/worker.go | 1 - 1 file changed, 1 deletion(-) diff --git a/miner/worker.go b/miner/worker.go index 118931135e2b..8f476f258f77 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -131,7 +131,6 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay includedWithdrawals = append(includedWithdrawals, withdrawal) work.size += params.WithdrawalSize } - } else { includedWithdrawals = genParam.withdrawals } From 98c9efe33768b8eb0348825fe224148cc7e503ea Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 9 Jun 2025 19:52:04 +0200 Subject: [PATCH 10/16] add comment for size check in body validation --- core/block_validator.go | 1 + miner/worker.go | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/core/block_validator.go b/core/block_validator.go index a25fb7e69e37..d4b76e02f810 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -49,6 +49,7 @@ func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain) *Bloc // header's transaction and uncle roots. The headers are assumed to be already // validated at this point. func (v *BlockValidator) ValidateBody(block *types.Block) error { + // check EIP 7934 RLP-encoded block size cap if v.config.IsOsaka(block.Number(), block.Time()) && block.Size() > params.BlockRLPSizeCap { return ErrBlockOversized } diff --git a/miner/worker.go b/miner/worker.go index 8f476f258f77..86eec6310983 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -127,7 +127,6 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay if int(work.size)+params.WithdrawalSize > maxBlockSize { break } - includedWithdrawals = append(includedWithdrawals, withdrawal) work.size += params.WithdrawalSize } From 66cf1f7ebaaf8ce2625d4f8c9f410cb121c21320 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 9 Jun 2025 20:00:10 +0200 Subject: [PATCH 11/16] make sure that we respect the buffer when adding transactions. comments and constant deduplication. --- miner/worker.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index 86eec6310983..1af174b465bf 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -69,6 +69,11 @@ const ( commitInterruptNewHead commitInterruptResubmit commitInterruptTimeout + + // cap the size of blocks we will produce below the max allowed by + // EIP-7934. This gives us buffer room if the estimated size of the + // block we are building is off from the actual encoded size. + blockRLPSizeCapBuffer = 1_000_000 ) // newPayloadResult is the result of payload generation. @@ -118,10 +123,7 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay var includedWithdrawals types.Withdrawals if miner.chainConfig.IsOsaka(work.header.Number, work.header.Time) { - // cap the size of blocks we will produce below the cap allowed by - // EIP-7934. This gives us buffer room if the estimated size of the - // block we are building is somewhat off. - maxBlockSize := params.BlockRLPSizeCap - 1_000_000 + maxBlockSize := params.BlockRLPSizeCap - blockRLPSizeCapBuffer for _, withdrawal := range genParam.withdrawals { if int(work.size)+params.WithdrawalSize > maxBlockSize { @@ -414,7 +416,9 @@ func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *tran continue } - if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) && env.size+tx.Size() > params.BlockRLPSizeCap { + // if inclusion of the transaction would put the block size over the + // maximum we allow, don't add any more txs to the payload. + if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) && env.size+tx.Size() > params.BlockRLPSizeCap-blockRLPSizeCapBuffer { break } From 4267de51efe725447adc209d4f7fd6079a2ee548 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 10 Jun 2025 15:20:11 +0200 Subject: [PATCH 12/16] ensure that all requested withdrawals are included in the block even if we would hit the size cap when filling it with txs --- miner/worker.go | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index 1af174b465bf..d945752f7466 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -106,22 +106,16 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay if err != nil { return &newPayloadResult{err: err} } - if !genParam.noTxs { - interrupt := new(atomic.Int32) - timer := time.AfterFunc(miner.config.Recommit, func() { - interrupt.Store(commitInterruptTimeout) - }) - defer timer.Stop() - - err := miner.fillTransactions(interrupt, work) - if errors.Is(err, errBlockInterruptedByTimeout) { - log.Warn("Block building is interrupted", "allowance", common.PrettyDuration(miner.config.Recommit)) - } - } - - body := types.Body{Transactions: work.txs} - var includedWithdrawals types.Withdrawals + + // If we are post-osaka, incorporate the requested withdrawals into the + // block size up-front to ensure that all requested withdrawals can be + // included even if we hit the size cap when filling the block with txs. + // + // Also, ensure that including all requested withdrawals wouldn't bring us + // over the block size cap limit. The withdrawal cap ensures that this can't + // actually happen right now, but it doesn't hurt to make this code + // future-proof for a situation where the withdrawal cap is lifted. if miner.chainConfig.IsOsaka(work.header.Number, work.header.Time) { maxBlockSize := params.BlockRLPSizeCap - blockRLPSizeCapBuffer @@ -129,13 +123,26 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay if int(work.size)+params.WithdrawalSize > maxBlockSize { break } - includedWithdrawals = append(includedWithdrawals, withdrawal) work.size += params.WithdrawalSize + includedWithdrawals = append(includedWithdrawals, withdrawal) } } else { includedWithdrawals = genParam.withdrawals } - body.Withdrawals = includedWithdrawals + + if !genParam.noTxs { + interrupt := new(atomic.Int32) + timer := time.AfterFunc(miner.config.Recommit, func() { + interrupt.Store(commitInterruptTimeout) + }) + defer timer.Stop() + + err := miner.fillTransactions(interrupt, work) + if errors.Is(err, errBlockInterruptedByTimeout) { + log.Warn("Block building is interrupted", "allowance", common.PrettyDuration(miner.config.Recommit)) + } + } + body := types.Body{Transactions: work.txs, Withdrawals: includedWithdrawals} allLogs := make([]*types.Log, 0) for _, r := range work.receipts { From 669986b5bfdc7d2a6e07b1c6a2e2e46612aae1d9 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 10 Jun 2025 15:30:15 +0200 Subject: [PATCH 13/16] comment phrasing --- miner/worker.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index d945752f7466..0e0dcf0c8d71 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -109,8 +109,9 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay var includedWithdrawals types.Withdrawals // If we are post-osaka, incorporate the requested withdrawals into the - // block size up-front to ensure that all requested withdrawals can be - // included even if we hit the size cap when filling the block with txs. + // block size calculation up-front to ensure that all requested withdrawals + // can be included even if we hit the size cap when filling the block with + // txs. // // Also, ensure that including all requested withdrawals wouldn't bring us // over the block size cap limit. The withdrawal cap ensures that this can't From e43cb0a8da7c5d4fc60af743defeb1fc04338819 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Wed, 11 Jun 2025 18:06:16 +0200 Subject: [PATCH 14/16] consider tx without sidecar when accounting for the size it will contribute to the RLP-encoded block --- miner/worker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miner/worker.go b/miner/worker.go index 0e0dcf0c8d71..6b714364d6ba 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -305,7 +305,7 @@ func (miner *Miner) commitTransaction(env *environment, tx *types.Transaction) e } env.txs = append(env.txs, tx) env.receipts = append(env.receipts, receipt) - env.size += tx.Size() + env.size += tx.WithoutBlobTxSidecar().Size() env.tcount++ return nil } From 71a9b4e149188b9ce1b0e4aedbcd4c83f982fffd Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Wed, 11 Jun 2025 18:12:41 +0200 Subject: [PATCH 15/16] don't calculate the current fork for every transaction that we attempt to add when creating a block --- miner/worker.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index 6b714364d6ba..e691307d21b9 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -351,7 +351,11 @@ func (miner *Miner) applyTransaction(env *environment, tx *types.Transaction) (* } func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *transactionsByPriceAndNonce, interrupt *atomic.Int32) error { - gasLimit := env.header.GasLimit + var ( + isOsaka = miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) + isCancun = miner.chainConfig.IsCancun(env.header.Number, env.header.Time) + gasLimit = env.header.GasLimit + ) if env.gasPool == nil { env.gasPool = new(core.GasPool).AddGas(gasLimit) } @@ -407,7 +411,7 @@ func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *tran // Most of the blob gas logic here is agnostic as to if the chain supports // blobs or not, however the max check panics when called on a chain without // a defined schedule, so we need to verify it's safe to call. - if miner.chainConfig.IsCancun(env.header.Number, env.header.Time) { + if isCancun { left := eip4844.MaxBlobsPerBlock(miner.chainConfig, env.header.Time) - env.blobs if left < int(ltx.BlobGas/params.BlobTxBlobGasPerBlob) { log.Trace("Not enough blob space left for transaction", "hash", ltx.Hash, "left", left, "needed", ltx.BlobGas/params.BlobTxBlobGasPerBlob) @@ -426,12 +430,12 @@ func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *tran // if inclusion of the transaction would put the block size over the // maximum we allow, don't add any more txs to the payload. - if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) && env.size+tx.Size() > params.BlockRLPSizeCap-blockRLPSizeCapBuffer { + if isOsaka && env.size+tx.Size() > params.BlockRLPSizeCap-blockRLPSizeCapBuffer { break } // Make sure all transactions after osaka have cell proofs - if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) { + if isOsaka { if sidecar := tx.BlobTxSidecar(); sidecar != nil { if sidecar.Version == 0 { log.Info("Including blob tx with v0 sidecar, recomputing proofs", "hash", ltx.Hash) From 627133dbd30e5ef954a016391ca3d33cd0e75605 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Thu, 12 Jun 2025 13:18:52 +0200 Subject: [PATCH 16/16] correctly incorporate blob transaction size --- miner/worker.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/miner/worker.go b/miner/worker.go index e691307d21b9..780ad419bd9b 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -305,7 +305,7 @@ func (miner *Miner) commitTransaction(env *environment, tx *types.Transaction) e } env.txs = append(env.txs, tx) env.receipts = append(env.receipts, receipt) - env.size += tx.WithoutBlobTxSidecar().Size() + env.size += tx.Size() env.tcount++ return nil } @@ -331,6 +331,7 @@ func (miner *Miner) commitBlobTransaction(env *environment, tx *types.Transactio env.receipts = append(env.receipts, receipt) env.sidecars = append(env.sidecars, sc) env.blobs += len(sc.Blobs) + env.size += tx.WithoutBlobTxSidecar().Size() *env.header.BlobGasUsed += receipt.BlobGasUsed env.tcount++ return nil