aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-23 19:22:58 +0800
committerobscuren <geffobscura@gmail.com>2015-03-23 19:22:58 +0800
commit524f8199bfaddebc96798827e943667a909a03e7 (patch)
treed7f55579c0ed67cdaa24d83ff58439de2c9fe7e7 /core
parent6657d544db4eefec24ebd280940048f25ed85186 (diff)
downloaddexon-524f8199bfaddebc96798827e943667a909a03e7.tar
dexon-524f8199bfaddebc96798827e943667a909a03e7.tar.gz
dexon-524f8199bfaddebc96798827e943667a909a03e7.tar.bz2
dexon-524f8199bfaddebc96798827e943667a909a03e7.tar.lz
dexon-524f8199bfaddebc96798827e943667a909a03e7.tar.xz
dexon-524f8199bfaddebc96798827e943667a909a03e7.tar.zst
dexon-524f8199bfaddebc96798827e943667a909a03e7.zip
added some nil checks for cache (testing specific)
Diffstat (limited to 'core')
-rw-r--r--core/chain_manager.go25
1 files changed, 19 insertions, 6 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 1bc8edea6..755487900 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -106,12 +106,7 @@ func NewChainManager(blockDb, stateDb common.Database, mux *event.TypeMux) *Chai
// Take ownership of this particular state
bc.txState = state.ManageState(bc.State().Copy())
- // load in last `blockCacheLimit` - 1 blocks. Last block is the current.
- ancestors := bc.GetAncestors(bc.currentBlock, blockCacheLimit-1)
- ancestors = append(ancestors, bc.currentBlock)
- for _, block := range ancestors {
- bc.cache.Push(block)
- }
+ bc.makeCache()
go bc.update()
@@ -194,6 +189,18 @@ func (bc *ChainManager) setLastBlock() {
chainlogger.Infof("Last block (#%v) %x TD=%v\n", bc.currentBlock.Number(), bc.currentBlock.Hash(), bc.td)
}
+func (bc *ChainManager) makeCache() {
+ if bc.cache == nil {
+ bc.cache = NewBlockCache(blockCacheLimit)
+ }
+ // load in last `blockCacheLimit` - 1 blocks. Last block is the current.
+ ancestors := bc.GetAncestors(bc.currentBlock, blockCacheLimit-1)
+ ancestors = append(ancestors, bc.currentBlock)
+ for _, block := range ancestors {
+ bc.cache.Push(block)
+ }
+}
+
// Block creation & chain handling
func (bc *ChainManager) NewBlock(coinbase common.Address) *types.Block {
bc.mu.RLock()
@@ -240,10 +247,15 @@ func (bc *ChainManager) Reset() {
bc.removeBlock(block)
}
+ if bc.cache == nil {
+ bc.cache = NewBlockCache(blockCacheLimit)
+ }
+
// Prepare the genesis block
bc.write(bc.genesisBlock)
bc.insert(bc.genesisBlock)
bc.currentBlock = bc.genesisBlock
+ bc.makeCache()
bc.setTotalDifficulty(common.Big("0"))
}
@@ -265,6 +277,7 @@ func (bc *ChainManager) ResetWithGenesisBlock(gb *types.Block) {
bc.write(bc.genesisBlock)
bc.insert(bc.genesisBlock)
bc.currentBlock = bc.genesisBlock
+ bc.makeCache()
}
// Export writes the active chain to the given writer.