Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert delete runner changes #15

Merged
merged 3 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dkg/frost/frost_keygen_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion dkg/frost/frost_round1.go
Original file line number Diff line number Diff line change
@@ -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()
}
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 5 additions & 1 deletion dkg/frost/frost_round2.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (

func (fr *FROST) processRound2() (*dkg.ProtocolOutcome, error) {

if fr.state.currentRound != Round2 {
return nil, dkg.ErrInvalidRound{}
}

if !fr.needToRunCurrentRound() {
return nil, nil
}
Expand Down Expand Up @@ -79,7 +83,7 @@ func (fr *FROST) processRound2() (*dkg.ProtocolOutcome, error) {
}

msg := &ProtocolMsg{
Round: fr.state.currentRound,
Round: Round2,
Round2Message: &Round2Message{
Vk: bCastMessage.VerificationKey.ToAffineCompressed(),
VkShare: bCastMessage.VkShare.ToAffineCompressed(),
Expand Down
39 changes: 7 additions & 32 deletions dkg/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions dkg/spectest/tests/frost/blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func GetBlameSpecTest(testName string, data []byte) *FrostSpecTest {
Valid: true,
},
},
ExpectedError: "",
ExpectedError: "could not find dkg runner",

InputMessages: map[int]MessagesForNodes{
0: initMessages,
Expand Down Expand Up @@ -147,7 +147,7 @@ func BlameTypeInvalidShare_FailedValidationAgainstCommitment() *FrostSpecTest {
Valid: true,
},
},
ExpectedError: "",
ExpectedError: "could not find dkg runner",

InputMessages: map[int]MessagesForNodes{
0: initMessages,
Expand Down Expand Up @@ -222,7 +222,7 @@ func BlameTypeInconsistentMessage() *FrostSpecTest {
Valid: true,
},
},
ExpectedError: "",
ExpectedError: "could not find dkg runner",

InputMessages: map[int]MessagesForNodes{
0: initMessages,
Expand Down
1 change: 1 addition & 0 deletions dkg/spectest/tests/frost/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down