Skip to content

Commit f4d5313

Browse files
authored
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 9a0fa80 commit f4d5313

25 files changed

+88
-2990
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

+5-103
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ import (
5050
"github.com/ethereum/go-ethereum/triedb"
5151
"github.com/ethereum/go-ethereum/triedb/hashdb"
5252
"github.com/ethereum/go-ethereum/triedb/pathdb"
53-
"golang.org/x/exp/slices"
5453
)
5554

5655
var (
@@ -97,13 +96,11 @@ var (
9796
)
9897

9998
const (
100-
bodyCacheLimit = 256
101-
blockCacheLimit = 256
102-
receiptsCacheLimit = 32
103-
txLookupCacheLimit = 1024
104-
maxFutureBlocks = 256
105-
maxTimeFutureBlocks = 30
106-
TriesInMemory = 128
99+
bodyCacheLimit = 256
100+
blockCacheLimit = 256
101+
receiptsCacheLimit = 32
102+
txLookupCacheLimit = 1024
103+
TriesInMemory = 128
107104

108105
// BlockChainVersion ensures that an incompatible database forces a resync from scratch.
109106
//
@@ -245,9 +242,6 @@ type BlockChain struct {
245242
blockCache *lru.Cache[common.Hash, *types.Block]
246243
txLookupCache *lru.Cache[common.Hash, txLookup]
247244

248-
// future blocks are blocks added for later processing
249-
futureBlocks *lru.Cache[common.Hash, *types.Block]
250-
251245
wg sync.WaitGroup
252246
quit chan struct{} // shutdown signal, closed in Stop.
253247
stopping atomic.Bool // false if chain is running, true when stopped
@@ -299,7 +293,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
299293
receiptsCache: lru.NewCache[common.Hash, []*types.Receipt](receiptsCacheLimit),
300294
blockCache: lru.NewCache[common.Hash, *types.Block](blockCacheLimit),
301295
txLookupCache: lru.NewCache[common.Hash, txLookup](txLookupCacheLimit),
302-
futureBlocks: lru.NewCache[common.Hash, *types.Block](maxFutureBlocks),
303296
engine: engine,
304297
vmConfig: vmConfig,
305298
}
@@ -449,11 +442,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
449442
}
450443
bc.snaps, _ = snapshot.New(snapconfig, bc.db, bc.triedb, head.Root)
451444
}
452-
453-
// Start future block processor.
454-
bc.wg.Add(1)
455-
go bc.updateFutureBlocks()
456-
457445
// Rewind the chain in case of an incompatible config upgrade.
458446
if compat, ok := genesisErr.(*params.ConfigCompatError); ok {
459447
log.Warn("Rewinding chain to upgrade configuration", "err", compat)
@@ -794,7 +782,6 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha
794782
bc.receiptsCache.Purge()
795783
bc.blockCache.Purge()
796784
bc.txLookupCache.Purge()
797-
bc.futureBlocks.Purge()
798785

799786
// Clear safe block, finalized block if needed
800787
if safe := bc.CurrentSafeBlock(); safe != nil && head < safe.Number.Uint64() {
@@ -1048,24 +1035,6 @@ func (bc *BlockChain) insertStopped() bool {
10481035
return bc.procInterrupt.Load()
10491036
}
10501037

1051-
func (bc *BlockChain) procFutureBlocks() {
1052-
blocks := make([]*types.Block, 0, bc.futureBlocks.Len())
1053-
for _, hash := range bc.futureBlocks.Keys() {
1054-
if block, exist := bc.futureBlocks.Peek(hash); exist {
1055-
blocks = append(blocks, block)
1056-
}
1057-
}
1058-
if len(blocks) > 0 {
1059-
slices.SortFunc(blocks, func(a, b *types.Block) int {
1060-
return a.Number().Cmp(b.Number())
1061-
})
1062-
// Insert one by one as chain insertion needs contiguous ancestry between blocks
1063-
for i := range blocks {
1064-
bc.InsertChain(blocks[i : i+1])
1065-
}
1066-
}
1067-
}
1068-
10691038
// WriteStatus status of write
10701039
type WriteStatus byte
10711040

@@ -1466,8 +1435,6 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types
14661435
if status == CanonStatTy {
14671436
bc.writeHeadBlock(block)
14681437
}
1469-
bc.futureBlocks.Remove(block.Hash())
1470-
14711438
if status == CanonStatTy {
14721439
bc.chainFeed.Send(ChainEvent{Block: block, Hash: block.Hash(), Logs: logs})
14731440
if len(logs) > 0 {
@@ -1487,25 +1454,6 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types
14871454
return status, nil
14881455
}
14891456

1490-
// addFutureBlock checks if the block is within the max allowed window to get
1491-
// accepted for future processing, and returns an error if the block is too far
1492-
// ahead and was not added.
1493-
//
1494-
// TODO after the transition, the future block shouldn't be kept. Because
1495-
// it's not checked in the Geth side anymore.
1496-
func (bc *BlockChain) addFutureBlock(block *types.Block) error {
1497-
max := uint64(time.Now().Unix() + maxTimeFutureBlocks)
1498-
if block.Time() > max {
1499-
return fmt.Errorf("future block timestamp %v > allowed %v", block.Time(), max)
1500-
}
1501-
if block.Difficulty().Cmp(common.Big0) == 0 {
1502-
// Never add PoS blocks into the future queue
1503-
return nil
1504-
}
1505-
bc.futureBlocks.Add(block.Hash(), block)
1506-
return nil
1507-
}
1508-
15091457
// InsertChain attempts to insert the given batch of blocks in to the canonical
15101458
// chain or, otherwise, create a fork. If an error is returned it will return
15111459
// the index number of the failing block as well an error describing what went
@@ -1643,26 +1591,10 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
16431591
_, err := bc.recoverAncestors(block)
16441592
return it.index, err
16451593
}
1646-
// First block is future, shove it (and all children) to the future queue (unknown ancestor)
1647-
case errors.Is(err, consensus.ErrFutureBlock) || (errors.Is(err, consensus.ErrUnknownAncestor) && bc.futureBlocks.Contains(it.first().ParentHash())):
1648-
for block != nil && (it.index == 0 || errors.Is(err, consensus.ErrUnknownAncestor)) {
1649-
log.Debug("Future block, postponing import", "number", block.Number(), "hash", block.Hash())
1650-
if err := bc.addFutureBlock(block); err != nil {
1651-
return it.index, err
1652-
}
1653-
block, err = it.next()
1654-
}
1655-
stats.queued += it.processed()
1656-
stats.ignored += it.remaining()
1657-
1658-
// If there are any still remaining, mark as ignored
1659-
return it.index, err
1660-
16611594
// Some other error(except ErrKnownBlock) occurred, abort.
16621595
// ErrKnownBlock is allowed here since some known blocks
16631596
// still need re-execution to generate snapshots that are missing
16641597
case err != nil && !errors.Is(err, ErrKnownBlock):
1665-
bc.futureBlocks.Remove(block.Hash())
16661598
stats.ignored += len(it.chain)
16671599
bc.reportBlock(block, nil, err)
16681600
return it.index, err
@@ -1867,23 +1799,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
18671799
"root", block.Root())
18681800
}
18691801
}
1870-
1871-
// Any blocks remaining here? The only ones we care about are the future ones
1872-
if block != nil && errors.Is(err, consensus.ErrFutureBlock) {
1873-
if err := bc.addFutureBlock(block); err != nil {
1874-
return it.index, err
1875-
}
1876-
block, err = it.next()
1877-
1878-
for ; block != nil && errors.Is(err, consensus.ErrUnknownAncestor); block, err = it.next() {
1879-
if err := bc.addFutureBlock(block); err != nil {
1880-
return it.index, err
1881-
}
1882-
stats.queued++
1883-
}
1884-
}
18851802
stats.ignored += it.remaining()
1886-
18871803
return it.index, err
18881804
}
18891805

