diff options
Diffstat (limited to 'core/types/dkg')
-rw-r--r-- | core/types/dkg/dkg.go | 21 | ||||
-rw-r--r-- | core/types/dkg/dkg_test.go | 31 |
2 files changed, 52 insertions, 0 deletions
diff --git a/core/types/dkg/dkg.go b/core/types/dkg/dkg.go index cecc4f1..f021d1b 100644 --- a/core/types/dkg/dkg.go +++ b/core/types/dkg/dkg.go @@ -167,6 +167,27 @@ type PartialSignature struct { Signature crypto.Signature `json:"signature"` } +// MPKReady describe a dig ready message in DKG protocol. +type MPKReady struct { + ProposerID types.NodeID `json:"proposer_id"` + Round uint64 `json:"round"` + Signature crypto.Signature `json:"signature"` +} + +func (ready *MPKReady) String() string { + return fmt.Sprintf("DKGMPKReady{RP:%s Round:%d}", + ready.ProposerID.String()[:6], + ready.Round) +} + +// Equal check equality of two MPKReady instances. +func (ready *MPKReady) Equal(other *MPKReady) bool { + return ready.ProposerID.Equal(other.ProposerID) && + ready.Round == other.Round && + ready.Signature.Type == other.Signature.Type && + bytes.Compare(ready.Signature.Signature, other.Signature.Signature) == 0 +} + // Finalize describe a dig finalize message in DKG protocol. type Finalize struct { ProposerID types.NodeID `json:"proposer_id"` diff --git a/core/types/dkg/dkg_test.go b/core/types/dkg/dkg_test.go index ea46621..4eb17ac 100644 --- a/core/types/dkg/dkg_test.go +++ b/core/types/dkg/dkg_test.go @@ -212,6 +212,37 @@ func (s *DKGTestSuite) TestComplaintEquality() { req.True(comp1.Equal(comp2)) } +func (s *DKGTestSuite) TestMPKReadyEquality() { + var req = s.Require() + ready1 := &MPKReady{ + ProposerID: types.NodeID{Hash: common.NewRandomHash()}, + Round: 1, + Signature: crypto.Signature{ + Signature: s.genRandomBytes(), + }, + } + // Make a copy + ready2 := &MPKReady{} + s.clone(ready1, ready2) + req.True(ready1.Equal(ready2)) + // Change proposer ID. + ready2.ProposerID = types.NodeID{Hash: common.NewRandomHash()} + req.False(ready1.Equal(ready2)) + ready2.ProposerID = ready1.ProposerID + // Change round. + ready2.Round = ready1.Round + 1 + req.False(ready1.Equal(ready2)) + ready2.Round = ready1.Round + // Change signature. + ready2.Signature = crypto.Signature{ + Signature: s.genRandomBytes(), + } + req.False(ready1.Equal(ready2)) + ready2.Signature = ready1.Signature + // After changing every field back, they should be equal. + req.True(ready1.Equal(ready2)) +} + func (s *DKGTestSuite) TestFinalizeEquality() { var req = s.Require() final1 := &Finalize{ |