aboutsummaryrefslogtreecommitdiffstats
path: root/integration_test/validator.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-08-30 15:39:06 +0800
committermissionliao <38416648+missionliao@users.noreply.github.com>2018-08-30 15:39:06 +0800
commita4e0da981a3dfc8817d39be65cb5b24938b0761a (patch)
tree9c372875258bd942c30050643604d7d1448d2627 /integration_test/validator.go
parent8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8 (diff)
downloaddexon-consensus-a4e0da981a3dfc8817d39be65cb5b24938b0761a.tar
dexon-consensus-a4e0da981a3dfc8817d39be65cb5b24938b0761a.tar.gz
dexon-consensus-a4e0da981a3dfc8817d39be65cb5b24938b0761a.tar.bz2
dexon-consensus-a4e0da981a3dfc8817d39be65cb5b24938b0761a.tar.lz
dexon-consensus-a4e0da981a3dfc8817d39be65cb5b24938b0761a.tar.xz
dexon-consensus-a4e0da981a3dfc8817d39be65cb5b24938b0761a.tar.zst
dexon-consensus-a4e0da981a3dfc8817d39be65cb5b24938b0761a.zip
core: Change the lattice key from validatorID to chainID. (#83)
* Add chainID in simulation.Validator * Change validatorid to chainID in rbModule
Diffstat (limited to 'integration_test/validator.go')
-rw-r--r--integration_test/validator.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/integration_test/validator.go b/integration_test/validator.go
index 2cb7e43..60c6b1f 100644
--- a/integration_test/validator.go
+++ b/integration_test/validator.go
@@ -19,9 +19,11 @@ package integration
import (
"fmt"
+ "sort"
"time"
"github.com/dexon-foundation/dexon-consensus-core/blockdb"
+ "github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core"
"github.com/dexon-foundation/dexon-consensus-core/core/test"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
@@ -63,6 +65,7 @@ func NewReceiveBlockEvent(
// Validator is designed to work with test.Scheduler.
type Validator struct {
ID types.ValidatorID
+ chainID uint64
cons *core.Consensus
gov core.Governance
networkLatency LatencyModel
@@ -79,8 +82,22 @@ func NewValidator(
networkLatency LatencyModel,
proposingLatency LatencyModel) *Validator {
+ hashes := make(common.Hashes, 0)
+ for vID := range gov.GetValidatorSet() {
+ hashes = append(hashes, vID.Hash)
+ }
+ sort.Sort(hashes)
+ chainID := uint64(0)
+ for i, hash := range hashes {
+ if hash == vID.Hash {
+ chainID = uint64(i)
+ break
+ }
+ }
+
return &Validator{
ID: vID,
+ chainID: chainID,
gov: gov,
networkLatency: networkLatency,
proposingLatency: proposingLatency,
@@ -106,7 +123,10 @@ func (v *Validator) Handle(e *test.Event) (events []*test.Event) {
func (v *Validator) handleProposeBlock(when time.Time, piggyback interface{}) (
events []*test.Event, err error) {
- b := &types.Block{ProposerID: v.ID}
+ b := &types.Block{
+ ProposerID: v.ID,
+ ChainID: v.chainID,
+ }
defer types.RecycleBlock(b)
if err = v.cons.PrepareBlock(b, when); err != nil {
return