Skip to content

Commit a6eb14b

Browse files
karalabebuddh0
authored andcommitted
consensus, cmd, core, eth: remove support for non-merge mode of operation (#29169)
* eth: drop support for forward sync triggers and head block packets * consensus, eth: enforce always merged network * eth: fix tx looper startup and shutdown * cmd, core: fix some tests * core: remove notion of future blocks * core, eth: drop unused methods and types
1 parent a7c2b50 commit a6eb14b

24 files changed

+237
-2357
lines changed

cmd/geth/testdata/clique.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"byzantiumBlock": 0,
99
"constantinopleBlock": 0,
1010
"petersburgBlock": 0,
11+
"terminalTotalDifficultyPassed": true,
1112
"clique": {
1213
"period": 5,
1314
"epoch": 30000

consensus/merger.go

-110
This file was deleted.

core/block_validator_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ func testHeaderVerificationForMerging(t *testing.T, isClique bool) {
9494
preBlocks []*types.Block
9595
postBlocks []*types.Block
9696
engine consensus.Engine
97-
merger = consensus.NewMerger(rawdb.NewMemoryDatabase())
9897
)
9998
if isClique {
10099
var (
@@ -186,11 +185,6 @@ func testHeaderVerificationForMerging(t *testing.T, isClique bool) {
186185
}
187186
chain.InsertChain(preBlocks[i : i+1])
188187
}
189-
190-
// Make the transition
191-
merger.ReachTTD()
192-
merger.FinalizePoS()
193-
194188
// Verify the blocks after the merging
195189
for i := 0; i < len(postBlocks); i++ {
196190
_, results := engine.VerifyHeaders(chain, []*types.Header{postHeaders[i]})

core/blockchain.go

+34-73
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import (
5656
"github.com/ethereum/go-ethereum/triedb"
5757
"github.com/ethereum/go-ethereum/triedb/hashdb"
5858
"github.com/ethereum/go-ethereum/triedb/pathdb"
59-
"golang.org/x/exp/slices"
6059
)
6160

6261
var (
@@ -110,6 +109,7 @@ var (
110109
)
111110

112111
const (
112+
<<<<<<< HEAD
113113
bodyCacheLimit = 256
114114
blockCacheLimit = 256
115115
diffLayerCacheLimit = 1024
@@ -127,6 +127,13 @@ const (
127127
maxDiffForkDist = 11 // Maximum allowed backward distance from the chain head
128128

129129
rewindBadBlockInterval = 1 * time.Second
130+
=======
131+
bodyCacheLimit = 256
132+
blockCacheLimit = 256
133+
receiptsCacheLimit = 32
134+
txLookupCacheLimit = 1024
135+
TriesInMemory = 128
136+
>>>>>>> f4d53133f (consensus, cmd, core, eth: remove support for non-merge mode of operation (#29169))
130137

131138
// BlockChainVersion ensures that an incompatible database forces a resync from scratch.
132139
//
@@ -292,6 +299,7 @@ type BlockChain struct {
292299
txLookupCache *lru.Cache[common.Hash, txLookup]
293300
sidecarsCache *lru.Cache[common.Hash, types.BlobSidecars]
294301

302+
<<<<<<< HEAD
295303
// future blocks are blocks added for later processing
296304
futureBlocks *lru.Cache[common.Hash, *types.Block]
297305
// Cache for the blocks that failed to pass MPT root verification
@@ -304,6 +312,8 @@ type BlockChain struct {
304312
diffQueueBuffer chan *types.DiffLayer
305313
diffLayerFreezerBlockLimit uint64
306314

315+
=======
316+
>>>>>>> f4d53133f (consensus, cmd, core, eth: remove support for non-merge mode of operation (#29169))
307317
wg sync.WaitGroup
308318
dbWg sync.WaitGroup
309319
quit chan struct{} // shutdown signal, closed in Stop.
@@ -363,6 +373,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
363373
*/
364374

365375
bc := &BlockChain{
376+
<<<<<<< HEAD
366377
chainConfig: chainConfig,
367378
cacheConfig: cacheConfig,
368379
db: db,
@@ -385,6 +396,22 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
385396
vmConfig: vmConfig,
386397
diffQueue: prque.New[int64, *types.DiffLayer](nil),
387398
diffQueueBuffer: make(chan *types.DiffLayer),
399+
=======
400+
chainConfig: chainConfig,
401+
cacheConfig: cacheConfig,
402+
db: db,
403+
triedb: triedb,
404+
triegc: prque.New[int64, common.Hash](nil),
405+
quit: make(chan struct{}),
406+
chainmu: syncx.NewClosableMutex(),
407+
bodyCache: lru.NewCache[common.Hash, *types.Body](bodyCacheLimit),
408+
bodyRLPCache: lru.NewCache[common.Hash, rlp.RawValue](bodyCacheLimit),
409+
receiptsCache: lru.NewCache[common.Hash, []*types.Receipt](receiptsCacheLimit),
410+
blockCache: lru.NewCache[common.Hash, *types.Block](blockCacheLimit),
411+
txLookupCache: lru.NewCache[common.Hash, txLookup](txLookupCacheLimit),
412+
engine: engine,
413+
vmConfig: vmConfig,
414+
>>>>>>> f4d53133f (consensus, cmd, core, eth: remove support for non-merge mode of operation (#29169))
388415
}
389416
bc.flushInterval.Store(int64(cacheConfig.TrieTimeLimit))
390417
bc.forker = NewForkChoice(bc, shouldPreserve)
@@ -550,6 +577,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
550577
return nil, err
551578
}
552579
}
580+
<<<<<<< HEAD
553581
// Start future block processor.
554582
bc.wg.Add(1)
555583
go bc.updateFutureBlocks()
@@ -570,6 +598,8 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
570598
go bc.startDoubleSignMonitor()
571599
}
572600

601+
=======
602+
>>>>>>> f4d53133f (consensus, cmd, core, eth: remove support for non-merge mode of operation (#29169))
573603
// Rewind the chain in case of an incompatible config upgrade.
574604
if compat, ok := genesisErr.(*params.ConfigCompatError); ok {
575605
log.Warn("Rewinding chain to upgrade configuration", "err", compat)
@@ -1157,7 +1187,6 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha
11571187
bc.sidecarsCache.Purge()
11581188
bc.blockCache.Purge()
11591189
bc.txLookupCache.Purge()
1160-
bc.futureBlocks.Purge()
11611190

11621191
if finalized := bc.CurrentFinalBlock(); finalized != nil && head < finalized.Number.Uint64() {
11631192
log.Error("SetHead invalidated finalized block")
@@ -1445,24 +1474,6 @@ func (bc *BlockChain) insertStopped() bool {
14451474
return bc.procInterrupt.Load()
14461475
}
14471476

1448-
func (bc *BlockChain) procFutureBlocks() {
1449-
blocks := make([]*types.Block, 0, bc.futureBlocks.Len())
1450-
for _, hash := range bc.futureBlocks.Keys() {
1451-
if block, exist := bc.futureBlocks.Peek(hash); exist {
1452-
blocks = append(blocks, block)
1453-
}
1454-
}
1455-
if len(blocks) > 0 {
1456-
slices.SortFunc(blocks, func(a, b *types.Block) int {
1457-
return a.Number().Cmp(b.Number())
1458-
})
1459-
// Insert one by one as chain insertion needs contiguous ancestry between blocks
1460-
for i := range blocks {
1461-
bc.InsertChain(blocks[i : i+1])
1462-
}
1463-
}
1464-
}
1465-
14661477
// WriteStatus status of write
14671478
type WriteStatus byte
14681479

@@ -1959,8 +1970,6 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types
19591970
if status == CanonStatTy {
19601971
bc.writeHeadBlock(block)
19611972
}
1962-
bc.futureBlocks.Remove(block.Hash())
1963-
19641973
if status == CanonStatTy {
19651974
bc.chainFeed.Send(ChainEvent{Block: block, Hash: block.Hash(), Logs: logs})
19661975
if len(logs) > 0 {
@@ -1989,25 +1998,6 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types
19891998
return status, nil
19901999
}
19912000

1992-
// addFutureBlock checks if the block is within the max allowed window to get
1993-
// accepted for future processing, and returns an error if the block is too far
1994-
// ahead and was not added.
1995-
//
1996-
// TODO after the transition, the future block shouldn't be kept. Because
1997-
// it's not checked in the Geth side anymore.
1998-
func (bc *BlockChain) addFutureBlock(block *types.Block) error {
1999-
max := uint64(time.Now().Unix() + maxTimeFutureBlocks)
2000-
if block.Time() > max {
2001-
return fmt.Errorf("future block timestamp %v > allowed %v", block.Time(), max)
2002-
}
2003-
if block.Difficulty().Cmp(common.Big0) == 0 {
2004-
// Never add PoS blocks into the future queue
2005-
return nil
2006-
}
2007-
bc.futureBlocks.Add(block.Hash(), block)
2008-
return nil
2009-
}
2010-
20112001
// InsertChain attempts to insert the given batch of blocks in to the canonical
20122002
// chain or, otherwise, create a fork. If an error is returned it will return
20132003
// the index number of the failing block as well an error describing what went
@@ -2162,26 +2152,10 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
21622152
_, err := bc.recoverAncestors(block)
21632153
return it.index, err
21642154
}
2165-
// First block is future, shove it (and all children) to the future queue (unknown ancestor)
2166-
case errors.Is(err, consensus.ErrFutureBlock) || (errors.Is(err, consensus.ErrUnknownAncestor) && bc.futureBlocks.Contains(it.first().ParentHash())):
2167-
for block != nil && (it.index == 0 || errors.Is(err, consensus.ErrUnknownAncestor)) {
2168-
log.Debug("Future block, postponing import", "number", block.Number(), "hash", block.Hash())
2169-
if err := bc.addFutureBlock(block); err != nil {
2170-
return it.index, err
2171-
}
2172-
block, err = it.next()
2173-
}
2174-
stats.queued += it.processed()
2175-
stats.ignored += it.remaining()
2176-
2177-
// If there are any still remaining, mark as ignored
2178-
return it.index, err
2179-
21802155
// Some other error(except ErrKnownBlock) occurred, abort.
21812156
// ErrKnownBlock is allowed here since some known blocks
21822157
// still need re-execution to generate snapshots that are missing
21832158
case err != nil && !errors.Is(err, ErrKnownBlock):
2184-
bc.futureBlocks.Remove(block.Hash())
21852159
stats.ignored += len(it.chain)
21862160
bc.reportBlock(block, nil, err)
21872161
return it.index, err
@@ -2380,23 +2354,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
23802354
}
23812355
bc.chainBlockFeed.Send(ChainHeadEvent{block})
23822356
}
2383-
2384-
// Any blocks remaining here? The only ones we care about are the future ones
2385-
if block != nil && errors.Is(err, consensus.ErrFutureBlock) {
2386-
if err := bc.addFutureBlock(block); err != nil {
2387-
return it.index, err
2388-
}
2389-
block, err = it.next()
2390-
2391-
for ; block != nil && errors.Is(err, consensus.ErrUnknownAncestor); block, err = it.next() {
2392-
if err := bc.addFutureBlock(block); err != nil {
2393-
return it.index, err
2394-
}
2395-
stats.queued++
2396-
}
2397-
}
23982357
stats.ignored += it.remaining()
2399-
24002358
return it.index, err
24012359
}
24022360

@@ -2875,6 +2833,7 @@ func (bc *BlockChain) SetCanonical(head *types.Block) (common.Hash, error) {
28752833
return head.Hash(), nil
28762834
}
28772835

2836+
<<<<<<< HEAD
28782837
func (bc *BlockChain) updateFutureBlocks() {
28792838
futureTimer := time.NewTicker(5 * time.Second)
28802839
defer futureTimer.Stop()
@@ -3001,6 +2960,8 @@ func (bc *BlockChain) startDoubleSignMonitor() {
30012960
}
30022961
}
30032962

2963+
=======
2964+
>>>>>>> f4d53133f (consensus, cmd, core, eth: remove support for non-merge mode of operation (#29169))
30042965
// skipBlock returns 'true', if the block being imported can be skipped over, meaning
30052966
// that the block does not need to be processed but can be considered already fully 'done'.
30062967
func (bc *BlockChain) skipBlock(err error, it *insertIterator) bool {

core/blockchain_insert.go

-5
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,3 @@ func (it *insertIterator) first() *types.Block {
187187
func (it *insertIterator) remaining() int {
188188
return len(it.chain) - it.index
189189
}
190-
191-
// processed returns the number of processed blocks.
192-
func (it *insertIterator) processed() int {
193-
return it.index + 1
194-
}

0 commit comments

Comments
 (0)