aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-03-12 15:31:10 +0800
committerGitHub <noreply@github.com>2019-03-12 15:31:10 +0800
commit0cbdfa83622dbd396a2ccfe29b0e6d7958238180 (patch)
tree3dabbe9e3e2c0616dae5eb7225c8902b63addeff
parentbdd9130c05828a158cb8088eec3561f8b1d0f956 (diff)
downloadtangerine-consensus-0cbdfa83622dbd396a2ccfe29b0e6d7958238180.tar
tangerine-consensus-0cbdfa83622dbd396a2ccfe29b0e6d7958238180.tar.gz
tangerine-consensus-0cbdfa83622dbd396a2ccfe29b0e6d7958238180.tar.bz2
tangerine-consensus-0cbdfa83622dbd396a2ccfe29b0e6d7958238180.tar.lz
tangerine-consensus-0cbdfa83622dbd396a2ccfe29b0e6d7958238180.tar.xz
tangerine-consensus-0cbdfa83622dbd396a2ccfe29b0e6d7958238180.tar.zst
tangerine-consensus-0cbdfa83622dbd396a2ccfe29b0e6d7958238180.zip
core: recoverDKGInfo return partial result (#485)
-rw-r--r--core/configuration-chain.go67
1 files changed, 46 insertions, 21 deletions
diff --git a/core/configuration-chain.go b/core/configuration-chain.go
index 9e8df6b..faea49f 100644
--- a/core/configuration-chain.go
+++ b/core/configuration-chain.go
@@ -287,33 +287,58 @@ func (cc *configurationChain) getDKGInfo(
}
func (cc *configurationChain) recoverDKGInfo(round uint64) error {
- cc.dkgResult.Lock()
- defer cc.dkgResult.Unlock()
- _, signerExists := cc.dkgSigner[round]
- _, npksExists := cc.npks[round]
+ var npksExists, signerExists bool
+ func() {
+ cc.dkgResult.Lock()
+ defer cc.dkgResult.Unlock()
+ _, signerExists = cc.dkgSigner[round]
+ _, npksExists = cc.npks[round]
+ }()
if signerExists && npksExists {
return nil
}
if !cc.gov.IsDKGFinal(round) {
return ErrDKGNotReady
}
- // Restore group public key.
- npks, err := typesDKG.NewNodePublicKeys(round,
- cc.gov.DKGMasterPublicKeys(round),
- cc.gov.DKGComplaints(round),
- utils.GetDKGThreshold(
- utils.GetConfigWithPanic(cc.gov, round, cc.logger)))
- if err != nil {
- return err
- }
- // Check if we have private shares in DB.
- prvKey, err := cc.db.GetDKGPrivateKey(round)
- if err != nil {
- return err
- }
- cc.npks[round] = npks
- cc.dkgSigner[round] = &dkgShareSecret{
- privateKey: &prvKey,
+
+ if !npksExists {
+ threshold := utils.GetDKGThreshold(
+ utils.GetConfigWithPanic(cc.gov, round, cc.logger))
+ // Restore group public key.
+ cc.logger.Debug("Calling Governance.DKGMasterPublicKeys for recoverDKGInfo",
+ "round", round)
+ cc.logger.Debug("Calling Governance.DKGComplaints for recoverDKGInfo",
+ "round", round)
+ npks, err := typesDKG.NewNodePublicKeys(round,
+ cc.gov.DKGMasterPublicKeys(round),
+ cc.gov.DKGComplaints(round),
+ threshold)
+ if err != nil {
+ cc.logger.Warn("Failed to create DKGGroupPublicKey",
+ "round", round, "error", err)
+ return err
+ }
+ func() {
+ cc.dkgResult.Lock()
+ defer cc.dkgResult.Unlock()
+ cc.npks[round] = npks
+ }()
+ }
+ if !signerExists {
+ // Check if we have private shares in DB.
+ prvKey, err := cc.db.GetDKGPrivateKey(round)
+ if err != nil {
+ cc.logger.Warn("Failed to create DKGPrivateKey",
+ "round", round, "error", err)
+ return err
+ }
+ func() {
+ cc.dkgResult.Lock()
+ defer cc.dkgResult.Unlock()
+ cc.dkgSigner[round] = &dkgShareSecret{
+ privateKey: &prvKey,
+ }
+ }()
}
return nil
}