@@ -2334,20 +2250,6 @@ func (bc *BlockChain) SetCanonical(head *types.Block) (common.Hash, error) {
23342250
return head.Hash(), nil
23352251
}
23362252

2337-
func (bc *BlockChain) updateFutureBlocks() {
2338-
futureTimer := time.NewTicker(5 * time.Second)
2339-
defer futureTimer.Stop()
2340-
defer bc.wg.Done()
2341-
for {
2342-
select {
2343-
case <-futureTimer.C:
2344-
bc.procFutureBlocks()
2345-
case <-bc.quit:
2346-
return
2347-
}
2348-
}
2349-
}
2350-
23512253
// skipBlock returns 'true', if the block being imported can be skipped over, meaning
23522254
// that the block does not need to be processed but can be considered already fully 'done'.
23532255
func (bc *BlockChain) skipBlock(err error, it *insertIterator) bool {

core/blockchain_insert.go

-5
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,3 @@ func (it *insertIterator) first() *types.Block {
179179
func (it *insertIterator) remaining() int {
180180
return len(it.chain) - it.index
181181
}
182-
183-
// processed returns the number of processed blocks.
184-
func (it *insertIterator) processed() int {
185-
return it.index + 1
186-
}

core/blockchain_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,6 @@ func testSideImport(t *testing.T, numCanonBlocksInSidechain, blocksBetweenCommon
21292129
// Generate a canonical chain to act as the main dataset
21302130
chainConfig := *params.TestChainConfig
21312131
var (
2132-
merger = consensus.NewMerger(rawdb.NewMemoryDatabase())
21332132
engine = beacon.New(ethash.NewFaker())
21342133
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
21352134
addr = crypto.PubkeyToAddress(key.PublicKey)
@@ -2153,8 +2152,6 @@ func testSideImport(t *testing.T, numCanonBlocksInSidechain, blocksBetweenCommon
21532152
// Activate the transition since genesis if required
21542153
if mergePoint == 0 {
21552154
mergeBlock = 0
2156-
merger.ReachTTD()
2157-
merger.FinalizePoS()
21582155

21592156
// Set the terminal total difficulty in the config
21602157
gspec.Config.TerminalTotalDifficulty = big.NewInt(0)
@@ -2189,8 +2186,6 @@ func testSideImport(t *testing.T, numCanonBlocksInSidechain, blocksBetweenCommon
21892186

21902187
// Activate the transition in the middle of the chain
21912188
if mergePoint == 1 {
2192-
merger.ReachTTD()
2193-
merger.FinalizePoS()
21942189
// Set the terminal total difficulty in the config
21952190
ttd := big.NewInt(int64(len(blocks)))
21962191
ttd.Mul(ttd, params.GenesisDifficulty)

0 commit comments

Comments
 (0)