From 07b4a7246e5adbb878f0f55711b93b5cbdbb7f9a Mon Sep 17 00:00:00 2001 From: Aayush Gautam Date: Tue, 8 Nov 2022 16:41:41 +0800 Subject: [PATCH] revert delete runner changes --- dkg/frost/frost_keygen_output.go | 4 ++++ dkg/frost/frost_round1.go | 7 +++++- dkg/frost/frost_round2.go | 7 +++++- dkg/node.go | 39 ++++++------------------------- dkg/spectest/tests/frost/blame.go | 4 ++-- dkg/spectest/tests/frost/test.go | 1 + 6 files changed, 26 insertions(+), 36 deletions(-) diff --git a/dkg/frost/frost_keygen_output.go b/dkg/frost/frost_keygen_output.go index d9738a83b..1e444870d 100644 --- a/dkg/frost/frost_keygen_output.go +++ b/dkg/frost/frost_keygen_output.go @@ -11,6 +11,10 @@ import ( func (fr *FROST) processKeygenOutput() (*dkg.KeyGenOutput, error) { + if fr.state.currentRound != KeygenOutput { + return nil, dkg.ErrInvalidRound{} + } + if !fr.needToRunCurrentRound() { return nil, nil } diff --git a/dkg/frost/frost_round1.go b/dkg/frost/frost_round1.go index 1cc8c6658..842c6bf79 100644 --- a/dkg/frost/frost_round1.go +++ b/dkg/frost/frost_round1.go @@ -1,12 +1,17 @@ package frost import ( + "github.com/bloxapp/ssv-spec/dkg" "github.com/bloxapp/ssv-spec/types" "github.com/herumi/bls-eth-go-binary/bls" ) func (fr *FROST) processRound1() error { + if fr.state.currentRound != Round1 { + return dkg.ErrInvalidRound{} + } + if !fr.needToRunCurrentRound() { return fr.state.participant.SkipRound1() } @@ -58,7 +63,7 @@ func (fr *FROST) processRound1() error { } msg := &ProtocolMsg{ - Round: fr.state.currentRound, + Round: Round1, Round1Message: &Round1Message{ Commitment: commitments, ProofS: bCastMessage.Wi.Bytes(), diff --git a/dkg/frost/frost_round2.go b/dkg/frost/frost_round2.go index 495539c4d..9340f724c 100644 --- a/dkg/frost/frost_round2.go +++ b/dkg/frost/frost_round2.go @@ -1,6 +1,7 @@ package frost import ( + "github.com/bloxapp/ssv-spec/dkg" "github.com/coinbase/kryptology/pkg/dkg/frost" "github.com/coinbase/kryptology/pkg/sharing" ecies "github.com/ecies/go/v2" @@ -9,6 +10,10 @@ import ( func (fr *FROST) processRound2() error { + if fr.state.currentRound != Round2 { + return dkg.ErrInvalidRound{} + } + if !fr.needToRunCurrentRound() { return nil } @@ -86,7 +91,7 @@ func (fr *FROST) processRound2() error { } msg := &ProtocolMsg{ - Round: fr.state.currentRound, + Round: Round2, Round2Message: &Round2Message{ Vk: bCastMessage.VerificationKey.ToAffineCompressed(), VkShare: bCastMessage.VkShare.ToAffineCompressed(), diff --git a/dkg/node.go b/dkg/node.go index 1e58d0979..a0d8535c7 100644 --- a/dkg/node.go +++ b/dkg/node.go @@ -8,45 +8,24 @@ import ( ) // Runners is a map of dkg runners mapped by dkg ID. -type Runners map[string]struct { - Runner Runner - isDeleted bool -} +type Runners map[string]Runner func (runners Runners) AddRunner(id RequestID, runner Runner) { - runners[hex.EncodeToString(id[:])] = struct { - Runner Runner - isDeleted bool - }{ - Runner: runner, - isDeleted: false, - } + runners[hex.EncodeToString(id[:])] = runner } // RunnerForID returns a Runner from the provided msg ID, or nil if not found func (runners Runners) RunnerForID(id RequestID) Runner { - r := runners[hex.EncodeToString(id[:])] - if r.Runner == nil || r.isDeleted { - return nil - } - return r.Runner + return runners[hex.EncodeToString(id[:])] } func (runners Runners) Exists(id RequestID) bool { - r := runners[hex.EncodeToString(id[:])] - return r.Runner != nil -} - -func (runners Runners) IsDeleted(id RequestID) bool { - r := runners[hex.EncodeToString(id[:])] - return r.Runner != nil && r.isDeleted + _, ok := runners[hex.EncodeToString(id[:])] + return ok } func (runners Runners) DeleteRunner(id RequestID) { - r := runners[hex.EncodeToString(id[:])] - r.isDeleted = true - runners[hex.EncodeToString(id[:])] = r - // delete(runners, hex.EncodeToString(id[:])) + delete(runners, hex.EncodeToString(id[:])) } // Node is responsible for receiving and managing DKG session and messages @@ -238,23 +217,19 @@ func (n *Node) validateReshareMsg(message *SignedMessage) (*Reshare, error) { } func (n *Node) processDKGMsg(message *SignedMessage) error { - if n.runners.IsDeleted(message.Message.Identifier) { - return nil - } if !n.runners.Exists(message.Message.Identifier) { return errors.New("could not find dkg runner") } - r := n.runners.RunnerForID(message.Message.Identifier) if err := n.validateDKGMsg(message); err != nil { return errors.Wrap(err, "dkg msg not valid") } + r := n.runners.RunnerForID(message.Message.Identifier) finished, err := r.ProcessMsg(message) if err != nil { return errors.Wrap(err, "could not process dkg message") } - if finished { n.runners.DeleteRunner(message.Message.Identifier) } diff --git a/dkg/spectest/tests/frost/blame.go b/dkg/spectest/tests/frost/blame.go index aca03ca46..8bce82e2f 100644 --- a/dkg/spectest/tests/frost/blame.go +++ b/dkg/spectest/tests/frost/blame.go @@ -58,7 +58,7 @@ func BlameTypeInvalidShare() *FrostSpecTest { Valid: true, }, }, - ExpectedError: "", + ExpectedError: "could not find dkg runner", InputMessages: map[int]MessagesForNodes{ 0: initMessages, @@ -133,7 +133,7 @@ func BlameTypeInconsistentMessage() *FrostSpecTest { Valid: true, }, }, - ExpectedError: "", + ExpectedError: "could not find dkg runner", InputMessages: map[int]MessagesForNodes{ 0: initMessages, diff --git a/dkg/spectest/tests/frost/test.go b/dkg/spectest/tests/frost/test.go index 1d4ecb9d1..284f864ff 100644 --- a/dkg/spectest/tests/frost/test.go +++ b/dkg/spectest/tests/frost/test.go @@ -47,6 +47,7 @@ func (test *FrostSpecTest) Run(t *testing.T) { if len(test.ExpectedError) > 0 { require.EqualError(t, err, test.ExpectedError) + return } else { require.NoError(t, err) }