aboutsummaryrefslogtreecommitdiffstats
path: root/core/utils
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-02 14:15:51 +0800
committerGitHub <noreply@github.com>2019-04-02 14:15:51 +0800
commit35f3fe0b857e8006de345505d7fc09c0b7c10326 (patch)
tree2c4383122604620caeace6d225f8035f43d3b792 /core/utils
parent7e85e9475ef303356ccdbcbfe8219ac1173db418 (diff)
downloaddexon-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')
-rw-r--r--core/utils/nodeset-cache.go38
-rw-r--r--core/utils/nodeset-cache_test.go8
-rw-r--r--core/utils/utils.go5
3 files changed, 11 insertions, 40 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))
diff --git a/core/utils/nodeset-cache_test.go b/core/utils/nodeset-cache_test.go
index 0ee3883..b9052c8 100644
--- a/core/utils/nodeset-cache_test.go
+++ b/core/utils/nodeset-cache_test.go
@@ -90,14 +90,6 @@ func (s *NodeSetCacheTestSuite) TestBasicUsage() {
notarySet, err := cache.GetNotarySet(0)
req.NoError(err)
chk(cache, 0, notarySet)
- leaderNode, err := cache.GetLeaderNode(types.Position{
- Round: uint64(0),
- Height: uint64(10),
- })
- req.NoError(err)
- chk(cache, 0, map[types.NodeID]struct{}{
- leaderNode: struct{}{},
- })
// Try to get round 1.
nodeSet1, err := cache.GetNodeSet(1)
req.NoError(err)
diff --git a/core/utils/utils.go b/core/utils/utils.go
index e6739ce..1a372c7 100644
--- a/core/utils/utils.go
+++ b/core/utils/utils.go
@@ -144,6 +144,11 @@ func GetDKGValidThreshold(config *types.Config) int {
return int(config.NotarySetSize * 5 / 6)
}
+// GetBAThreshold return threshold for BA votes.
+func GetBAThreshold(config *types.Config) int {
+ return int(config.NotarySetSize*2/3 + 1)
+}
+
// GetNextRoundValidationHeight returns the block height to check if the next
// round is ready.
func GetNextRoundValidationHeight(begin, length uint64) uint64 {