From 32fcefbe8d9c3f5e6b0732d9d33854d6f1333480 Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Tue, 12 Mar 2019 12:13:38 +0800 Subject: core: touch verifierCache at 90% of round (#247) --- core/blockchain.go | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'core') 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") + } + }() +} -- cgit v1.2.3