aboutsummaryrefslogtreecommitdiffstats
path: root/simulation
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-09-19 15:00:11 +0800
committerGitHub <noreply@github.com>2018-09-19 15:00:11 +0800
commit54fa224dbbf1b1c0f8d54a3f10a81adb321ce1e4 (patch)
treeb0e503e08cc52dae2536ebef3dcd0110edd1b333 /simulation
parent8c33027b943e08de21b7bddb82fecc2b2a5664a2 (diff)
downloadtangerine-consensus-54fa224dbbf1b1c0f8d54a3f10a81adb321ce1e4.tar
tangerine-consensus-54fa224dbbf1b1c0f8d54a3f10a81adb321ce1e4.tar.gz
tangerine-consensus-54fa224dbbf1b1c0f8d54a3f10a81adb321ce1e4.tar.bz2
tangerine-consensus-54fa224dbbf1b1c0f8d54a3f10a81adb321ce1e4.tar.lz
tangerine-consensus-54fa224dbbf1b1c0f8d54a3f10a81adb321ce1e4.tar.xz
tangerine-consensus-54fa224dbbf1b1c0f8d54a3f10a81adb321ce1e4.tar.zst
tangerine-consensus-54fa224dbbf1b1c0f8d54a3f10a81adb321ce1e4.zip
core:DKG and TSIG protocol (#115)
Diffstat (limited to 'simulation')
-rw-r--r--simulation/governance.go17
-rw-r--r--simulation/network.go10
-rw-r--r--simulation/validator.go7
3 files changed, 31 insertions, 3 deletions
diff --git a/simulation/governance.go b/simulation/governance.go
index ebfd32b..159d536 100644
--- a/simulation/governance.go
+++ b/simulation/governance.go
@@ -29,6 +29,7 @@ import (
// simGovernance is a simulated governance contract implementing the
// core.Governance interface.
type simGovernance struct {
+ id types.ValidatorID
lock sync.RWMutex
notarySet map[types.ValidatorID]struct{}
expectedNumValidators int
@@ -39,12 +40,15 @@ type simGovernance struct {
dkgComplaint map[uint64][]*types.DKGComplaint
dkgMasterPublicKey map[uint64][]*types.DKGMasterPublicKey
lambda time.Duration
+ network *network
}
// newSimGovernance returns a new simGovernance instance.
func newSimGovernance(
+ id types.ValidatorID,
numValidators int, consensusConfig config.Consensus) *simGovernance {
return &simGovernance{
+ id: id,
notarySet: make(map[types.ValidatorID]struct{}),
expectedNumValidators: numValidators,
k: consensusConfig.K,
@@ -57,9 +61,12 @@ func newSimGovernance(
}
}
+func (g *simGovernance) setNetwork(network *network) {
+ g.network = network
+}
+
// GetNotarySet returns the current notary set.
func (g *simGovernance) GetNotarySet() map[types.ValidatorID]struct{} {
-
g.lock.RLock()
defer g.lock.RUnlock()
@@ -99,8 +106,12 @@ func (g *simGovernance) addValidator(vID types.ValidatorID) {
// AddDKGComplaint adds a DKGComplaint.
func (g *simGovernance) AddDKGComplaint(complaint *types.DKGComplaint) {
+ // TODO(jimmy-dexon): check if the input is valid.
g.dkgComplaint[complaint.Round] = append(
g.dkgComplaint[complaint.Round], complaint)
+ if complaint.ProposerID == g.id {
+ g.network.broadcast(complaint)
+ }
}
// DKGComplaints returns the DKGComplaints of round.
@@ -115,8 +126,12 @@ func (g *simGovernance) DKGComplaints(round uint64) []*types.DKGComplaint {
// AddDKGMasterPublicKey adds a DKGMasterPublicKey.
func (g *simGovernance) AddDKGMasterPublicKey(
masterPublicKey *types.DKGMasterPublicKey) {
+ // TODO(jimmy-dexon): check if the input is valid.
g.dkgMasterPublicKey[masterPublicKey.Round] = append(
g.dkgMasterPublicKey[masterPublicKey.Round], masterPublicKey)
+ if masterPublicKey.ProposerID == g.id {
+ g.network.broadcast(masterPublicKey)
+ }
}
// DKGMasterPublicKeys returns the DKGMasterPublicKeys of round.
diff --git a/simulation/network.go b/simulation/network.go
index 89b4f59..83c4daf 100644
--- a/simulation/network.go
+++ b/simulation/network.go
@@ -138,6 +138,13 @@ func (n *network) BroadcastNotaryAck(notaryAck *types.NotaryAck) {
}
}
+// broadcast message to all other validators in the network.
+func (n *network) broadcast(message interface{}) {
+ if err := n.trans.Broadcast(message); err != nil {
+ panic(err)
+ }
+}
+
// SendDKGPrivateShare implements core.Network interface.
func (n *network) SendDKGPrivateShare(
recv types.ValidatorID, prvShare *types.DKGPrivateShare) {
@@ -181,7 +188,8 @@ func (n *network) run() {
// to consensus or validator, that's the question.
disp := func(e *test.TransportEnvelope) {
switch e.Msg.(type) {
- case *types.Block, *types.Vote, *types.NotaryAck:
+ case *types.Block, *types.Vote, *types.NotaryAck,
+ *types.DKGPrivateShare, *types.DKGPartialSignature:
n.toConsensus <- e.Msg
default:
n.toValidator <- e.Msg
diff --git a/simulation/validator.go b/simulation/validator.go
index 12ff308..1662dc0 100644
--- a/simulation/validator.go
+++ b/simulation/validator.go
@@ -58,7 +58,7 @@ func newValidator(
if err != nil {
panic(err)
}
- gov := newSimGovernance(config.Validator.Num, config.Validator.Consensus)
+ gov := newSimGovernance(id, config.Validator.Num, config.Validator.Consensus)
return &validator{
ID: id,
prvKey: prvKey,
@@ -85,6 +85,7 @@ func (v *validator) run(serverEndpoint interface{}, legacy bool) {
msgChannel := v.netModule.receiveChanForValidator()
peers := v.netModule.peers()
go v.netModule.run()
+ v.gov.setNetwork(v.netModule)
// Run consensus.
hashes := make(common.Hashes, 0, len(peers))
for vID := range peers {
@@ -115,6 +116,10 @@ MainLoop:
if val == statusShutdown {
break MainLoop
}
+ case *types.DKGComplaint:
+ v.gov.AddDKGComplaint(val)
+ case *types.DKGMasterPublicKey:
+ v.gov.AddDKGMasterPublicKey(val)
default:
panic(fmt.Errorf("unexpected message from server: %v", val))
}