From 8e1194d60b89df925b7d5b53395d0949df4bd4f8 Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Fri, 19 Apr 2019 13:53:20 +0800 Subject: vendor: sync to latest core --- .../dexon-consensus/core/consensus.go | 35 ++------------------ .../dexon-consensus/core/utils/round-event.go | 31 +++++++----------- .../dexon-consensus/core/utils/utils.go | 38 ++++++++++++++++++++++ 3 files changed, 51 insertions(+), 53 deletions(-) (limited to 'vendor/github.com') diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go index e7449c222..3443c9676 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go @@ -820,40 +820,9 @@ func (con *Consensus) prepare(initBlock *types.Block) (err error) { if _, exist := curNotarySet[con.ID]; !exist { return } - isDKGValid := func() bool { - nextConfig := utils.GetConfigWithPanic(con.gov, nextRound, - con.logger) - if !con.gov.IsDKGFinal(nextRound) { - con.logger.Error("Next DKG is not final, reset it", - "round", e.Round, - "reset", e.Reset) - return false - } - if !con.gov.IsDKGSuccess(nextRound) { - con.logger.Error("Next DKG is not success, reset it", - "round", e.Round, - "reset", e.Reset) - return false - } - gpk, err := typesDKG.NewGroupPublicKey( - nextRound, - con.gov.DKGMasterPublicKeys(nextRound), - con.gov.DKGComplaints(nextRound), - utils.GetDKGThreshold(nextConfig)) - if err != nil { - con.logger.Error("Next DKG failed to prepare, reset it", - "round", e.Round, - "reset", e.Reset, - "error", err) - return false - } - if len(gpk.QualifyNodeIDs) < utils.GetDKGValidThreshold(nextConfig) { - return false - } - return true - } con.event.RegisterHeight(e.NextDKGResetHeight(), func(uint64) { - if isDKGValid() { + if ok, _ := utils.IsDKGValid( + con.gov, con.logger, nextRound, e.Reset); ok { return } // Aborting all previous running DKG protocol instance if any. diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/round-event.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/round-event.go index b1d4d230e..bda4383fa 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/round-event.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/round-event.go @@ -127,6 +127,9 @@ type governanceAccessor interface { // IsDKGFinal checks if DKG is final. IsDKGFinal(round uint64) bool + // IsDKGSuccess checks if DKG is success. + IsDKGSuccess(round uint64) bool + // DKGResetCount returns the reset count for DKG of given round. DKGResetCount(round uint64) uint64 @@ -162,7 +165,7 @@ type RoundEvent struct { lastTriggeredRound uint64 lastTriggeredResetCount uint64 roundShift uint64 - dkgFailed bool + gpkInvalid bool ctx context.Context ctxCancel context.CancelFunc } @@ -309,40 +312,28 @@ func (e *RoundEvent) check(blockHeight, startRound uint64) ( if resetCount > e.lastTriggeredResetCount { e.lastTriggeredResetCount++ e.config.ExtendLength() - e.dkgFailed = false + e.gpkInvalid = false triggered = true return } - if e.dkgFailed { + if e.gpkInvalid { // We know that DKG already failed, now wait for the DKG set from // previous round to reset DKG and don't have to reconstruct the // group public key again. return } if nextRound >= dkgDelayRound { - if !e.gov.IsDKGFinal(nextRound) { - e.logger.Debug("DKG is not final, waiting for DKG reset", - "round", nextRound, - "reset", e.lastTriggeredResetCount) - return - } - if _, err := typesDKG.NewGroupPublicKey( - nextRound, - e.gov.DKGMasterPublicKeys(nextRound), - e.gov.DKGComplaints(nextRound), - GetDKGThreshold(nextCfg)); err != nil { - e.logger.Debug( - "Group public key setup failed, waiting for DKG reset", - "round", nextRound, - "reset", e.lastTriggeredResetCount) - e.dkgFailed = true + var ok bool + ok, e.gpkInvalid = IsDKGValid( + e.gov, e.logger, nextRound, e.lastTriggeredResetCount) + if !ok { return } } // The DKG set for next round is well prepared. e.lastTriggeredRound = nextRound e.lastTriggeredResetCount = 0 - e.dkgFailed = false + e.gpkInvalid = false rCfg := RoundBasedConfig{} rCfg.SetupRoundBasedFields(nextRound, nextCfg) rCfg.AppendTo(e.config) 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 +} -- cgit v1.2.3