aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-03-12 12:13:38 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:58 +0800
commit32fcefbe8d9c3f5e6b0732d9d33854d6f1333480 (patch)
tree638c3643ca5b62a16f89ab1f320993cf7740f9de
parent7e6fbc77b8be3f2f0cc52f410b071a1e1fd28641 (diff)
downloaddexon-32fcefbe8d9c3f5e6b0732d9d33854d6f1333480.tar
dexon-32fcefbe8d9c3f5e6b0732d9d33854d6f1333480.tar.gz
dexon-32fcefbe8d9c3f5e6b0732d9d33854d6f1333480.tar.bz2
dexon-32fcefbe8d9c3f5e6b0732d9d33854d6f1333480.tar.lz
dexon-32fcefbe8d9c3f5e6b0732d9d33854d6f1333480.tar.xz
dexon-32fcefbe8d9c3f5e6b0732d9d33854d6f1333480.tar.zst
dexon-32fcefbe8d9c3f5e6b0732d9d33854d6f1333480.zip
core: touch verifierCache at 90% of round (#247)
-rw-r--r--core/blockchain.go37
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")
+ }
+ }()
+}