diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-03-12 12:13:38 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:22 +0800 |
commit | 9f881468d081c0627403cc5058ef4ee72fe9f933 (patch) | |
tree | 57f0316223e5653ae182c2ccca6dd7674a63be73 | |
parent | 8ffc8f2b78bfb3cc352f71ca569ad6c09bda1461 (diff) | |
download | go-tangerine-9f881468d081c0627403cc5058ef4ee72fe9f933.tar go-tangerine-9f881468d081c0627403cc5058ef4ee72fe9f933.tar.gz go-tangerine-9f881468d081c0627403cc5058ef4ee72fe9f933.tar.bz2 go-tangerine-9f881468d081c0627403cc5058ef4ee72fe9f933.tar.lz go-tangerine-9f881468d081c0627403cc5058ef4ee72fe9f933.tar.xz go-tangerine-9f881468d081c0627403cc5058ef4ee72fe9f933.tar.zst go-tangerine-9f881468d081c0627403cc5058ef4ee72fe9f933.zip |
core: touch verifierCache at 90% of round (#247)
-rw-r--r-- | core/blockchain.go | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index f829c0e8e..7a695ac38 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -145,8 +145,9 @@ type BlockChain struct { roundHeightMap sync.Map - gov *Governance - verifierCache *dexCore.TSigVerifierCache + gov *Governance + verifierCache *dexCore.TSigVerifierCache + nextTouchHeight uint64 } // NewBlockChain returns a fully initialised block chain using information @@ -1658,6 +1659,9 @@ func (bc *BlockChain) insertDexonChain(chain types.Blocks) (int, []interface{}, cache, _ := bc.stateCache.TrieDB().Size() stats.report(chain, i, cache) } + if lastCanon != nil { + bc.touchNextRoundCache(lastCanon.Round(), lastCanon.NumberU64()) + } // Append a single chain head event if we've progressed the chain if lastCanon != nil && bc.CurrentBlock().Hash() == lastCanon.Hash() { events = append(events, ChainHeadEvent{lastCanon}) @@ -2303,3 +2307,32 @@ func (bc *BlockChain) GetRoundHeight(round uint64) (uint64, bool) { func (bc *BlockChain) storeRoundHeight(round uint64, height uint64) { bc.roundHeightMap.Store(round, height) } + +func (bc *BlockChain) touchNextRoundCache(round uint64, height uint64) { + if height < bc.nextTouchHeight { + return + } + roundHeight, exist := bc.GetRoundHeight(round) + if !exist { + log.Warn("Unable to get round height", "round", round) + return + } + roundLength := bc.gov.Configuration(round).RoundLength + roundHeight += roundLength*bc.gov.DKGResetCount(round+1) + roundLength*9/10 + // DKGResetCount might have increased. + if height < roundHeight { + bc.nextTouchHeight = roundHeight + return + } + bc.nextTouchHeight = roundHeight + + roundLength*(1+bc.gov.DKGResetCount(round+1)) + + bc.gov.Configuration(round+1).RoundLength*9/10 + go func() { + ok, err := bc.verifierCache.Update(round + 1) + if err != nil { + log.Warn("Failed to update verifierCache", "err", err) + } else if !ok { + log.Warn("Unable to updated verifierCache") + } + }() +} |