aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-03-13 18:19:53 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:22 +0800
commit43457d6a008524f9dd353fce7b12e16cd4d0e157 (patch)
tree12782a2db49a1ee4e1fa97db64901251eeed36af /vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go
parenta0684dc255fb2d3db22ea4c03957d9b7b27a0a36 (diff)
downloadgo-tangerine-43457d6a008524f9dd353fce7b12e16cd4d0e157.tar
go-tangerine-43457d6a008524f9dd353fce7b12e16cd4d0e157.tar.gz
go-tangerine-43457d6a008524f9dd353fce7b12e16cd4d0e157.tar.bz2
go-tangerine-43457d6a008524f9dd353fce7b12e16cd4d0e157.tar.lz
go-tangerine-43457d6a008524f9dd353fce7b12e16cd4d0e157.tar.xz
go-tangerine-43457d6a008524f9dd353fce7b12e16cd4d0e157.tar.zst
go-tangerine-43457d6a008524f9dd353fce7b12e16cd4d0e157.zip
vendor: sync to latest core (#253)
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go73
1 files changed, 52 insertions, 21 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go
index 9e8df6bd1..9214cd97d 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go
@@ -106,6 +106,12 @@ func (cc *configurationChain) registerDKG(round uint64, threshold int) {
cc.recv,
round,
threshold)
+ err = cc.db.PutOrUpdateDKGMasterPrivateShares(round, *cc.dkg.prvShares)
+ if err != nil {
+ cc.logger.Error("Error put or update DKG master private shares", "error",
+ err)
+ return
+ }
go func() {
ticker := newTicker(cc.gov, round, TickerDKG)
defer ticker.Stop()
@@ -287,33 +293,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
}