diff options
Diffstat (limited to 'simulation')
-rw-r--r-- | simulation/simulation.go | 24 | ||||
-rw-r--r-- | simulation/validator.go | 6 |
2 files changed, 21 insertions, 9 deletions
diff --git a/simulation/simulation.go b/simulation/simulation.go index 27e31d2..6730b96 100644 --- a/simulation/simulation.go +++ b/simulation/simulation.go @@ -20,8 +20,7 @@ package simulation import ( "fmt" - "github.com/dexon-foundation/dexon-consensus-core/common" - "github.com/dexon-foundation/dexon-consensus-core/core/types" + "github.com/dexon-foundation/dexon-consensus-core/crypto/eth" "github.com/dexon-foundation/dexon-consensus-core/simulation/config" ) @@ -50,15 +49,21 @@ func Run(configPath string) { network = NewFakeNetwork(networkModel) for i := 0; i < cfg.Validator.Num; i++ { - id := types.ValidatorID{Hash: common.NewRandomHash()} - vs = append(vs, NewValidator(id, cfg.Validator, network)) + prv, err := eth.NewPrivateKey() + if err != nil { + panic(err) + } + vs = append(vs, NewValidator(prv, cfg.Validator, network)) } } else if networkType == config.NetworkTypeTCPLocal { for i := 0; i < cfg.Validator.Num; i++ { - id := types.ValidatorID{Hash: common.NewRandomHash()} + prv, err := eth.NewPrivateKey() + if err != nil { + panic(err) + } network := NewTCPNetwork(true, cfg.Networking.PeerServer) go network.Start() - vs = append(vs, NewValidator(id, cfg.Validator, network)) + vs = append(vs, NewValidator(prv, cfg.Validator, network)) } } @@ -67,10 +72,13 @@ func Run(configPath string) { go vs[i].Run() } } else if networkType == config.NetworkTypeTCP { - id := types.ValidatorID{Hash: common.NewRandomHash()} + prv, err := eth.NewPrivateKey() + if err != nil { + panic(err) + } network := NewTCPNetwork(false, cfg.Networking.PeerServer) go network.Start() - v := NewValidator(id, cfg.Validator, network) + v := NewValidator(prv, cfg.Validator, network) go v.Run() vs = append(vs, v) } diff --git a/simulation/validator.go b/simulation/validator.go index 246d0d3..c5bbe15 100644 --- a/simulation/validator.go +++ b/simulation/validator.go @@ -25,6 +25,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core" "github.com/dexon-foundation/dexon-consensus-core/core/types" + "github.com/dexon-foundation/dexon-consensus-core/crypto" "github.com/dexon-foundation/dexon-consensus-core/simulation/config" ) @@ -40,16 +41,19 @@ type Validator struct { isFinished chan struct{} ID types.ValidatorID + privateKey crypto.PrivateKey consensus *core.Consensus compactionChain *core.BlockChain } // NewValidator returns a new empty validator. func NewValidator( - id types.ValidatorID, + prvKey crypto.PrivateKey, config config.Validator, network Network) *Validator { + id := types.NewValidatorID(prvKey.PublicKey()) + db, err := blockdb.NewMemBackedBlockDB( id.String() + ".blockdb") if err != nil { |