diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-11-18 22:29:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-18 22:29:39 +0800 |
commit | 14e7fb10da9160d01f6dda0b86eaf7fe99d40a79 (patch) | |
tree | 81c931fccf1e981cfbd46dbfb3106a010882edba /core | |
parent | 591c80dbe9dbdea4cec202b07f4da081020f964a (diff) | |
download | dexon-consensus-14e7fb10da9160d01f6dda0b86eaf7fe99d40a79.tar dexon-consensus-14e7fb10da9160d01f6dda0b86eaf7fe99d40a79.tar.gz dexon-consensus-14e7fb10da9160d01f6dda0b86eaf7fe99d40a79.tar.bz2 dexon-consensus-14e7fb10da9160d01f6dda0b86eaf7fe99d40a79.tar.lz dexon-consensus-14e7fb10da9160d01f6dda0b86eaf7fe99d40a79.tar.xz dexon-consensus-14e7fb10da9160d01f6dda0b86eaf7fe99d40a79.tar.zst dexon-consensus-14e7fb10da9160d01f6dda0b86eaf7fe99d40a79.zip |
core: Handle issues if DKG/CRS is already finished (#334)
Diffstat (limited to 'core')
-rw-r--r-- | core/configuration-chain.go | 21 | ||||
-rw-r--r-- | core/consensus.go | 43 | ||||
-rw-r--r-- | core/consensus_test.go | 2 |
3 files changed, 28 insertions, 38 deletions
diff --git a/core/configuration-chain.go b/core/configuration-chain.go index 47a40b1..fdfcd13 100644 --- a/core/configuration-chain.go +++ b/core/configuration-chain.go @@ -107,6 +107,10 @@ func (cc *configurationChain) runDKG(round uint64) error { cc.dkgLock.Lock() defer cc.dkgLock.Unlock() if cc.dkg == nil || cc.dkg.round != round { + if cc.dkg != nil && cc.dkg.round > round { + cc.logger.Warn("DKG canceled", "round", round) + return nil + } return ErrDKGNotRegistered } if func() bool { @@ -117,6 +121,11 @@ func (cc *configurationChain) runDKG(round uint64) error { }() { return nil } + cc.logger.Debug("Calling Governance.IsDKGFinal", "round", round) + if cc.gov.IsDKGFinal(round) { + cc.logger.Warn("DKG already final", "round", round) + return nil + } ticker := newTicker(cc.gov, round, TickerDKG) cc.dkgLock.Unlock() @@ -183,10 +192,6 @@ func (cc *configurationChain) runDKG(round uint64) error { if err != nil { return err } - signer, err := cc.dkg.recoverShareSecret(gpk.qualifyIDs) - if err != nil { - return err - } qualifies := "" for nID := range gpk.qualifyNodeIDs { qualifies += fmt.Sprintf("%s ", nID.String()[:6]) @@ -196,6 +201,14 @@ func (cc *configurationChain) runDKG(round uint64) error { "round", round, "count", len(gpk.qualifyIDs), "qualifies", qualifies) + if _, exist := gpk.qualifyNodeIDs[cc.ID]; !exist { + cc.logger.Warn("Self is not in Qualify Nodes") + return nil + } + signer, err := cc.dkg.recoverShareSecret(gpk.qualifyIDs) + if err != nil { + return err + } cc.dkgResult.Lock() defer cc.dkgResult.Unlock() cc.dkgSigner[round] = signer diff --git a/core/consensus.go b/core/consensus.go index 251f475..d5a386d 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -443,7 +443,7 @@ func (con *Consensus) Run(initBlock *types.Block) { con.cfgModule.registerDKG(initRound, int(initConfig.DKGSetSize)/3+1) con.event.RegisterTime(con.dMoment.Add(initConfig.RoundInterval/4), func(time.Time) { - con.runDKGTSIG(initRound, initConfig) + con.runDKG(initRound, initConfig) }) } con.initialRound(con.dMoment, initRound, initConfig) @@ -547,8 +547,8 @@ BALoop: } } -// runDKGTSIG starts running DKG+TSIG protocol. -func (con *Consensus) runDKGTSIG(round uint64, config *types.Config) { +// runDKG starts running DKG protocol. +func (con *Consensus) runDKG(round uint64, config *types.Config) { con.dkgReady.L.Lock() defer con.dkgReady.L.Unlock() if con.dkgRunning != 0 { @@ -572,39 +572,16 @@ func (con *Consensus) runDKGTSIG(round uint64, config *types.Config) { if err := con.cfgModule.runDKG(round); err != nil { panic(err) } - nodes, err := con.nodeSetCache.GetNodeSet(round) - if err != nil { - panic(err) - } - con.logger.Debug("Calling Governance.Configuration", "round", round) - hash := HashConfigurationBlock( - nodes.IDs, - con.gov.Configuration(round), - common.Hash{}, - con.cfgModule.prevHash) - psig, err := con.cfgModule.preparePartialSignature( - round, hash) - if err != nil { - panic(err) - } - if err = con.authModule.SignDKGPartialSignature(psig); err != nil { - panic(err) - } - if err = con.cfgModule.processPartialSignature(psig); err != nil { - panic(err) - } - con.logger.Debug("Calling Network.BroadcastDKGPartialSignature", - "proposer", psig.ProposerID, - "round", psig.Round, - "hash", psig.Hash) - con.network.BroadcastDKGPartialSignature(psig) - if _, err = con.cfgModule.runBlockTSig(round, hash); err != nil { - panic(err) - } }() } func (con *Consensus) runCRS(round uint64) { + con.logger.Debug("Calling Governance.CRS to check if already proposed", + "round", round+1) + if (con.gov.CRS(round+1) != common.Hash{}) { + con.logger.Info("CRS already proposed", "round", round+1) + return + } // Start running next round CRS. con.logger.Debug("Calling Governance.CRS", "round", round) psig, err := con.cfgModule.preparePartialSignature(round, con.gov.CRS(round)) @@ -689,7 +666,7 @@ func (con *Consensus) initialRound( con.logger.Debug("Calling Governance.Configuration", "round", nextRound) nextConfig := con.gov.Configuration(nextRound) - con.runDKGTSIG(nextRound, nextConfig) + con.runDKG(nextRound, nextConfig) }) }(round + 1) }) diff --git a/core/consensus_test.go b/core/consensus_test.go index a55d708..802182a 100644 --- a/core/consensus_test.go +++ b/core/consensus_test.go @@ -522,7 +522,7 @@ func (s *ConsensusTestSuite) TestDKGCRS() { con.cfgModule.registerDKG(uint64(0), n/3+1) } for _, con := range cons { - con.runDKGTSIG(0, gov.Configuration(0)) + con.runDKG(0, gov.Configuration(0)) } for _, con := range cons { func() { |