aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-06-19 22:48:55 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-06-30 00:51:49 +0800
commit6ca3a446383bafc9510b36c88629ca7d876fb258 (patch)
treee9f6a20ffe3a00d670da4808ee40f9da501360ec
parent4460dc9d1a7e12f1f0583538c7df852cd64c4fed (diff)
downloaddexon-6ca3a446383bafc9510b36c88629ca7d876fb258.tar
dexon-6ca3a446383bafc9510b36c88629ca7d876fb258.tar.gz
dexon-6ca3a446383bafc9510b36c88629ca7d876fb258.tar.bz2
dexon-6ca3a446383bafc9510b36c88629ca7d876fb258.tar.lz
dexon-6ca3a446383bafc9510b36c88629ca7d876fb258.tar.xz
dexon-6ca3a446383bafc9510b36c88629ca7d876fb258.tar.zst
dexon-6ca3a446383bafc9510b36c88629ca7d876fb258.zip
core: switched to proper LRU
-rw-r--r--core/chain_manager.go15
1 files changed, 6 insertions, 9 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go
index a0f945020..e67439bb6 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -21,7 +21,7 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/pow"
"github.com/ethereum/go-ethereum/rlp"
- "github.com/golang/groupcache/lru"
+ "github.com/hashicorp/golang-lru"
"github.com/syndtr/goleveldb/leveldb"
)
@@ -121,13 +121,14 @@ type ChainManager struct {
}
func NewChainManager(genesis *types.Block, blockDb, stateDb common.Database, pow pow.PoW, mux *event.TypeMux) (*ChainManager, error) {
+ cache, _ := lru.New(blockCacheLimit)
bc := &ChainManager{
blockDb: blockDb,
stateDb: stateDb,
genesisBlock: GenesisBlock(42, stateDb),
eventMux: mux,
quit: make(chan struct{}),
- cache: lru.New(blockCacheLimit),
+ cache: cache,
pow: pow,
}
// Check the genesis block given to the chain manager. If the genesis block mismatches block number 0
@@ -172,7 +173,7 @@ func (bc *ChainManager) SetHead(head *types.Block) {
bc.removeBlock(block)
}
- bc.cache = lru.New(blockCacheLimit)
+ bc.cache, _ = lru.New(blockCacheLimit)
bc.currentBlock = head
bc.makeCache()
@@ -260,9 +261,7 @@ func (bc *ChainManager) setLastState() {
}
func (bc *ChainManager) makeCache() {
- if bc.cache == nil {
- bc.cache = lru.New(blockCacheLimit)
- }
+ bc.cache, _ = lru.New(blockCacheLimit)
// load in last `blockCacheLimit` - 1 blocks. Last block is the current.
ancestors := bc.GetAncestors(bc.currentBlock, blockCacheLimit-1)
ancestors = append(ancestors, bc.currentBlock)
@@ -279,9 +278,7 @@ func (bc *ChainManager) Reset() {
bc.removeBlock(block)
}
- if bc.cache == nil {
- bc.cache = lru.New(blockCacheLimit)
- }
+ bc.cache, _ = lru.New(blockCacheLimit)
// Prepare the genesis block
bc.write(bc.genesisBlock)