Skip to content

Commit 07db098

Browse files
committed
core: renamed next to pending & fixed tests
1 parent 855e76f commit 07db098

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

core/chain_manager.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ type ChainManager struct {
108108
transState *state.StateDB
109109
txState *state.ManagedState
110110

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
114114

115115
quit chan struct{}
116116
// procInterrupt must be atomically called
@@ -389,8 +389,8 @@ func (bc *ChainManager) HasBlock(hash common.Hash) bool {
389389
return true
390390
}
391391

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 {
394394
return true
395395
}
396396
}
@@ -425,8 +425,8 @@ func (self *ChainManager) GetBlock(hash common.Hash) *types.Block {
425425
return block.(*types.Block)
426426
}
427427

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 {
430430
return block
431431
}
432432
}
@@ -521,13 +521,13 @@ func (self *ChainManager) procFutureBlocks() {
521521
}
522522

523523
func (self *ChainManager) enqueueForWrite(block *types.Block) {
524-
self.nextBlocks.Push(block)
524+
self.pendingBlocks.Push(block)
525525
}
526526

527527
func (self *ChainManager) flushQueuedBlocks() {
528528
db, batchWrite := self.blockDb.(*ethdb.LDBDatabase)
529529
batch := new(leveldb.Batch)
530-
self.nextBlocks.Each(func(i int, block *types.Block) {
530+
self.pendingBlocks.Each(func(i int, block *types.Block) {
531531
enc, _ := rlp.EncodeToBytes((*types.StorageBlock)(block))
532532
key := append(blockHashPre, block.Hash().Bytes()...)
533533
if batchWrite {
@@ -539,10 +539,6 @@ func (self *ChainManager) flushQueuedBlocks() {
539539
if batchWrite {
540540
db.LDB().Write(batch, nil)
541541
}
542-
543-
// reset the next blocks cache
544-
self.nextBlocks = nil
545-
546542
}
547543

548544
// 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) {
554550
self.chainmu.Lock()
555551
defer self.chainmu.Unlock()
556552

557-
self.nextBlocks = NewBlockCache(len(chain))
553+
self.pendingBlocks = NewBlockCache(len(chain))
558554

559555
// A queued approach to delivering events. This is generally
560556
// faster than direct delivery and requires much less mutex
@@ -687,7 +683,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
687683
queue[i] = ChainSideEvent{block, logs}
688684
queueEvent.sideCount++
689685
}
690-
// Write block to database. Eventually we'll have to improve on this and throw away blocks that are
691686
// not in the canonical chain.
692687
self.enqueueForWrite(block)
693688
// Delete from future blocks

core/chain_manager_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/ethereum/go-ethereum/event"
1919
"github.com/ethereum/go-ethereum/pow"
2020
"github.com/ethereum/go-ethereum/rlp"
21+
"github.com/hashicorp/golang-lru"
2122
)
2223

2324
func init() {
@@ -109,7 +110,8 @@ func testChain(chainB types.Blocks, bman *BlockProcessor) (*big.Int, error) {
109110

110111
bman.bc.mu.Lock()
111112
{
112-
bman.bc.write(block)
113+
bman.bc.enqueueForWrite(block)
114+
//bman.bc.write(block)
113115
}
114116
bman.bc.mu.Unlock()
115117
}
@@ -391,7 +393,7 @@ func makeChainWithDiff(genesis *types.Block, d []int, seed byte) []*types.Block
391393
func chm(genesis *types.Block, db common.Database) *ChainManager {
392394
var eventMux event.TypeMux
393395
bc := &ChainManager{blockDb: db, stateDb: db, genesisBlock: genesis, eventMux: &eventMux, pow: FakePow{}}
394-
bc.cache = NewBlockCache(100)
396+
bc.cache, _ = lru.New(100)
395397
bc.futureBlocks = NewBlockCache(100)
396398
bc.processor = bproc{}
397399
bc.ResetWithGenesisBlock(genesis)

0 commit comments

Comments
 (0)