aboutsummaryrefslogtreecommitdiffstats
path: root/core/types
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-15 11:44:04 +0800
committerGitHub <noreply@github.com>2019-04-15 11:44:04 +0800
commit79be89a6b0b1d24b889e7c9fe0244026af4d49d0 (patch)
treebacd2dd8a224d2cffbe9965439707df7fa2888de /core/types
parent7abe09214fbf04f9f1f7f4f6ec57cd1f924953d6 (diff)
downloaddexon-consensus-79be89a6b0b1d24b889e7c9fe0244026af4d49d0.tar
dexon-consensus-79be89a6b0b1d24b889e7c9fe0244026af4d49d0.tar.gz
dexon-consensus-79be89a6b0b1d24b889e7c9fe0244026af4d49d0.tar.bz2
dexon-consensus-79be89a6b0b1d24b889e7c9fe0244026af4d49d0.tar.lz
dexon-consensus-79be89a6b0b1d24b889e7c9fe0244026af4d49d0.tar.xz
dexon-consensus-79be89a6b0b1d24b889e7c9fe0244026af4d49d0.tar.zst
dexon-consensus-79be89a6b0b1d24b889e7c9fe0244026af4d49d0.zip
core: Add DKGSuccess (#569)
* core: Add DKGSuccess * core: reset if not enough of dkg success
Diffstat (limited to 'core/types')
-rw-r--r--core/types/dkg/dkg.go34
-rw-r--r--core/types/dkg/dkg_test.go36
2 files changed, 65 insertions, 5 deletions
diff --git a/core/types/dkg/dkg.go b/core/types/dkg/dkg.go
index 868f0da..cb921e5 100644
--- a/core/types/dkg/dkg.go
+++ b/core/types/dkg/dkg.go
@@ -242,6 +242,11 @@ func (c *Complaint) DecodeRLP(s *rlp.Stream) error {
return nil
}
+// IsNack returns true if it's a nack complaint in DKG protocol.
+func (c *Complaint) IsNack() bool {
+ return len(c.PrivateShare.Signature.Signature) == 0
+}
+
// PartialSignature describe a partial signature in DKG protocol.
type PartialSignature struct {
ProposerID types.NodeID `json:"proposer_id"`
@@ -251,7 +256,7 @@ type PartialSignature struct {
Signature crypto.Signature `json:"signature"`
}
-// MPKReady describe a dig ready message in DKG protocol.
+// MPKReady describe a dkg ready message in DKG protocol.
type MPKReady struct {
ProposerID types.NodeID `json:"proposer_id"`
Round uint64 `json:"round"`
@@ -275,7 +280,7 @@ func (ready *MPKReady) Equal(other *MPKReady) bool {
bytes.Compare(ready.Signature.Signature, other.Signature.Signature) == 0
}
-// Finalize describe a dig finalize message in DKG protocol.
+// Finalize describe a dkg finalize message in DKG protocol.
type Finalize struct {
ProposerID types.NodeID `json:"proposer_id"`
Round uint64 `json:"round"`
@@ -299,9 +304,28 @@ func (final *Finalize) Equal(other *Finalize) bool {
bytes.Compare(final.Signature.Signature, other.Signature.Signature) == 0
}
-// IsNack returns true if it's a nack complaint in DKG protocol.
-func (c *Complaint) IsNack() bool {
- return len(c.PrivateShare.Signature.Signature) == 0
+// Success describe a dkg success message in DKG protocol.
+type Success struct {
+ ProposerID types.NodeID `json:"proposer_id"`
+ Round uint64 `json:"round"`
+ Reset uint64 `json:"reset"`
+ Signature crypto.Signature `json:"signature"`
+}
+
+func (s *Success) String() string {
+ return fmt.Sprintf("DKGSuccess{SP:%s Round:%d Reset:%d}",
+ s.ProposerID.String()[:6],
+ s.Round,
+ s.Reset)
+}
+
+// Equal check equality of two Success instances.
+func (s *Success) Equal(other *Success) bool {
+ return s.ProposerID.Equal(other.ProposerID) &&
+ s.Round == other.Round &&
+ s.Reset == other.Reset &&
+ s.Signature.Type == other.Signature.Type &&
+ bytes.Compare(s.Signature.Signature, other.Signature.Signature) == 0
}
// GroupPublicKey is the result of DKG protocol.
diff --git a/core/types/dkg/dkg_test.go b/core/types/dkg/dkg_test.go
index 9f50feb..ea6a565 100644
--- a/core/types/dkg/dkg_test.go
+++ b/core/types/dkg/dkg_test.go
@@ -394,6 +394,42 @@ func (s *DKGTestSuite) TestFinalizeEquality() {
req.True(final1.Equal(final2))
}
+func (s *DKGTestSuite) TestSuccessEquality() {
+ var req = s.Require()
+ success1 := &Success{
+ ProposerID: types.NodeID{Hash: common.NewRandomHash()},
+ Round: 1,
+ Reset: 2,
+ Signature: crypto.Signature{
+ Signature: s.genRandomBytes(),
+ },
+ }
+ // Make a copy
+ success2 := &Success{}
+ s.clone(success1, success2)
+ req.True(success1.Equal(success2))
+ // Change proposer ID.
+ success2.ProposerID = types.NodeID{Hash: common.NewRandomHash()}
+ req.False(success1.Equal(success2))
+ success2.ProposerID = success1.ProposerID
+ // Change round.
+ success2.Round = success1.Round + 1
+ req.False(success1.Equal(success2))
+ success2.Round = success1.Round
+ // Change reset.
+ success2.Reset = success1.Reset + 1
+ req.False(success1.Equal(success2))
+ success2.Reset = success1.Reset
+ // Change signature.
+ success2.Signature = crypto.Signature{
+ Signature: s.genRandomBytes(),
+ }
+ req.False(success1.Equal(success2))
+ success2.Signature = success1.Signature
+ // After changing every field back, they should be equal.
+ req.True(success1.Equal(success2))
+}
+
func TestDKG(t *testing.T) {
suite.Run(t, new(DKGTestSuite))
}