@@ -50,7 +50,6 @@ import (
50
50
"github.com/ethereum/go-ethereum/triedb"
51
51
"github.com/ethereum/go-ethereum/triedb/hashdb"
52
52
"github.com/ethereum/go-ethereum/triedb/pathdb"
53
- "golang.org/x/exp/slices"
54
53
)
55
54
56
55
var (
@@ -97,13 +96,11 @@ var (
97
96
)
98
97
99
98
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
107
104
108
105
// BlockChainVersion ensures that an incompatible database forces a resync from scratch.
109
106
//
@@ -245,9 +242,6 @@ type BlockChain struct {
245
242
blockCache * lru.Cache [common.Hash , * types.Block ]
246
243
txLookupCache * lru.Cache [common.Hash , txLookup ]
247
244
248
- // future blocks are blocks added for later processing
249
- futureBlocks * lru.Cache [common.Hash , * types.Block ]
250
-
251
245
wg sync.WaitGroup
252
246
quit chan struct {} // shutdown signal, closed in Stop.
253
247
stopping atomic.Bool // false if chain is running, true when stopped
@@ -299,7 +293,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
299
293
receiptsCache : lru.NewCache [common.Hash , []* types.Receipt ](receiptsCacheLimit ),
300
294
blockCache : lru.NewCache [common.Hash , * types.Block ](blockCacheLimit ),
301
295
txLookupCache : lru.NewCache [common.Hash , txLookup ](txLookupCacheLimit ),
302
- futureBlocks : lru.NewCache [common.Hash , * types.Block ](maxFutureBlocks ),
303
296
engine : engine ,
304
297
vmConfig : vmConfig ,
305
298
}
@@ -449,11 +442,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
449
442
}
450
443
bc .snaps , _ = snapshot .New (snapconfig , bc .db , bc .triedb , head .Root )
451
444
}
452
-
453
- // Start future block processor.
454
- bc .wg .Add (1 )
455
- go bc .updateFutureBlocks ()
456
-
457
445
// Rewind the chain in case of an incompatible config upgrade.
458
446
if compat , ok := genesisErr .(* params.ConfigCompatError ); ok {
459
447
log .Warn ("Rewinding chain to upgrade configuration" , "err" , compat )
@@ -794,7 +782,6 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha
794
782
bc .receiptsCache .Purge ()
795
783
bc .blockCache .Purge ()
796
784
bc .txLookupCache .Purge ()
797
- bc .futureBlocks .Purge ()
798
785
799
786
// Clear safe block, finalized block if needed
800
787
if safe := bc .CurrentSafeBlock (); safe != nil && head < safe .Number .Uint64 () {
@@ -1048,24 +1035,6 @@ func (bc *BlockChain) insertStopped() bool {
1048
1035
return bc .procInterrupt .Load ()
1049
1036
}
1050
1037
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
-
1069
1038
// WriteStatus status of write
1070
1039
type WriteStatus byte
1071
1040
@@ -1466,8 +1435,6 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types
1466
1435
if status == CanonStatTy {
1467
1436
bc .writeHeadBlock (block )
1468
1437
}
1469
- bc .futureBlocks .Remove (block .Hash ())
1470
-
1471
1438
if status == CanonStatTy {
1472
1439
bc .chainFeed .Send (ChainEvent {Block : block , Hash : block .Hash (), Logs : logs })
1473
1440
if len (logs ) > 0 {
@@ -1487,25 +1454,6 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types
1487
1454
return status , nil
1488
1455
}
1489
1456
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
-
1509
1457
// InsertChain attempts to insert the given batch of blocks in to the canonical
1510
1458
// chain or, otherwise, create a fork. If an error is returned it will return
1511
1459
// 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)
1643
1591
_ , err := bc .recoverAncestors (block )
1644
1592
return it .index , err
1645
1593
}
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
-
1661
1594
// Some other error(except ErrKnownBlock) occurred, abort.
1662
1595
// ErrKnownBlock is allowed here since some known blocks
1663
1596
// still need re-execution to generate snapshots that are missing
1664
1597
case err != nil && ! errors .Is (err , ErrKnownBlock ):
1665
- bc .futureBlocks .Remove (block .Hash ())
1666
1598
stats .ignored += len (it .chain )
1667
1599
bc .reportBlock (block , nil , err )
1668
1600
return it .index , err
@@ -1867,23 +1799,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
1867
1799
"root" , block .Root ())
1868
1800
}
1869
1801
}
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
- }
1885
1802
stats .ignored += it .remaining ()
1886
-
1887
1803
return it .index , err
1888
1804
}
1889
1805
@@ -2334,20 +2250,6 @@ func (bc *BlockChain) SetCanonical(head *types.Block) (common.Hash, error) {
2334
2250
return head .Hash (), nil
2335
2251
}
2336
2252
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
-
2351
2253
// skipBlock returns 'true', if the block being imported can be skipped over, meaning
2352
2254
// that the block does not need to be processed but can be considered already fully 'done'.
2353
2255
func (bc * BlockChain ) skipBlock (err error , it * insertIterator ) bool {
0 commit comments