aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-30 12:19:59 +0800
committerGitHub <noreply@github.com>2018-10-30 12:19:59 +0800
commit9c08b810e12f0a828e1de47b40b4e5de30c1c929 (patch)
tree7f438a9622705b1773869c35bed20a3586572030 /core
parent2275880f65fbfa253c1ec1d4c25d0b94cbdb185d (diff)
downloadtangerine-consensus-9c08b810e12f0a828e1de47b40b4e5de30c1c929.tar
tangerine-consensus-9c08b810e12f0a828e1de47b40b4e5de30c1c929.tar.gz
tangerine-consensus-9c08b810e12f0a828e1de47b40b4e5de30c1c929.tar.bz2
tangerine-consensus-9c08b810e12f0a828e1de47b40b4e5de30c1c929.tar.lz
tangerine-consensus-9c08b810e12f0a828e1de47b40b4e5de30c1c929.tar.xz
tangerine-consensus-9c08b810e12f0a828e1de47b40b4e5de30c1c929.tar.zst
tangerine-consensus-9c08b810e12f0a828e1de47b40b4e5de30c1c929.zip
core: Create an interface for TSigVerifierCache (#273)
Diffstat (limited to 'core')
-rw-r--r--core/dkg-tsig-protocol.go31
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
}