aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSonic <sonic@dexon.org>2019-01-03 17:04:10 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:21 +0800
commit7c31a0ecb0cf29a0e4b8a7ef3fb3930ac2cf072d (patch)
tree33458fd989dbe10acc2ffab35d822b2599cd14ef
parentfd72482f7a9af7b8230414a59c6541366e1816c7 (diff)
downloadgo-tangerine-7c31a0ecb0cf29a0e4b8a7ef3fb3930ac2cf072d.tar
go-tangerine-7c31a0ecb0cf29a0e4b8a7ef3fb3930ac2cf072d.tar.gz
go-tangerine-7c31a0ecb0cf29a0e4b8a7ef3fb3930ac2cf072d.tar.bz2
go-tangerine-7c31a0ecb0cf29a0e4b8a7ef3fb3930ac2cf072d.tar.lz
go-tangerine-7c31a0ecb0cf29a0e4b8a7ef3fb3930ac2cf072d.tar.xz
go-tangerine-7c31a0ecb0cf29a0e4b8a7ef3fb3930ac2cf072d.tar.zst
go-tangerine-7c31a0ecb0cf29a0e4b8a7ef3fb3930ac2cf072d.zip
core: fix vm wrong round height context (#124)
Let roundHeightMap be corret whenever we starting a bp node.
-rw-r--r--core/blockchain.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 0e87360c3..72837e324 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -237,6 +237,51 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
gov := NewGovernance(NewGovernanceStateDB(bc))
bc.verifierCache = dexCore.NewTSigVerifierCache(gov, 5)
+ // Init round height map
+ curblock := bc.CurrentBlock()
+ r := curblock.Round()
+
+ // Blocks will interleave during round change, so we need to init current
+ // and previous round.
+ if r == 0 {
+ // No previous round.
+ log.Debug("Init round height", "height", curblock.NumberU64(), "round", curblock.Round())
+ bc.storeRoundHeight(uint64(0), uint64(0))
+ } else {
+ prevh := gov.GetRoundHeight(r - 1)
+ if prevh == uint64(0) {
+ // Previous round height should be already snapshoted
+ // in governance state at this moment.
+ panic("can not init previous round height map")
+ }
+ log.Debug("Init previous round height", "height", prevh, "round", r-1)
+ bc.storeRoundHeight(r-1, prevh)
+
+ curh := gov.GetRoundHeight(r)
+
+ // Current round height is not snapshoted in governance state yet,
+ if curh == uint64(0) {
+ // Linear search the first block of current round
+ // from previous round height.
+ h := prevh
+ for h <= curblock.NumberU64() {
+ b := bc.GetBlockByNumber(h)
+ if b.Round() == r {
+ curh = h
+ break
+ }
+ }
+
+ // This case is impossible.
+ if curh == uint64(0) {
+ panic("can find current round height")
+ }
+ }
+
+ log.Debug("Init current round height", "height", curh, "round", r)
+ bc.storeRoundHeight(r, curh)
+ }
+
// Take ownership of this particular state
go bc.update()
return bc, nil