aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/utils/utils.go')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/utils/utils.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/utils.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/utils.go
index dc29bdfa5..f259f34bb 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/utils.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/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
+}