diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-10-23 14:22:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-23 14:22:42 +0800 |
commit | e5aa1799c256a1ae56cc4b7ee0a54f94cb084687 (patch) | |
tree | 1172f946e49fd7e49c1e4211e492cca5a2c38fe7 /core/types/dkg.go | |
parent | 50e7b0fcb7fd78218be68f32f818713e6933a9e8 (diff) | |
download | tangerine-consensus-e5aa1799c256a1ae56cc4b7ee0a54f94cb084687.tar tangerine-consensus-e5aa1799c256a1ae56cc4b7ee0a54f94cb084687.tar.gz tangerine-consensus-e5aa1799c256a1ae56cc4b7ee0a54f94cb084687.tar.bz2 tangerine-consensus-e5aa1799c256a1ae56cc4b7ee0a54f94cb084687.tar.lz tangerine-consensus-e5aa1799c256a1ae56cc4b7ee0a54f94cb084687.tar.xz tangerine-consensus-e5aa1799c256a1ae56cc4b7ee0a54f94cb084687.tar.zst tangerine-consensus-e5aa1799c256a1ae56cc4b7ee0a54f94cb084687.zip |
core: add equality checker for dkg related structure (#237)
Besides adding equality, also renaming those fields.
- PublicKeyShares.shares -> shareCaches
- PublicKeyShares.shareIndex -> shareCacheIndex
- rlpPublicKeyShares.Shares -> ShareCaches
- rlpPublicKeyShares.ShareIndexK -> ShareCacheIndexK
- rlpPublicKeyShares.ShareIndexV -> ShareCahceIndexV
Diffstat (limited to 'core/types/dkg.go')
-rw-r--r-- | core/types/dkg.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/core/types/dkg.go b/core/types/dkg.go index 3bdb414..edd420d 100644 --- a/core/types/dkg.go +++ b/core/types/dkg.go @@ -18,6 +18,7 @@ package types import ( + "bytes" "encoding/json" "fmt" "io" @@ -38,6 +39,17 @@ type DKGPrivateShare struct { Signature crypto.Signature `json:"signature"` } +// Equal checks equality between two DKGPrivateShare instances. +func (p *DKGPrivateShare) Equal(other *DKGPrivateShare) bool { + return p.ProposerID.Equal(other.ProposerID) && + p.ReceiverID.Equal(other.ReceiverID) && + p.Round == other.Round && + p.Signature.Type == other.Signature.Type && + bytes.Compare(p.Signature.Signature, other.Signature.Signature) == 0 && + bytes.Compare( + p.PrivateShare.Bytes(), other.PrivateShare.Bytes()) == 0 +} + // DKGMasterPublicKey decrtibe a master public key in DKG protocol. type DKGMasterPublicKey struct { ProposerID NodeID `json:"proposer_id"` @@ -53,6 +65,16 @@ func (d *DKGMasterPublicKey) String() string { d.Round) } +// Equal check equality of two DKG master public keys. +func (d *DKGMasterPublicKey) Equal(other *DKGMasterPublicKey) bool { + return d.ProposerID.Equal(other.ProposerID) && + d.Round == other.Round && + d.DKGID.GetHexString() == other.DKGID.GetHexString() && + d.PublicKeyShares.Equal(&other.PublicKeyShares) && + d.Signature.Type == other.Signature.Type && + bytes.Compare(d.Signature.Signature, other.Signature.Signature) == 0 +} + type rlpDKGMasterPublicKey struct { ProposerID NodeID Round uint64 @@ -126,6 +148,15 @@ func (c *DKGComplaint) String() string { c.ProposerID.String()[:6], c.Round, c.PrivateShare) } +// Equal checks equality between two DKGComplaint instances. +func (c *DKGComplaint) Equal(other *DKGComplaint) bool { + return c.ProposerID.Equal(other.ProposerID) && + c.Round == other.Round && + c.PrivateShare.Equal(&other.PrivateShare) && + c.Signature.Type == other.Signature.Type && + bytes.Compare(c.Signature.Signature, other.Signature.Signature) == 0 +} + // DKGPartialSignature describe a partial signature in DKG protocol. type DKGPartialSignature struct { ProposerID NodeID `json:"proposer_id"` @@ -148,6 +179,14 @@ func (final *DKGFinalize) String() string { final.Round) } +// Equal check equality of two DKGFinalize instances. +func (final *DKGFinalize) Equal(other *DKGFinalize) bool { + return final.ProposerID.Equal(other.ProposerID) && + final.Round == other.Round && + final.Signature.Type == other.Signature.Type && + bytes.Compare(final.Signature.Signature, other.Signature.Signature) == 0 +} + // IsNack returns true if it's a nack complaint in DKG protocol. func (c *DKGComplaint) IsNack() bool { return len(c.PrivateShare.Signature.Signature) == 0 |