aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-10 09:52:20 +0800
committerGitHub <noreply@github.com>2019-04-10 09:52:20 +0800
commitb9492bc09f8bb53b2a36e505ddad0d26373e71a3 (patch)
tree3c7ec50bb23f2e0275dc580fc38466c7e3e16185
parent948be08a7294e26f3b52f94f9af803f69680f9df (diff)
downloadtangerine-consensus-b9492bc09f8bb53b2a36e505ddad0d26373e71a3.tar.gz
tangerine-consensus-b9492bc09f8bb53b2a36e505ddad0d26373e71a3.tar.zst
tangerine-consensus-b9492bc09f8bb53b2a36e505ddad0d26373e71a3.zip
core: try to recover dkg private key from db (#558)
* core: try to recover dkg private key from db * fixup
-rw-r--r--core/configuration-chain.go62
1 files changed, 42 insertions, 20 deletions
diff --git a/core/configuration-chain.go b/core/configuration-chain.go
index 4a99d3d..76917a3 100644
--- a/core/configuration-chain.go
+++ b/core/configuration-chain.go
@@ -580,31 +580,31 @@ func (cc *configurationChain) recoverDKGInfo(
return ErrDKGNotReady
}
+ threshold := utils.GetDKGThreshold(
+ utils.GetConfigWithPanic(cc.gov, round, cc.logger))
+ cc.logger.Debug("Calling Governance.DKGMasterPublicKeys for recoverDKGInfo",
+ "round", round)
+ mpk := cc.gov.DKGMasterPublicKeys(round)
+ cc.logger.Debug("Calling Governance.DKGComplaints for recoverDKGInfo",
+ "round", round)
+ comps := cc.gov.DKGComplaints(round)
+ qualifies, _, err := typesDKG.CalcQualifyNodes(mpk, comps, threshold)
+ if err != nil {
+ return err
+ }
+ if len(qualifies) <
+ utils.GetDKGValidThreshold(utils.GetConfigWithPanic(
+ cc.gov, round, cc.logger)) {
+ return typesDKG.ErrNotReachThreshold
+ }
+
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)
- mpk := cc.gov.DKGMasterPublicKeys(round)
- cc.logger.Debug("Calling Governance.DKGComplaints for recoverDKGInfo",
- "round", round)
- comps := cc.gov.DKGComplaints(round)
- qualifies, _, err := typesDKG.CalcQualifyNodes(mpk, comps, threshold)
- if err != nil {
- return err
- }
- if len(qualifies) <
- utils.GetDKGValidThreshold(utils.GetConfigWithPanic(
- cc.gov, round, cc.logger)) {
- return typesDKG.ErrNotReachThreshold
- }
npks, err := typesDKG.NewNodePublicKeys(round,
cc.gov.DKGMasterPublicKeys(round),
cc.gov.DKGComplaints(round),
threshold)
if err != nil {
- cc.logger.Warn("Failed to create DKGGroupPublicKey",
+ cc.logger.Warn("Failed to create DKGNodePublicKeys",
"round", round, "error", err)
return err
}
@@ -620,7 +620,29 @@ func (cc *configurationChain) recoverDKGInfo(
if err != nil {
cc.logger.Warn("Failed to create DKGPrivateKey",
"round", round, "error", err)
- return err
+ dkgProtocolInfo, err := cc.db.GetDKGProtocol()
+ if err != nil {
+ cc.logger.Warn("Unable to recover DKGProtocolInfo",
+ "round", round, "error", err)
+ return err
+ }
+ if dkgProtocolInfo.Round != round {
+ cc.logger.Warn("DKGProtocolInfo round mismatch",
+ "round", round, "infoRound", dkgProtocolInfo.Round)
+ return err
+ }
+ prvKeyRecover, err :=
+ dkgProtocolInfo.PrvShares.RecoverPrivateKey(qualifies)
+ if err != nil {
+ cc.logger.Warn("Failed to recover DKGPrivateKey",
+ "round", round, "error", err)
+ return err
+ }
+ if err = cc.db.PutDKGPrivateKey(round, *prvKeyRecover); err != nil {
+ cc.logger.Warn("Failed to save DKGPrivateKey",
+ "round", round, "error", err)
+ }
+ prvKey = *prvKeyRecover
}
func() {
cc.dkgResult.Lock()