aboutsummaryrefslogtreecommitdiffstats
path: root/core/utils
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
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')
-rw-r--r--core/utils/crypto.go4
-rw-r--r--core/utils/nodeset-cache.go22
-rw-r--r--core/utils/nodeset-cache_test.go10
-rw-r--r--core/utils/signer_test.go12
4 files changed, 14 insertions, 34 deletions
diff --git a/core/utils/crypto.go b/core/utils/crypto.go
index 43bbde1..fe67a95 100644
--- a/core/utils/crypto.go
+++ b/core/utils/crypto.go
@@ -140,9 +140,6 @@ func VerifyCRSSignature(block *types.Block, crs common.Hash) (
}
func hashPosition(position types.Position) common.Hash {
- binaryChainID := make([]byte, 4)
- binary.LittleEndian.PutUint32(binaryChainID, position.ChainID)
-
binaryRound := make([]byte, 8)
binary.LittleEndian.PutUint64(binaryRound, position.Round)
@@ -150,7 +147,6 @@ func hashPosition(position types.Position) common.Hash {
binary.LittleEndian.PutUint64(binaryHeight, position.Height)
return crypto.Keccak256Hash(
- binaryChainID,
binaryRound,
binaryHeight,
)
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
}
diff --git a/core/utils/nodeset-cache_test.go b/core/utils/nodeset-cache_test.go
index eb6008d..52036b5 100644
--- a/core/utils/nodeset-cache_test.go
+++ b/core/utils/nodeset-cache_test.go
@@ -38,9 +38,8 @@ func (g *nsIntf) Configuration(round uint64) (cfg *types.Config) {
return &types.Config{
NotarySetSize: 7,
DKGSetSize: 7,
- NumChains: 4,
+ RoundInterval: 60,
LambdaBA: 250 * time.Millisecond,
- RoundInterval: 60 * time.Second,
MinBlockInterval: 1 * time.Second,
}
}
@@ -89,16 +88,15 @@ func (s *NodeSetCacheTestSuite) TestBasicUsage() {
nodeSet0, err := cache.GetNodeSet(0)
req.NoError(err)
chk(cache, 0, nodeSet0.IDs)
- notarySet, err := cache.GetNotarySet(0, 0)
+ notarySet, err := cache.GetNotarySet(0)
req.NoError(err)
chk(cache, 0, notarySet)
dkgSet, err := cache.GetDKGSet(0)
req.NoError(err)
chk(cache, 0, dkgSet)
leaderNode, err := cache.GetLeaderNode(types.Position{
- Round: uint64(0),
- ChainID: uint32(0),
- Height: uint64(10),
+ Round: uint64(0),
+ Height: uint64(10),
})
req.NoError(err)
chk(cache, 0, map[types.NodeID]struct{}{
diff --git a/core/utils/signer_test.go b/core/utils/signer_test.go
index 8e34b98..3905352 100644
--- a/core/utils/signer_test.go
+++ b/core/utils/signer_test.go
@@ -42,8 +42,8 @@ func (s *SignerTestSuite) TestBlock() {
b := &types.Block{
ParentHash: common.NewRandomHash(),
Position: types.Position{
- ChainID: 2,
- Height: 3,
+ Round: 2,
+ Height: 3,
},
Timestamp: time.Now().UTC(),
}
@@ -55,8 +55,8 @@ func (s *SignerTestSuite) TestVote() {
k := s.setupSigner()
v := types.NewVote(types.VoteCom, common.NewRandomHash(), 123)
v.Position = types.Position{
- ChainID: 4,
- Height: 6,
+ Round: 4,
+ Height: 6,
}
v.ProposerID = types.NodeID{Hash: common.NewRandomHash()}
s.NoError(k.SignVote(v))
@@ -70,8 +70,8 @@ func (s *SignerTestSuite) TestCRS() {
b := &types.Block{
ParentHash: common.NewRandomHash(),
Position: types.Position{
- ChainID: 8,
- Height: 9,
+ Round: 8,
+ Height: 9,
},
Timestamp: time.Now().UTC(),
}