diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-03-27 20:47:32 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-15 22:09:55 +0800 |
commit | 8732c918f7b5d3dd9ac45b6e00995f5d74bc8a47 (patch) | |
tree | ab7aed4bb7d580011469dda917483e785c234a32 /vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go | |
parent | c52c9e04a916fac3550b0a3c3d8cdf979ab70bb8 (diff) | |
download | go-tangerine-8732c918f7b5d3dd9ac45b6e00995f5d74bc8a47.tar go-tangerine-8732c918f7b5d3dd9ac45b6e00995f5d74bc8a47.tar.gz go-tangerine-8732c918f7b5d3dd9ac45b6e00995f5d74bc8a47.tar.bz2 go-tangerine-8732c918f7b5d3dd9ac45b6e00995f5d74bc8a47.tar.lz go-tangerine-8732c918f7b5d3dd9ac45b6e00995f5d74bc8a47.tar.xz go-tangerine-8732c918f7b5d3dd9ac45b6e00995f5d74bc8a47.tar.zst go-tangerine-8732c918f7b5d3dd9ac45b6e00995f5d74bc8a47.zip |
core: merge notarySet and DKGSet (#265)
* vendor: sync to latest core
* core: merge notarySet and dkgSet
* dex: optimize network traffic for finalized block
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.go | 32 |
1 files changed, 17 insertions, 15 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 48b0f2a89..92b283098 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 @@ -76,7 +76,7 @@ type configurationChain struct { tsigReady *sync.Cond cache *utils.NodeSetCache db db.Database - dkgSet map[types.NodeID]struct{} + notarySet map[types.NodeID]struct{} mpkReady bool pendingPrvShare map[types.NodeID]*typesDKG.PrivateShare // TODO(jimmy-dexon): add timeout to pending psig. @@ -194,12 +194,12 @@ func (cc *configurationChain) registerDKG( }) } } - dkgSet, err := cc.cache.GetDKGSet(round) + notarySet, err := cc.cache.GetNotarySet(round) if err != nil { - cc.logger.Error("Error getting DKG set from cache", "error", err) + cc.logger.Error("Error getting notary set from cache", "error", err) return } - cc.dkgSet = dkgSet + cc.notarySet = notarySet cc.pendingPrvShare = make(map[types.NodeID]*typesDKG.PrivateShare) cc.mpkReady = false cc.dkg, err = recoverDKGProtocol(cc.ID, cc.recv, round, reset, cc.db) @@ -479,7 +479,7 @@ func (cc *configurationChain) runDKG(round uint64, reset uint64) (err error) { cc.dkgRunning = false }() // Check if corresponding DKG signer is ready. - if _, _, err = cc.getDKGInfo(round); err == nil { + if _, _, err = cc.getDKGInfo(round, true); err == nil { return ErrSkipButNoError } tickStartAt := 1 @@ -518,12 +518,13 @@ func (cc *configurationChain) isDKGFinal(round uint64) bool { if !cc.gov.IsDKGFinal(round) { return false } - _, _, err := cc.getDKGInfo(round) + _, _, err := cc.getDKGInfo(round, false) return err == nil } func (cc *configurationChain) getDKGInfo( - round uint64) (*typesDKG.NodePublicKeys, *dkgShareSecret, error) { + round uint64, ignoreSigner bool) ( + *typesDKG.NodePublicKeys, *dkgShareSecret, error) { getFromCache := func() (*typesDKG.NodePublicKeys, *dkgShareSecret) { cc.dkgResult.RLock() defer cc.dkgResult.RUnlock() @@ -532,19 +533,20 @@ func (cc *configurationChain) getDKGInfo( return npks, signer } npks, signer := getFromCache() - if npks == nil || signer == nil { - if err := cc.recoverDKGInfo(round); err != nil { + if npks == nil || (!ignoreSigner && signer == nil) { + if err := cc.recoverDKGInfo(round, ignoreSigner); err != nil { return nil, nil, err } npks, signer = getFromCache() } - if npks == nil || signer == nil { + if npks == nil || (!ignoreSigner && signer == nil) { return nil, nil, ErrDKGNotReady } return npks, signer, nil } -func (cc *configurationChain) recoverDKGInfo(round uint64) error { +func (cc *configurationChain) recoverDKGInfo( + round uint64, ignoreSigner bool) error { var npksExists, signerExists bool func() { cc.dkgResult.Lock() @@ -582,7 +584,7 @@ func (cc *configurationChain) recoverDKGInfo(round uint64) error { cc.npks[round] = npks }() } - if !signerExists { + if !signerExists && !ignoreSigner { // Check if we have private shares in DB. prvKey, err := cc.db.GetDKGPrivateKey(round) if err != nil { @@ -603,7 +605,7 @@ func (cc *configurationChain) recoverDKGInfo(round uint64) error { func (cc *configurationChain) preparePartialSignature( round uint64, hash common.Hash) (*typesDKG.PartialSignature, error) { - _, signer, _ := cc.getDKGInfo(round) + _, signer, _ := cc.getDKGInfo(round, false) if signer == nil { return nil, ErrDKGNotReady } @@ -632,7 +634,7 @@ func (cc *configurationChain) untouchTSigHash(hash common.Hash) { func (cc *configurationChain) runTSig( round uint64, hash common.Hash) ( crypto.Signature, error) { - npks, _, _ := cc.getDKGInfo(round) + npks, _, _ := cc.getDKGInfo(round, false) if npks == nil { return crypto.Signature{}, ErrDKGNotReady } @@ -697,7 +699,7 @@ func (cc *configurationChain) processPrivateShare( if cc.dkg == nil { return nil } - if _, exist := cc.dkgSet[prvShare.ProposerID]; !exist { + if _, exist := cc.notarySet[prvShare.ProposerID]; !exist { return ErrNotDKGParticipant } if !cc.mpkReady { |