@@ -56,7 +56,6 @@ import (
56
56
"github.com/ethereum/go-ethereum/triedb"
57
57
"github.com/ethereum/go-ethereum/triedb/hashdb"
58
58
"github.com/ethereum/go-ethereum/triedb/pathdb"
59
- "golang.org/x/exp/slices"
60
59
)
61
60
62
61
var (
@@ -110,6 +109,7 @@ var (
110
109
)
111
110
112
111
const (
112
+ << << << < HEAD
113
113
bodyCacheLimit = 256
114
114
blockCacheLimit = 256
115
115
diffLayerCacheLimit = 1024
@@ -127,6 +127,13 @@ const (
127
127
maxDiffForkDist = 11 // Maximum allowed backward distance from the chain head
128
128
129
129
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 ))
130
137
131
138
// BlockChainVersion ensures that an incompatible database forces a resync from scratch.
132
139
//
@@ -292,6 +299,7 @@ type BlockChain struct {
292
299
txLookupCache * lru.Cache [common.Hash , txLookup ]
293
300
sidecarsCache * lru.Cache [common.Hash , types.BlobSidecars ]
294
301
302
+ << << << < HEAD
295
303
// future blocks are blocks added for later processing
296
304
futureBlocks * lru.Cache [common.Hash , * types.Block ]
297
305
// Cache for the blocks that failed to pass MPT root verification
@@ -304,6 +312,8 @@ type BlockChain struct {
304
312
diffQueueBuffer chan * types.DiffLayer
305
313
diffLayerFreezerBlockLimit uint64
306
314
315
+ == == == =
316
+ >> >> >> > f4d53133f (consensus , cmd , core , eth : remove support for non - merge mode of operation (#29169 ))
307
317
wg sync.WaitGroup
308
318
dbWg sync.WaitGroup
309
319
quit chan struct {} // shutdown signal, closed in Stop.
@@ -363,6 +373,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
363
373
*/
364
374
365
375
bc := & BlockChain {
376
+ << << << < HEAD
366
377
chainConfig: chainConfig ,
367
378
cacheConfig : cacheConfig ,
368
379
db : db ,
@@ -385,6 +396,22 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
385
396
vmConfig : vmConfig ,
386
397
diffQueue : prque.New [int64 , * types.DiffLayer ](nil ),
387
398
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 ))
388
415
}
389
416
bc .flushInterval .Store (int64 (cacheConfig .TrieTimeLimit ))
390
417
bc .forker = NewForkChoice (bc , shouldPreserve )
@@ -550,6 +577,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
550
577
return nil , err
551
578
}
552
579
}
580
+ << << << < HEAD
553
581
// Start future block processor.
554
582
bc .wg .Add (1 )
555
583
go bc .updateFutureBlocks ()
@@ -570,6 +598,8 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
570
598
go bc .startDoubleSignMonitor ()
571
599
}
572
600
601
+ == == == =
602
+ >> >> >> > f4d53133f (consensus , cmd , core , eth : remove support for non - merge mode of operation (#29169 ))
573
603
// Rewind the chain in case of an incompatible config upgrade.
574
604
if compat , ok := genesisErr .(* params.ConfigCompatError ); ok {
575
605
log .Warn ("Rewinding chain to upgrade configuration" , "err" , compat )
@@ -1157,7 +1187,6 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha
1157
1187
bc .sidecarsCache .Purge ()
1158
1188
bc .blockCache .Purge ()
1159
1189
bc .txLookupCache .Purge ()
1160
- bc .futureBlocks .Purge ()
1161
1190
1162
1191
if finalized := bc .CurrentFinalBlock (); finalized != nil && head < finalized .Number .Uint64 () {
1163
1192
log .Error ("SetHead invalidated finalized block" )
@@ -1445,24 +1474,6 @@ func (bc *BlockChain) insertStopped() bool {
1445
1474
return bc .procInterrupt .Load ()
1446
1475
}
1447
1476
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
-
1466
1477
// WriteStatus status of write
1467
1478
type WriteStatus byte
1468
1479
@@ -1959,8 +1970,6 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types
1959
1970
if status == CanonStatTy {
1960
1971
bc .writeHeadBlock (block )
1961
1972
}
1962
- bc .futureBlocks .Remove (block .Hash ())
1963
-
1964
1973
if status == CanonStatTy {
1965
1974
bc .chainFeed .Send (ChainEvent {Block : block , Hash : block .Hash (), Logs : logs })
1966
1975
if len (logs ) > 0 {
@@ -1989,25 +1998,6 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types
1989
1998
return status , nil
1990
1999
}
1991
2000
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
-
2011
2001
// InsertChain attempts to insert the given batch of blocks in to the canonical
2012
2002
// chain or, otherwise, create a fork. If an error is returned it will return
2013
2003
// 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)
2162
2152
_ , err := bc .recoverAncestors (block )
2163
2153
return it .index , err
2164
2154
}
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
-
2180
2155
// Some other error(except ErrKnownBlock) occurred, abort.
2181
2156
// ErrKnownBlock is allowed here since some known blocks
2182
2157
// still need re-execution to generate snapshots that are missing
2183
2158
case err != nil && ! errors .Is (err , ErrKnownBlock ):
2184
- bc .futureBlocks .Remove (block .Hash ())
2185
2159
stats .ignored += len (it .chain )
2186
2160
bc .reportBlock (block , nil , err )
2187
2161
return it .index , err
@@ -2380,23 +2354,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
2380
2354
}
2381
2355
bc .chainBlockFeed .Send (ChainHeadEvent {block })
2382
2356
}
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
- }
2398
2357
stats .ignored += it .remaining ()
2399
-
2400
2358
return it .index , err
2401
2359
}
2402
2360
@@ -2875,6 +2833,7 @@ func (bc *BlockChain) SetCanonical(head *types.Block) (common.Hash, error) {
2875
2833
return head .Hash (), nil
2876
2834
}
2877
2835
2836
+ << << << < HEAD
2878
2837
func (bc * BlockChain ) updateFutureBlocks () {
2879
2838
futureTimer := time .NewTicker (5 * time .Second )
2880
2839
defer futureTimer .Stop ()
@@ -3001,6 +2960,8 @@ func (bc *BlockChain) startDoubleSignMonitor() {
3001
2960
}
3002
2961
}
3003
2962
2963
+ == == == =
2964
+ >> >> >> > f4d53133f (consensus , cmd , core , eth : remove support for non - merge mode of operation (#29169 ))
3004
2965
// skipBlock returns 'true', if the block being imported can be skipped over, meaning
3005
2966
// that the block does not need to be processed but can be considered already fully 'done'.
3006
2967
func (bc * BlockChain ) skipBlock (err error , it * insertIterator ) bool {
0 commit comments