@@ -108,9 +108,9 @@ type ChainManager struct {
108
108
transState * state.StateDB
109
109
txState * state.ManagedState
110
110
111
- cache * lru.Cache // cache is the LRU caching
112
- futureBlocks * BlockCache // future blocks are blocks added for later processing
113
- nextBlocks * BlockCache // next blocks is used during large inserts
111
+ cache * lru.Cache // cache is the LRU caching
112
+ futureBlocks * BlockCache // future blocks are blocks added for later processing
113
+ pendingBlocks * BlockCache // pending blocks contain blocks not yet written to the db
114
114
115
115
quit chan struct {}
116
116
// procInterrupt must be atomically called
@@ -389,8 +389,8 @@ func (bc *ChainManager) HasBlock(hash common.Hash) bool {
389
389
return true
390
390
}
391
391
392
- if bc .nextBlocks != nil {
393
- if block := bc .nextBlocks .Get (hash ); block != nil {
392
+ if bc .pendingBlocks != nil {
393
+ if block := bc .pendingBlocks .Get (hash ); block != nil {
394
394
return true
395
395
}
396
396
}
@@ -425,8 +425,8 @@ func (self *ChainManager) GetBlock(hash common.Hash) *types.Block {
425
425
return block .(* types.Block )
426
426
}
427
427
428
- if self .nextBlocks != nil {
429
- if block := self .nextBlocks .Get (hash ); block != nil {
428
+ if self .pendingBlocks != nil {
429
+ if block := self .pendingBlocks .Get (hash ); block != nil {
430
430
return block
431
431
}
432
432
}
@@ -521,13 +521,13 @@ func (self *ChainManager) procFutureBlocks() {
521
521
}
522
522
523
523
func (self * ChainManager ) enqueueForWrite (block * types.Block ) {
524
- self .nextBlocks .Push (block )
524
+ self .pendingBlocks .Push (block )
525
525
}
526
526
527
527
func (self * ChainManager ) flushQueuedBlocks () {
528
528
db , batchWrite := self .blockDb .(* ethdb.LDBDatabase )
529
529
batch := new (leveldb.Batch )
530
- self .nextBlocks .Each (func (i int , block * types.Block ) {
530
+ self .pendingBlocks .Each (func (i int , block * types.Block ) {
531
531
enc , _ := rlp .EncodeToBytes ((* types .StorageBlock )(block ))
532
532
key := append (blockHashPre , block .Hash ().Bytes ()... )
533
533
if batchWrite {
@@ -539,10 +539,6 @@ func (self *ChainManager) flushQueuedBlocks() {
539
539
if batchWrite {
540
540
db .LDB ().Write (batch , nil )
541
541
}
542
-
543
- // reset the next blocks cache
544
- self .nextBlocks = nil
545
-
546
542
}
547
543
548
544
// InsertChain will attempt to insert the given chain in to the canonical chain or, otherwise, create a fork. It an error is returned
@@ -554,7 +550,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
554
550
self .chainmu .Lock ()
555
551
defer self .chainmu .Unlock ()
556
552
557
- self .nextBlocks = NewBlockCache (len (chain ))
553
+ self .pendingBlocks = NewBlockCache (len (chain ))
558
554
559
555
// A queued approach to delivering events. This is generally
560
556
// faster than direct delivery and requires much less mutex
@@ -687,7 +683,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
687
683
queue [i ] = ChainSideEvent {block , logs }
688
684
queueEvent .sideCount ++
689
685
}
690
- // Write block to database. Eventually we'll have to improve on this and throw away blocks that are
691
686
// not in the canonical chain.
692
687
self .enqueueForWrite (block )
693
688
// Delete from future blocks
0 commit comments