diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-03-20 14:57:12 +0800 |
---|---|---|
committer | Jimmy Hu <jimmy.hu@dexon.org> | 2019-03-27 15:25:10 +0800 |
commit | 6efe199cb38eb4cb9a9a64d98ff5f8c4fb997da7 (patch) | |
tree | 2c18fe616f84df7274f19f88cf325fe558869918 /core/configuration-chain.go | |
parent | fa3b5a29499739e90b3cf17f9a0cf60a72a64fc0 (diff) | |
download | dexon-consensus-6efe199cb38eb4cb9a9a64d98ff5f8c4fb997da7.tar dexon-consensus-6efe199cb38eb4cb9a9a64d98ff5f8c4fb997da7.tar.gz dexon-consensus-6efe199cb38eb4cb9a9a64d98ff5f8c4fb997da7.tar.bz2 dexon-consensus-6efe199cb38eb4cb9a9a64d98ff5f8c4fb997da7.tar.lz dexon-consensus-6efe199cb38eb4cb9a9a64d98ff5f8c4fb997da7.tar.xz dexon-consensus-6efe199cb38eb4cb9a9a64d98ff5f8c4fb997da7.tar.zst dexon-consensus-6efe199cb38eb4cb9a9a64d98ff5f8c4fb997da7.zip |
core: merge notarySet and DKGSet (#488)
* core: ăăăȘă DKGSet
* test logger
* temporary fix before finalized
* core: Sign psig on commit vote
* Add syncer log
* fixup
Diffstat (limited to 'core/configuration-chain.go')
-rw-r--r-- | core/configuration-chain.go | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/core/configuration-chain.go b/core/configuration-chain.go index 48b0f2a..92b2830 100644 --- a/core/configuration-chain.go +++ b/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 { |