aboutsummaryrefslogtreecommitdiffstats
path: root/core/utils/nodeset-cache.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2019-02-20 12:53:18 +0800
committerGitHub <noreply@github.com>2019-02-20 12:53:18 +0800
commit8ef4fc213703620fbfa13890dee042d40eea8545 (patch)
treeba9a07d2423314396e5677b7294122caa505ae9a /core/utils/nodeset-cache.go
parent2cf18fd299ea0fc270b213343314cab652cac271 (diff)
downloaddexon-consensus-8ef4fc213703620fbfa13890dee042d40eea8545.tar
dexon-consensus-8ef4fc213703620fbfa13890dee042d40eea8545.tar.gz
dexon-consensus-8ef4fc213703620fbfa13890dee042d40eea8545.tar.bz2
dexon-consensus-8ef4fc213703620fbfa13890dee042d40eea8545.tar.lz
dexon-consensus-8ef4fc213703620fbfa13890dee042d40eea8545.tar.xz
dexon-consensus-8ef4fc213703620fbfa13890dee042d40eea8545.tar.zst
dexon-consensus-8ef4fc213703620fbfa13890dee042d40eea8545.zip
core: switch round by block height (#450)
Diffstat (limited to 'core/utils/nodeset-cache.go')
-rw-r--r--core/utils/nodeset-cache.go22
1 files changed, 4 insertions, 18 deletions
diff --git a/core/utils/nodeset-cache.go b/core/utils/nodeset-cache.go
index 8354128..3ff5196 100644
--- a/core/utils/nodeset-cache.go
+++ b/core/utils/nodeset-cache.go
@@ -19,7 +19,6 @@ package utils
import (
"errors"
- "fmt"
"sync"
"github.com/dexon-foundation/dexon-consensus/common"
@@ -34,8 +33,6 @@ var (
ErrCRSNotReady = errors.New("crs is not ready")
// ErrConfigurationNotReady means we go nil configuration.
ErrConfigurationNotReady = errors.New("configuration is not ready")
- // ErrInvalidChainID means the chain ID is unexpected.
- ErrInvalidChainID = errors.New("invalid chain id")
)
type sets struct {
@@ -125,12 +122,8 @@ func (cache *NodeSetCache) GetNodeSet(round uint64) (*types.NodeSet, error) {
}
// GetNotarySet returns of notary set of this round.
-// TODO(mission): remove chainID parameter.
func (cache *NodeSetCache) GetNotarySet(
- round uint64, chainID uint32) (map[types.NodeID]struct{}, error) {
- if chainID != 0 {
- panic(fmt.Errorf("non-zero chainID found: %d", chainID))
- }
+ round uint64) (map[types.NodeID]struct{}, error) {
IDs, err := cache.getOrUpdate(round)
if err != nil {
return nil, err
@@ -196,12 +189,9 @@ func (cache *NodeSetCache) getOrUpdate(round uint64) (nIDs *sets, err error) {
//
// This cache would maintain 10 rounds before the updated round and purge
// rounds not in this range.
-func (cache *NodeSetCache) update(
- round uint64) (nIDs *sets, err error) {
-
+func (cache *NodeSetCache) update(round uint64) (nIDs *sets, err error) {
cache.lock.Lock()
defer cache.lock.Unlock()
-
// Get information for the requested round.
keySet := cache.nsIntf.NodeSet(round)
if keySet == nil {
@@ -232,14 +222,13 @@ func (cache *NodeSetCache) update(
err = ErrConfigurationNotReady
return
}
- nodesPerChain := cfg.RoundInterval / cfg.MinBlockInterval
nIDs = &sets{
crs: crs,
nodeSet: nodeSet,
notarySet: make(map[types.NodeID]struct{}),
dkgSet: nodeSet.GetSubSet(
int(cfg.DKGSetSize), types.NewDKGSetTarget(crs)),
- leaderNode: make(map[uint64]types.NodeID, nodesPerChain),
+ leaderNode: make(map[uint64]types.NodeID, cfg.RoundInterval),
}
nIDs.notarySet = nodeSet.GetSubSet(
int(cfg.NotarySetSize), types.NewNotarySetTarget(crs))
@@ -261,12 +250,9 @@ func (cache *NodeSetCache) update(
return
}
-func (cache *NodeSetCache) get(
- round uint64) (nIDs *sets, exists bool) {
-
+func (cache *NodeSetCache) get(round uint64) (nIDs *sets, exists bool) {
cache.lock.RLock()
defer cache.lock.RUnlock()
-
nIDs, exists = cache.rounds[round]
return
}