Skip to content

Commit

Permalink
revert delete runner changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush-rockx committed Nov 8, 2022
1 parent 74e1f3b commit 07b4a72
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 36 deletions.
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
7 changes: 6 additions & 1 deletion dkg/frost/frost_round2.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -9,6 +10,10 @@ import (

func (fr *FROST) processRound2() error {

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

if !fr.needToRunCurrentRound() {
return nil
}
Expand Down Expand Up @@ -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(),
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
4 changes: 2 additions & 2 deletions dkg/spectest/tests/frost/blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func BlameTypeInvalidShare() *FrostSpecTest {
Valid: true,
},
},
ExpectedError: "",
ExpectedError: "could not find dkg runner",

InputMessages: map[int]MessagesForNodes{
0: initMessages,
Expand Down Expand Up @@ -133,7 +133,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

0 comments on commit 07b4a72

Please sign in to comment.