diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-03-12 12:13:38 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | ed67d8155556892f81a7f1a729a5733ed6318743 (patch) | |
tree | d48431e6dcade58e18eda8561d542644efe6c7d7 | |
parent | 390b0f5aa6d7a5127a04b8949815033d59608e7b (diff) | |
download | dexon-ed67d8155556892f81a7f1a729a5733ed6318743.tar.gz dexon-ed67d8155556892f81a7f1a729a5733ed6318743.tar.zst dexon-ed67d8155556892f81a7f1a729a5733ed6318743.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 b04255156..9e6c305fb 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}) @@ -2281,3 +2285,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") + } + }() +} |