aboutsummaryrefslogtreecommitdiffstats
path: root/core/chain_manager.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-20 18:29:02 +0800
committerobscuren <geffobscura@gmail.com>2015-04-20 18:29:02 +0800
commit45da3e17e2ada226d7c82db667d263f8e004cbfc (patch)
tree627499fa3e24bbe70ed5c0c526d30d713205b106 /core/chain_manager.go
parent52584596d4c9cee7adcc1c343addd19279aaac84 (diff)
downloaddexon-45da3e17e2ada226d7c82db667d263f8e004cbfc.tar.gz
dexon-45da3e17e2ada226d7c82db667d263f8e004cbfc.tar.zst
dexon-45da3e17e2ada226d7c82db667d263f8e004cbfc.zip
core: added chain head reset to known block
Diffstat (limited to 'core/chain_manager.go')
-rw-r--r--core/chain_manager.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 76fa3e1ea..d312f2495 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -109,6 +109,30 @@ func NewChainManager(blockDb, stateDb common.Database, mux *event.TypeMux) *Chai
return bc
}
+func (bc *ChainManager) SetHead(block *types.Block) {
+ bc.mu.Lock()
+ defer bc.mu.Unlock()
+
+ for block := bc.currentBlock; block != nil && block.Hash() != block.Hash(); block = bc.GetBlock(block.Header().ParentHash) {
+ bc.removeBlock(block)
+ }
+
+ if bc.cache == nil {
+ bc.cache = NewBlockCache(blockCacheLimit)
+ }
+
+ bc.currentBlock = block
+ bc.makeCache()
+
+ statedb := state.New(block.Root(), bc.stateDb)
+ bc.txState = state.ManageState(statedb)
+ bc.transState = statedb.Copy()
+ bc.setTotalDifficulty(block.Td)
+ bc.setLastBlock()
+ bc.insert(block)
+ bc.setLastBlock()
+}
+
func (self *ChainManager) Td() *big.Int {
self.mu.RLock()
defer self.mu.RUnlock()