aboutsummaryrefslogtreecommitdiffstats
path: root/simulation
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 /simulation
parent8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8 (diff)
downloadtangerine-consensus-a4e0da981a3dfc8817d39be65cb5b24938b0761a.tar
tangerine-consensus-a4e0da981a3dfc8817d39be65cb5b24938b0761a.tar.gz
tangerine-consensus-a4e0da981a3dfc8817d39be65cb5b24938b0761a.tar.bz2
tangerine-consensus-a4e0da981a3dfc8817d39be65cb5b24938b0761a.tar.lz
tangerine-consensus-a4e0da981a3dfc8817d39be65cb5b24938b0761a.tar.xz
tangerine-consensus-a4e0da981a3dfc8817d39be65cb5b24938b0761a.tar.zst
tangerine-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 'simulation')
-rw-r--r--simulation/validator.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/simulation/validator.go b/simulation/validator.go
index 24de155..302f3af 100644
--- a/simulation/validator.go
+++ b/simulation/validator.go
@@ -19,6 +19,7 @@ package simulation
import (
"fmt"
+ "sort"
"time"
"github.com/dexon-foundation/dexon-consensus-core/blockdb"
@@ -41,6 +42,7 @@ type Validator struct {
isFinished chan struct{}
ID types.ValidatorID
+ chainID uint64
prvKey crypto.PrivateKey
sigToPub core.SigToPubFn
consensus *core.Consensus
@@ -84,14 +86,24 @@ func (v *Validator) GetID() types.ValidatorID {
func (v *Validator) Run() {
v.msgChannel = v.network.Join(v)
+ hashes := make(common.Hashes, 0, v.network.NumPeers())
for _, vID := range v.network.Endpoints() {
v.gov.addValidator(vID)
+ hashes = append(hashes, vID.Hash)
+ }
+ sort.Sort(hashes)
+ for i, hash := range hashes {
+ if hash == v.ID.Hash {
+ v.chainID = uint64(i)
+ break
+ }
}
v.consensus = core.NewConsensus(
v.app, v.gov, v.db, v.prvKey, v.sigToPub)
genesisBlock := &types.Block{
ProposerID: v.ID,
+ ChainID: v.chainID,
}
err := v.consensus.PrepareGenesisBlock(genesisBlock, time.Now().UTC())
if err != nil {
@@ -188,6 +200,7 @@ ProposingBlockLoop:
block := &types.Block{
ProposerID: v.ID,
+ ChainID: v.chainID,
Hash: common.NewRandomHash(),
}
if err := v.consensus.PrepareBlock(block, time.Now().UTC()); err != nil {