diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-10-30 12:19:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-30 12:19:59 +0800 |
commit | 9c08b810e12f0a828e1de47b40b4e5de30c1c929 (patch) | |
tree | 7f438a9622705b1773869c35bed20a3586572030 | |
parent | 2275880f65fbfa253c1ec1d4c25d0b94cbdb185d (diff) | |
download | dexon-consensus-9c08b810e12f0a828e1de47b40b4e5de30c1c929.tar dexon-consensus-9c08b810e12f0a828e1de47b40b4e5de30c1c929.tar.gz dexon-consensus-9c08b810e12f0a828e1de47b40b4e5de30c1c929.tar.bz2 dexon-consensus-9c08b810e12f0a828e1de47b40b4e5de30c1c929.tar.lz dexon-consensus-9c08b810e12f0a828e1de47b40b4e5de30c1c929.tar.xz dexon-consensus-9c08b810e12f0a828e1de47b40b4e5de30c1c929.tar.zst dexon-consensus-9c08b810e12f0a828e1de47b40b4e5de30c1c929.zip |
core: Create an interface for TSigVerifierCache (#273)
-rw-r--r-- | core/dkg-tsig-protocol.go | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/core/dkg-tsig-protocol.go b/core/dkg-tsig-protocol.go index f3a596e..e3fdbcc 100644 --- a/core/dkg-tsig-protocol.go +++ b/core/dkg-tsig-protocol.go @@ -106,9 +106,25 @@ type TSigVerifier interface { VerifySignature(hash common.Hash, sig crypto.Signature) bool } +// TSigVerifierCacheInterface specifies interface used by TSigVerifierCache. +type TSigVerifierCacheInterface interface { + // Configuration returns the configuration at a given round. + // Return the genesis configuration if round == 0. + Configuration(round uint64) *types.Config + + // DKGComplaints gets all the DKGComplaints of round. + DKGComplaints(round uint64) []*typesDKG.Complaint + + // DKGMasterPublicKeys gets all the DKGMasterPublicKey of round. + DKGMasterPublicKeys(round uint64) []*typesDKG.MasterPublicKey + + // IsDKGFinal checks if DKG is final. + IsDKGFinal(round uint64) bool +} + // TSigVerifierCache is the cache for TSigVerifier. type TSigVerifierCache struct { - gov Governance + intf TSigVerifierCacheInterface verifier map[uint64]TSigVerifier minRound uint64 cacheSize int @@ -431,9 +447,10 @@ func (gpk *DKGGroupPublicKey) VerifySignature( } // NewTSigVerifierCache creats a DKGGroupPublicKey instance. -func NewTSigVerifierCache(gov Governance, cacheSize int) *TSigVerifierCache { +func NewTSigVerifierCache( + intf TSigVerifierCacheInterface, cacheSize int) *TSigVerifierCache { return &TSigVerifierCache{ - gov: gov, + intf: intf, verifier: make(map[uint64]TSigVerifier), cacheSize: cacheSize, } @@ -463,13 +480,13 @@ func (tc *TSigVerifierCache) Update(round uint64) (bool, error) { if _, exist := tc.verifier[round]; exist { return true, nil } - if !tc.gov.IsDKGFinal(round) { + if !tc.intf.IsDKGFinal(round) { return false, nil } gpk, err := NewDKGGroupPublicKey(round, - tc.gov.DKGMasterPublicKeys(round), - tc.gov.DKGComplaints(round), - int(tc.gov.Configuration(round).DKGSetSize/3)+1) + tc.intf.DKGMasterPublicKeys(round), + tc.intf.DKGComplaints(round), + int(tc.intf.Configuration(round).DKGSetSize/3)+1) if err != nil { return false, err } |