core,miner,params: implement EIP-7934 - RLP Execution Block Size Limit

This commit is contained in:
Jared Wasinger 2025-06-09 13:41:48 +02:00 committed by Felix Lange
parent b3131f00a3
commit d11ef8b624
4 changed files with 21 additions and 0 deletions

View file

@ -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 // header's transaction and uncle roots. The headers are assumed to be already
// validated at this point. // validated at this point.
func (v *BlockValidator) ValidateBody(block *types.Block) error { 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. // Check whether the block is already imported.
if v.bc.HasBlockAndState(block.Hash(), block.NumberU64()) { if v.bc.HasBlockAndState(block.Hash(), block.NumberU64()) {
return ErrKnownBlock return ErrKnownBlock

View file

@ -28,6 +28,10 @@ var (
// ErrNoGenesis is returned when there is no Genesis Block. // ErrNoGenesis is returned when there is no Genesis Block.
ErrNoGenesis = errors.New("genesis not found in chain") 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 // List of evm-call-message pre-checking errors. All state transition messages will

View file

@ -19,6 +19,7 @@ package miner
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/trie"
"math/big" "math/big"
"sync/atomic" "sync/atomic"
"time" "time"
@ -94,6 +95,13 @@ type generateParams struct {
noTxs bool // Flag whether an empty block without any transaction is expected 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. // generateWork generates a sealing block based on the given parameters.
func (miner *Miner) generateWork(params *generateParams, witness bool) *newPayloadResult { func (miner *Miner) generateWork(params *generateParams, witness bool) *newPayloadResult {
work, err := miner.prepareWork(params, witness) work, err := miner.prepareWork(params, witness)
@ -391,6 +399,10 @@ func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *tran
continue 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 // Make sure all transactions after osaka have cell proofs
if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) { if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) {
if sidecar := tx.BlobTxSidecar(); sidecar != nil { if sidecar := tx.BlobTxSidecar(); sidecar != nil {

View file

@ -178,6 +178,8 @@ const (
BlobBaseCost = 1 << 13 // Base execution gas cost for a blob. BlobBaseCost = 1 << 13 // Base execution gas cost for a blob.
HistoryServeWindow = 8192 // Number of blocks to serve historical block hashes for, EIP-2935. 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 // Bls12381G1MultiExpDiscountTable is the gas discount table for BLS12-381 G1 multi exponentiation operation