diff options
Diffstat (limited to 'core/test/governance.go')
-rw-r--r-- | core/test/governance.go | 29 |
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 { |