From 6ab10aadc24193b1366bb1f048b92c1a6aec4861 Mon Sep 17 00:00:00 2001 From: Mission Liao Date: Fri, 19 Apr 2019 12:03:31 +0800 Subject: 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 --- core/utils/utils.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'core/utils/utils.go') 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 +} -- cgit