aboutsummaryrefslogtreecommitdiffstats
path: root/core/test/governance.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-12-19 17:16:40 +0800
committerGitHub <noreply@github.com>2018-12-19 17:16:40 +0800
commitc7b4045802450df361216d9e7da3ec318e67cc34 (patch)
treec4060817a54e5cf455e830b21e6a91b9fc11004f /core/test/governance.go
parent7bafefa5c70a26a28636123cb2b6598eea3ed380 (diff)
downloaddexon-consensus-c7b4045802450df361216d9e7da3ec318e67cc34.tar
dexon-consensus-c7b4045802450df361216d9e7da3ec318e67cc34.tar.gz
dexon-consensus-c7b4045802450df361216d9e7da3ec318e67cc34.tar.bz2
dexon-consensus-c7b4045802450df361216d9e7da3ec318e67cc34.tar.lz
dexon-consensus-c7b4045802450df361216d9e7da3ec318e67cc34.tar.xz
dexon-consensus-c7b4045802450df361216d9e7da3ec318e67cc34.tar.zst
dexon-consensus-c7b4045802450df361216d9e7da3ec318e67cc34.zip
core: Add a `MPKReady` so `MasterPublicKey` cannot be added afterwards (#375)
* Add type DKGReady * Add DKGReady to interface and state * DKG will wait for MPK to be ready before running * Modify test * Check if self's MPK is registered * Add test for delay add MPK * Rename Ready to MPKReady
Diffstat (limited to 'core/test/governance.go')
-rw-r--r--core/test/governance.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/core/test/governance.go b/core/test/governance.go
index 9bb042e..769934b 100644
--- a/core/test/governance.go
+++ b/core/test/governance.go
@@ -163,6 +163,9 @@ func (g *Governance) AddDKGMasterPublicKey(
if round != masterPublicKey.Round {
return
}
+ if g.IsDKGMPKReady(masterPublicKey.Round) {
+ return
+ }
if err := g.stateModule.RequestChange(
StateAddDKGMasterPublicKey, masterPublicKey); err != nil {
panic(err)
@@ -176,6 +179,32 @@ func (g *Governance) DKGMasterPublicKeys(
return g.stateModule.DKGMasterPublicKeys(round)
}
+// AddDKGMPKReady adds a DKG ready message.
+func (g *Governance) AddDKGMPKReady(round uint64, ready *typesDKG.MPKReady) {
+ if round != ready.Round {
+ return
+ }
+ if err := g.stateModule.RequestChange(StateAddDKGMPKReady, ready); err != nil {
+ panic(err)
+ }
+ g.broadcastPendingStateChanges()
+}
+
+// IsDKGMPKReady checks if DKG is ready.
+func (g *Governance) IsDKGMPKReady(round uint64) bool {
+ if round == 0 || round == 1 {
+ // Round 0, 1 are genesis round, their configs should be created
+ // by default.
+ g.CatchUpWithRound(round)
+ }
+ g.lock.RLock()
+ defer g.lock.RUnlock()
+ if round >= uint64(len(g.configs)) {
+ return false
+ }
+ return g.stateModule.IsDKGMPKReady(round, int(g.configs[round].DKGSetSize)/3*2)
+}
+
// AddDKGFinalize adds a DKG finalize message.
func (g *Governance) AddDKGFinalize(round uint64, final *typesDKG.Finalize) {
if round != final.Round {