diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-03-29 14:31:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-29 14:31:03 +0800 |
commit | 04a4df9479e31f1418760a389060706a72259381 (patch) | |
tree | 6f09bf2646ed87627f348a2c0f66e3465d7d231a | |
parent | e3e7f4fbd840819b1ef44ae2c345f64e0bb2c161 (diff) | |
download | dexon-consensus-04a4df9479e31f1418760a389060706a72259381.tar dexon-consensus-04a4df9479e31f1418760a389060706a72259381.tar.gz dexon-consensus-04a4df9479e31f1418760a389060706a72259381.tar.bz2 dexon-consensus-04a4df9479e31f1418760a389060706a72259381.tar.lz dexon-consensus-04a4df9479e31f1418760a389060706a72259381.tar.xz dexon-consensus-04a4df9479e31f1418760a389060706a72259381.tar.zst dexon-consensus-04a4df9479e31f1418760a389060706a72259381.zip |
core: reset DKG if to less qualified nodes (#528)
-rw-r--r-- | core/configuration-chain_test.go | 6 | ||||
-rw-r--r-- | core/consensus.go | 8 | ||||
-rw-r--r-- | core/utils/utils.go | 5 |
3 files changed, 14 insertions, 5 deletions
diff --git a/core/configuration-chain_test.go b/core/configuration-chain_test.go index a4c6e2a..0adfdcf 100644 --- a/core/configuration-chain_test.go +++ b/core/configuration-chain_test.go @@ -271,7 +271,7 @@ func (s *ConfigurationChainTestSuite) preparePartialSignature( // All participants are good people in this test. func (s *ConfigurationChainTestSuite) TestConfigurationChain() { k := 4 - n := 10 + n := 7 round := DKGDelayRound reset := uint64(0) cfgChains := s.runDKG(k, n, round, reset) @@ -320,7 +320,7 @@ func (s *ConfigurationChainTestSuite) TestConfigurationChain() { func (s *ConfigurationChainTestSuite) TestDKGMasterPublicKeyDelayAdd() { k := 4 - n := 10 + n := 7 round := DKGDelayRound reset := uint64(0) lambdaDKG := 1000 * time.Millisecond @@ -387,7 +387,7 @@ func (s *ConfigurationChainTestSuite) TestDKGMasterPublicKeyDelayAdd() { func (s *ConfigurationChainTestSuite) TestDKGComplaintDelayAdd() { k := 4 - n := 10 + n := 7 round := DKGDelayRound reset := uint64(0) lambdaDKG := 1000 * time.Millisecond diff --git a/core/consensus.go b/core/consensus.go index 6d0f683..2246bf1 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -849,17 +849,21 @@ func (con *Consensus) prepare(initBlock *types.Block) (err error) { "reset", e.Reset) return false } - if _, err := typesDKG.NewGroupPublicKey( + gpk, err := typesDKG.NewGroupPublicKey( nextRound, con.gov.DKGMasterPublicKeys(nextRound), con.gov.DKGComplaints(nextRound), - utils.GetDKGThreshold(nextConfig)); err != nil { + 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) { diff --git a/core/utils/utils.go b/core/utils/utils.go index fcdf422..9a4ae92 100644 --- a/core/utils/utils.go +++ b/core/utils/utils.go @@ -139,6 +139,11 @@ func GetDKGThreshold(config *types.Config) int { return int(config.NotarySetSize*2/3) + 1 } +// GetDKGValidThreshold return threshold for DKG set to considered valid. +func GetDKGValidThreshold(config *types.Config) int { + return int(config.NotarySetSize * 5 / 6) +} + // GetNextRoundValidationHeight returns the block height to check if the next // round is ready. func GetNextRoundValidationHeight(begin, length uint64) uint64 { |