aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-19 13:53:20 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-15 22:09:56 +0800
commit8e1194d60b89df925b7d5b53395d0949df4bd4f8 (patch)
tree760146083586068d791ce84a1fe6951c62595345 /vendor/github.com/dexon-foundation
parent3f433c2137aaf4cd972009cf61bf325f6a1ad2d3 (diff)
downloadgo-tangerine-8e1194d60b89df925b7d5b53395d0949df4bd4f8.tar
go-tangerine-8e1194d60b89df925b7d5b53395d0949df4bd4f8.tar.gz
go-tangerine-8e1194d60b89df925b7d5b53395d0949df4bd4f8.tar.bz2
go-tangerine-8e1194d60b89df925b7d5b53395d0949df4bd4f8.tar.lz
go-tangerine-8e1194d60b89df925b7d5b53395d0949df4bd4f8.tar.xz
go-tangerine-8e1194d60b89df925b7d5b53395d0949df4bd4f8.tar.zst
go-tangerine-8e1194d60b89df925b7d5b53395d0949df4bd4f8.zip
vendor: sync to latest core
Diffstat (limited to 'vendor/github.com/dexon-foundation')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go35
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/utils/round-event.go31
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/utils/utils.go38
3 files changed, 51 insertions, 53 deletions
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
+}