diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-02-13 11:44:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-13 11:44:38 +0800 |
commit | 33955365a764647b4e95eb8236eb9d54e7ceba12 (patch) | |
tree | f9cdd97c08dcbe71b551833b6bed4dc5f8699dc0 | |
parent | 7f57f843e14dc1c75c8747bd0e65ee3ee6de6d72 (diff) | |
download | dexon-consensus-33955365a764647b4e95eb8236eb9d54e7ceba12.tar.gz dexon-consensus-33955365a764647b4e95eb8236eb9d54e7ceba12.tar.zst dexon-consensus-33955365a764647b4e95eb8236eb9d54e7ceba12.zip |
core: polish dkg for recovery (#443)
* core: Add an error to NewGroupPublicKey
* core: Add Delete to TSigVerifierCache
* remove duplicated check
-rw-r--r-- | core/configuration-chain.go | 5 | ||||
-rw-r--r-- | core/dkg-tsig-protocol.go | 10 | ||||
-rw-r--r-- | core/dkg-tsig-protocol_test.go | 6 |
3 files changed, 16 insertions, 5 deletions
diff --git a/core/configuration-chain.go b/core/configuration-chain.go index bec47f4..ad4d7e6 100644 --- a/core/configuration-chain.go +++ b/core/configuration-chain.go @@ -308,11 +308,6 @@ func (cc *configurationChain) recoverDKGInfo(round uint64) error { if err != nil { return err } - // Restore DKG share secret, this segment of code is copied from - // dkgProtocol.recoverShareSecret. - if len(gpk.qualifyIDs) < threshold { - return ErrNotReachThreshold - } // Check if we have private shares in DB. prvKey, err := cc.db.GetDKGPrivateKey(round) if err != nil { diff --git a/core/dkg-tsig-protocol.go b/core/dkg-tsig-protocol.go index 73b8abf..2028154 100644 --- a/core/dkg-tsig-protocol.go +++ b/core/dkg-tsig-protocol.go @@ -400,6 +400,9 @@ func NewDKGGroupPublicKey( } } qualifyIDs := make(dkg.IDs, 0, len(mpks)-len(disqualifyIDs)) + if cap(qualifyIDs) < threshold { + return nil, ErrNotReachThreshold + } qualifyNodeIDs := make(map[types.NodeID]struct{}) mpkMap := make(map[dkg.ID]*typesDKG.MasterPublicKey, cap(qualifyIDs)) idMap := make(map[types.NodeID]dkg.ID) @@ -515,6 +518,13 @@ func (tc *TSigVerifierCache) Update(round uint64) (bool, error) { return true, nil } +// Delete the cache of given round. +func (tc *TSigVerifierCache) Delete(round uint64) { + tc.lock.Lock() + defer tc.lock.Unlock() + delete(tc.verifier, round) +} + // Get the TSigVerifier of round and returns if it exists. func (tc *TSigVerifierCache) Get(round uint64) (TSigVerifier, bool) { tc.lock.RLock() diff --git a/core/dkg-tsig-protocol_test.go b/core/dkg-tsig-protocol_test.go index 54118f6..4086267 100644 --- a/core/dkg-tsig-protocol_test.go +++ b/core/dkg-tsig-protocol_test.go @@ -780,6 +780,11 @@ func (s *DKGTSIGProtocolTestSuite) TestTSigVerifierCache() { ok, err := cache.Update(uint64(1)) s.Require().Equal(ErrRoundAlreadyPurged, err) + cache.Delete(uint64(5)) + s.Len(cache.verifier, 2) + _, exist := cache.Get(uint64(5)) + s.False(exist) + cache = NewTSigVerifierCache(gov, 1) ok, err = cache.Update(uint64(3)) s.Require().NoError(err) @@ -790,6 +795,7 @@ func (s *DKGTSIGProtocolTestSuite) TestTSigVerifierCache() { s.Require().NoError(err) s.Require().True(ok) s.Equal(uint64(5), cache.minRound) + } func TestDKGTSIGProtocol(t *testing.T) { |