aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/types/nodeset.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-01-04 16:24:26 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:21 +0800
commit9a8e616df90409e1a94b7843d1ceddcf010bc11b (patch)
tree9ee2a492ea8c5406bf7df078b1b2f028af1d65a7 /vendor/github.com/dexon-foundation/dexon-consensus/core/types/nodeset.go
parentb92aa8f1590c3ecb1e2fe8ba12a5092ca190786c (diff)
downloadgo-tangerine-9a8e616df90409e1a94b7843d1ceddcf010bc11b.tar
go-tangerine-9a8e616df90409e1a94b7843d1ceddcf010bc11b.tar.gz
go-tangerine-9a8e616df90409e1a94b7843d1ceddcf010bc11b.tar.bz2
go-tangerine-9a8e616df90409e1a94b7843d1ceddcf010bc11b.tar.lz
go-tangerine-9a8e616df90409e1a94b7843d1ceddcf010bc11b.tar.xz
go-tangerine-9a8e616df90409e1a94b7843d1ceddcf010bc11b.tar.zst
go-tangerine-9a8e616df90409e1a94b7843d1ceddcf010bc11b.zip
vendor: sync to latest core (#125)
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/types/nodeset.go')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/types/nodeset.go30
1 files changed, 17 insertions, 13 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/nodeset.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/nodeset.go
index 89dfef3fd..da615e1f0 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/nodeset.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/nodeset.go
@@ -32,7 +32,9 @@ type NodeSet struct {
}
// SubSetTarget is the sub set target for GetSubSet().
-type SubSetTarget *big.Int
+type SubSetTarget struct {
+ data [][]byte
+}
type subSetTargetType byte
@@ -71,7 +73,7 @@ func NewNodeSet() *NodeSet {
}
// NewNotarySetTarget is the target for getting Notary Set.
-func NewNotarySetTarget(crs common.Hash, chainID uint32) SubSetTarget {
+func NewNotarySetTarget(crs common.Hash, chainID uint32) *SubSetTarget {
binaryChainID := make([]byte, 4)
binary.LittleEndian.PutUint32(binaryChainID, chainID)
@@ -79,7 +81,7 @@ func NewNotarySetTarget(crs common.Hash, chainID uint32) SubSetTarget {
}
// NewDKGSetTarget is the target for getting DKG Set.
-func NewDKGSetTarget(crs common.Hash) SubSetTarget {
+func NewDKGSetTarget(crs common.Hash) *SubSetTarget {
return newTarget(targetDKGSet, crs[:])
}
@@ -99,7 +101,7 @@ func (ns *NodeSet) Clone() *NodeSet {
// GetSubSet returns the subset of given target.
func (ns *NodeSet) GetSubSet(
- size int, target SubSetTarget) map[NodeID]struct{} {
+ size int, target *SubSetTarget) map[NodeID]struct{} {
if size == 0 {
return make(map[NodeID]struct{})
}
@@ -129,18 +131,20 @@ func (ns *NodeSet) GetSubSet(
return nIDs
}
-func newTarget(targetType subSetTargetType, data ...[]byte) SubSetTarget {
+func newTarget(targetType subSetTargetType, data ...[]byte) *SubSetTarget {
data = append(data, []byte{byte(targetType)})
- h := crypto.Keccak256Hash(data...)
- num := big.NewInt(0)
- num.SetBytes(h[:])
- return SubSetTarget(num)
+ return &SubSetTarget{
+ data: data,
+ }
}
-func newNodeRank(ID NodeID, target SubSetTarget) *nodeRank {
- num := big.NewInt(0)
- num.SetBytes(ID.Hash[:])
- num.Abs(num.Sub((*big.Int)(target), num))
+func newNodeRank(ID NodeID, target *SubSetTarget) *nodeRank {
+ data := make([][]byte, 1, len(target.data)+1)
+ data[0] = make([]byte, len(ID.Hash))
+ copy(data[0], ID.Hash[:])
+ data = append(data, target.data...)
+ h := crypto.Keccak256Hash(data...)
+ num := new(big.Int).SetBytes(h[:])
return &nodeRank{
ID: ID,
rank: num,