diff options
Diffstat (limited to 'core')
-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) { |