diff options
author | Mission Liao <mission.liao@dexon.org> | 2019-04-19 12:03:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-19 12:03:31 +0800 |
commit | 6ab10aadc24193b1366bb1f048b92c1a6aec4861 (patch) | |
tree | dbf9326697eba33823b5af2f03e4a282b2306a00 /core/utils/utils.go | |
parent | 7ba4eb6eb78ec3ca431b216603987aaa8ce7df48 (diff) | |
download | dexon-consensus-6ab10aadc24193b1366bb1f048b92c1a6aec4861.tar dexon-consensus-6ab10aadc24193b1366bb1f048b92c1a6aec4861.tar.gz dexon-consensus-6ab10aadc24193b1366bb1f048b92c1a6aec4861.tar.bz2 dexon-consensus-6ab10aadc24193b1366bb1f048b92c1a6aec4861.tar.lz dexon-consensus-6ab10aadc24193b1366bb1f048b92c1a6aec4861.tar.xz dexon-consensus-6ab10aadc24193b1366bb1f048b92c1a6aec4861.tar.zst dexon-consensus-6ab10aadc24193b1366bb1f048b92c1a6aec4861.zip |
utils: fix logic to trigger round events (#575)
Merge the code to check if DKG valid in:
- trigger next round event
- check if resetting DKG is required
Diffstat (limited to 'core/utils/utils.go')
-rw-r--r-- | core/utils/utils.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/core/utils/utils.go b/core/utils/utils.go index dc29bdf..f259f34 100644 --- a/core/utils/utils.go +++ b/core/utils/utils.go @@ -167,3 +167,41 @@ func GetRoundHeight(accessor interface{}, round uint64) uint64 { } return height } + +// IsDKGValid check if DKG is correctly prepared. +func IsDKGValid( + gov governanceAccessor, logger common.Logger, round, reset uint64) ( + valid bool, gpkInvalid bool) { + if !gov.IsDKGFinal(round) { + logger.Debug("DKG is not final", "round", round, "reset", reset) + return + } + if !gov.IsDKGSuccess(round) { + logger.Debug("DKG is not successful", "round", round, "reset", reset) + return + } + cfg := GetConfigWithPanic(gov, round, logger) + gpk, err := typesDKG.NewGroupPublicKey( + round, + gov.DKGMasterPublicKeys(round), + gov.DKGComplaints(round), + GetDKGThreshold(cfg)) + if err != nil { + logger.Debug("Group public key setup failed", + "round", round, + "reset", reset, + "error", err) + gpkInvalid = true + return + } + if len(gpk.QualifyNodeIDs) < GetDKGValidThreshold(cfg) { + logger.Debug("Group public key threshold not reach", + "round", round, + "reset", reset, + "qualified", len(gpk.QualifyNodeIDs)) + gpkInvalid = true + return + } + valid = true + return +} |