aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-03-07 10:28:19 +0800
committerGitHub <noreply@github.com>2019-03-07 10:28:19 +0800
commit0dd85e178a8a8b00c3a192c32c48547444be18dc (patch)
tree6f135128bd9f3c741a8d5f2a797dfb79e31a0dd8
parentaff897fd2385152a7bfd8a8ac0846ef5ad736b96 (diff)
downloaddexon-consensus-0dd85e178a8a8b00c3a192c32c48547444be18dc.tar
dexon-consensus-0dd85e178a8a8b00c3a192c32c48547444be18dc.tar.gz
dexon-consensus-0dd85e178a8a8b00c3a192c32c48547444be18dc.tar.bz2
dexon-consensus-0dd85e178a8a8b00c3a192c32c48547444be18dc.tar.lz
dexon-consensus-0dd85e178a8a8b00c3a192c32c48547444be18dc.tar.xz
dexon-consensus-0dd85e178a8a8b00c3a192c32c48547444be18dc.tar.zst
dexon-consensus-0dd85e178a8a8b00c3a192c32c48547444be18dc.zip
core: touch nodeSetCache (#466)
-rw-r--r--core/consensus.go10
-rw-r--r--core/utils/nodeset-cache.go6
-rw-r--r--core/utils/nodeset-cache_test.go20
3 files changed, 36 insertions, 0 deletions
diff --git a/core/consensus.go b/core/consensus.go
index 0f665f2..b0827fe 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -831,6 +831,16 @@ func (con *Consensus) initialRound(
con.initialRound(
startHeight+config.RoundLength, nextRound, nextConfig)
})
+ // Touch nodeSetCache for next round.
+ con.event.RegisterHeight(startHeight+config.RoundLength*9/10, func(uint64) {
+ go func() {
+ // TODO(jimmy): check DKGResetCount and do not touch if nextRound is reset.
+ if err := con.nodeSetCache.Touch(round + 1); err != nil {
+ con.logger.Warn("Failed to update nodeSetCache",
+ "round", round+1, "error", err)
+ }
+ }()
+ })
}
// Stop the Consensus core.
diff --git a/core/utils/nodeset-cache.go b/core/utils/nodeset-cache.go
index 6249665..e09120d 100644
--- a/core/utils/nodeset-cache.go
+++ b/core/utils/nodeset-cache.go
@@ -165,6 +165,12 @@ func (cache *NodeSetCache) GetLeaderNode(pos types.Position) (
return IDs.leaderNode[pos.Height], nil
}
+// Touch updates the internal cache of round.
+func (cache *NodeSetCache) Touch(round uint64) (err error) {
+ _, err = cache.update(round)
+ return
+}
+
func (cache *NodeSetCache) cloneMap(
nIDs map[types.NodeID]struct{}) map[types.NodeID]struct{} {
nIDsCopy := make(map[types.NodeID]struct{}, len(nIDs))
diff --git a/core/utils/nodeset-cache_test.go b/core/utils/nodeset-cache_test.go
index 6d29b6e..fe905cf 100644
--- a/core/utils/nodeset-cache_test.go
+++ b/core/utils/nodeset-cache_test.go
@@ -118,6 +118,26 @@ func (s *NodeSetCacheTestSuite) TestBasicUsage() {
}
}
+func (s *NodeSetCacheTestSuite) TestTouch() {
+ var (
+ nsIntf = &nsIntf{
+ s: s,
+ crs: common.NewRandomHash(),
+ }
+ cache = NewNodeSetCache(nsIntf)
+ req = s.Require()
+ )
+
+ _, exists := cache.get(1)
+ req.False(exists)
+
+ err := cache.Touch(1)
+ req.NoError(err)
+
+ _, exists = cache.get(1)
+ req.True(exists)
+}
+
func TestNodeSetCache(t *testing.T) {
suite.Run(t, new(NodeSetCacheTestSuite))
}