diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-02 14:15:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-02 14:15:51 +0800 |
commit | 35f3fe0b857e8006de345505d7fc09c0b7c10326 (patch) | |
tree | 2c4383122604620caeace6d225f8035f43d3b792 /core/utils/nodeset-cache.go | |
parent | 7e85e9475ef303356ccdbcbfe8219ac1173db418 (diff) | |
download | dexon-consensus-35f3fe0b857e8006de345505d7fc09c0b7c10326.tar dexon-consensus-35f3fe0b857e8006de345505d7fc09c0b7c10326.tar.gz dexon-consensus-35f3fe0b857e8006de345505d7fc09c0b7c10326.tar.bz2 dexon-consensus-35f3fe0b857e8006de345505d7fc09c0b7c10326.tar.lz dexon-consensus-35f3fe0b857e8006de345505d7fc09c0b7c10326.tar.xz dexon-consensus-35f3fe0b857e8006de345505d7fc09c0b7c10326.tar.zst dexon-consensus-35f3fe0b857e8006de345505d7fc09c0b7c10326.zip |
core: only qualified nodes can participant BA (#540)
* core: only qualified nodes can participant BA
* core: remove leader calculation from node set cache
Diffstat (limited to 'core/utils/nodeset-cache.go')
-rw-r--r-- | core/utils/nodeset-cache.go | 38 |
1 files changed, 6 insertions, 32 deletions
diff --git a/core/utils/nodeset-cache.go b/core/utils/nodeset-cache.go index 89ebd24..89dcfc8 100644 --- a/core/utils/nodeset-cache.go +++ b/core/utils/nodeset-cache.go @@ -36,10 +36,9 @@ var ( ) type sets struct { - crs common.Hash - nodeSet *types.NodeSet - notarySet map[types.NodeID]struct{} - leaderNode map[uint64]types.NodeID + crs common.Hash + nodeSet *types.NodeSet + notarySet map[types.NodeID]struct{} } // NodeSetCacheInterface interface specifies interface used by NodeSetCache. @@ -133,30 +132,6 @@ func (cache *NodeSetCache) GetNotarySet( return cache.cloneMap(IDs.notarySet), nil } -// GetLeaderNode returns the BA leader of the position. -func (cache *NodeSetCache) GetLeaderNode(pos types.Position) ( - types.NodeID, error) { - IDs, err := cache.getOrUpdate(pos.Round) - if err != nil { - return types.NodeID{}, err - } - cache.lock.Lock() - defer cache.lock.Unlock() - if _, exist := IDs.leaderNode[pos.Height]; !exist { - notarySet := types.NewNodeSetFromMap(IDs.notarySet) - leader := notarySet.GetSubSet(1, types.NewNodeLeaderTarget( - IDs.crs, pos.Height)) - if len(leader) != 1 { - panic(errors.New("length of leader is not one")) - } - for nID := range leader { - IDs.leaderNode[pos.Height] = nID - break - } - } - return IDs.leaderNode[pos.Height], nil -} - // Purge a specific round. func (cache *NodeSetCache) Purge(rID uint64) { cache.lock.Lock() @@ -238,10 +213,9 @@ func (cache *NodeSetCache) update(round uint64) (nIDs *sets, err error) { return } nIDs = &sets{ - crs: crs, - nodeSet: nodeSet, - notarySet: make(map[types.NodeID]struct{}), - leaderNode: make(map[uint64]types.NodeID, cfg.RoundLength), + crs: crs, + nodeSet: nodeSet, + notarySet: make(map[types.NodeID]struct{}), } nIDs.notarySet = nodeSet.GetSubSet( int(cfg.NotarySetSize), types.NewNotarySetTarget(crs)) |