aboutsummaryrefslogtreecommitdiffstats
path: root/simulation/governance.go
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/governance.go
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/governance.go')
-rw-r--r--simulation/governance.go17
1 files changed, 16 insertions, 1 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.