Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions core/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,13 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
}
defer db.Close()
}

// Generate a chain of b.N blocks using the supplied block
// generator function.
gspec := &Genesis{
Alloc: types.GenesisAlloc{benchRootAddr: {Balance: benchRootFunds}},
Config: params.TestChainConfig,
Comment on lines 163 to 165
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params.TestChainConfig now has EIP-1559 enabled from block 0, which means legacy transactions must have a non-nil gas price (and typically >= base fee). The benchmark generators used by benchInsertChain (e.g. genValueTx and genTxRing) still create legacy txs with gasPrice == nil, which will panic when tx.GasPrice() is evaluated during block processing.

Update the benchmark generators to always set a concrete gas price (e.g. use gen.BaseFee() with a fallback to params.InitialBaseFee) so the benchmarks run under the updated test chain config.

Suggested change
gspec := &Genesis{
Alloc: types.GenesisAlloc{benchRootAddr: {Balance: benchRootFunds}},
Config: params.TestChainConfig,
cfg := *params.TestChainConfig
cfg.LondonBlock = nil
gspec := &Genesis{
Alloc: types.GenesisAlloc{benchRootAddr: {Balance: benchRootFunds}},
Config: &cfg,

Copilot uses AI. Check for mistakes.
}
genesis := gspec.MustCommit(db)
chain, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, b.N, gen)
_, chain, _ := GenerateChainWithGenesis(gspec, ethash.NewFaker(), b.N, gen)

// Time the insertion of the new chain.
// State and blocks are stored in the same DB.
Expand Down
8 changes: 3 additions & 5 deletions core/block_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ import (
func TestHeaderVerification(t *testing.T) {
// Create a simple chain to verify
var (
testdb = rawdb.NewMemoryDatabase()
gspec = &Genesis{Config: params.TestChainConfig}
genesis = gspec.MustCommit(testdb)
blocks, _ = GenerateChain(gspec.Config, genesis, ethash.NewFaker(), testdb, 8, nil)
gspec = &Genesis{Config: params.TestChainConfig}
_, blocks, _ = GenerateChainWithGenesis(gspec, ethash.NewFaker(), 8, nil)
)
headers := make([]*types.Header, len(blocks))
for i, block := range blocks {
headers[i] = block.Header()
}
// Run the header checker for blocks one-by-one, checking for both valid and invalid nonces
chain, err := NewBlockChain(testdb, nil, gspec, ethash.NewFaker(), vm.Config{})
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, ethash.NewFaker(), vm.Config{})
defer chain.Stop()
if err != nil {
t.Fatal(err)
Expand Down
16 changes: 8 additions & 8 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const (
receiptsCacheLimit = 32
maxFutureBlocks = 256
maxTimeFutureBlocks = 30
triesInMemory = 128
TriesInMemory = 128

// BlockChainVersion ensures that an incompatible database forces a resync from scratch.
//
Expand Down Expand Up @@ -900,7 +900,7 @@ func (bc *BlockChain) saveData() {
lendingTriedb = lendingService.GetStateCache().TrieDB()
}
}
for _, offset := range []uint64{0, 1, triesInMemory - 1} {
for _, offset := range []uint64{0, 1, TriesInMemory - 1} {
if number := bc.CurrentBlock().Number.Uint64(); number > offset {
recent := bc.GetBlockByNumber(number - offset)

Expand Down Expand Up @@ -1319,9 +1319,9 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
if lendingService != nil {
lendingService.GetTriegc().Push(lendingRoot, -int64(block.NumberU64()))
}
if current := block.NumberU64(); current > triesInMemory {
if current := block.NumberU64(); current > TriesInMemory {
// Find the next state trie we need to commit
chosen := current - triesInMemory
chosen := current - TriesInMemory
// Only write to disk if we exceeded our memory allowance *and* also have at
// least a given number of tries gapped.
//
Expand All @@ -1338,7 +1338,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
if nodes > limit || imgs > 4*1024*1024 {
bc.triedb.Cap(limit - ethdb.IdealBatchSize)
}
if bc.gcproc > bc.cacheConfig.TrieTimeLimit || chosen > lastWrite+triesInMemory {
if bc.gcproc > bc.cacheConfig.TrieTimeLimit || chosen > lastWrite+TriesInMemory {
// If the header is missing (canonical chain behind), we're reorging a low
// diff sidechain. Suspend committing until this operation is completed.
header := bc.GetHeaderByNumber(chosen)
Expand All @@ -1347,15 +1347,15 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
} else {
// If we're exceeding limits but haven't reached a large enough memory gap,
// warn the user that the system is becoming unstable.
if chosen < lastWrite+triesInMemory && bc.gcproc >= 2*bc.cacheConfig.TrieTimeLimit {
log.Info("State in memory for too long, committing", "time", bc.gcproc, "allowance", bc.cacheConfig.TrieTimeLimit, "optimum", float64(chosen-lastWrite)/triesInMemory)
if chosen < lastWrite+TriesInMemory && bc.gcproc >= 2*bc.cacheConfig.TrieTimeLimit {
log.Info("State in memory for too long, committing", "time", bc.gcproc, "allowance", bc.cacheConfig.TrieTimeLimit, "optimum", float64(chosen-lastWrite)/TriesInMemory)
}
// Flush an entire trie and restart the counters
bc.triedb.Commit(header.Root, true)
lastWrite = chosen
bc.gcproc = 0
if tradingTrieDb != nil && lendingTrieDb != nil {
b := bc.GetBlock(header.Hash(), current-triesInMemory)
b := bc.GetBlock(header.Hash(), current-TriesInMemory)
author, _ := bc.Engine().Author(b.Header())
oldTradingRoot, _ := tradingService.GetTradingStateRoot(b, author)
oldLendingRoot, _ := lendingService.GetLendingStateRoot(b, author)
Expand Down
Loading
Loading