Skip to content

Commit

Permalink
Merge pull request #168 from ssvlabs/improve-reshare-threshold
Browse files Browse the repository at this point in the history
feat: don't exchange msg with old inactive operators
  • Loading branch information
MatusKysel authored Jan 15, 2025
2 parents b2eb96a + e57f22d commit 08425ce
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions pkgs/initiator/initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,16 @@ func (c *Initiator) ReshareMessageFlowHandling(id [24]byte, signedReshare *wire.
reqIDs = append(reqIDs, msgID)
}
c.Logger.Info("sending signed reshare message to all operators")
var errs map[uint64]error
exchangeMsgs, errs, err := c.SendReshareMsg(id, signedReshare, allOps)
var initErrs map[uint64]error
exchangeMsgs, initErrs, err := c.SendReshareMsg(id, signedReshare, allOps)
if err != nil {
return nil, err
}
if len(initErrs) > 0 {
allOps = filterOpsWithErrors(allOps, initErrs)
}
// check that all new operators and threshold of old operators replied without errors
if err := checkThreshold(exchangeMsgs, errs, signedReshare.Messages[0].Reshare.OldOperators, signedReshare.Messages[0].Reshare.NewOperators, int(signedReshare.Messages[0].Reshare.OldT)); err != nil {
if err := checkThreshold(exchangeMsgs, initErrs, signedReshare.Messages[0].Reshare.OldOperators, signedReshare.Messages[0].Reshare.NewOperators, int(signedReshare.Messages[0].Reshare.OldT)); err != nil {
return nil, err
}
numOfCeremonies := len(signedReshare.Messages)
Expand All @@ -309,7 +312,7 @@ func (c *Initiator) ReshareMessageFlowHandling(id [24]byte, signedReshare *wire.
}
allResults[operatorID] = allRes
}
// Operators have created instances of all ceremonies and sent back all exhcnage messages to initiator
// Operators have created instances of all ceremonies and sent back all exchange messages to initiator
c.Logger.Info("received exchange message responses for all ceremonies")
c.Logger.Info("continuing with all ceremonies one by one")
// finalResults contains result bytes for each operator for each ceremony
Expand All @@ -328,6 +331,10 @@ func (c *Initiator) ReshareMessageFlowHandling(id [24]byte, signedReshare *wire.
if err != nil {
return nil, err
}
// merge errors from init phase
for k, v := range initErrs {
errs[k] = v
}
// check that all new operators and threshold of old operators replied without errors
if err := checkThreshold(kyberMsgs, errs, signedReshare.Messages[0].Reshare.OldOperators, signedReshare.Messages[0].Reshare.NewOperators, int(signedReshare.Messages[0].Reshare.OldT)); err != nil {
return nil, err
Expand Down Expand Up @@ -1024,3 +1031,14 @@ func verifyMessageType(tsp *wire.SignedTransport, expectedType wire.TransportTyp
}
return nil
}

// The returned slice contains only those operators without errors.
func filterOpsWithErrors(allOps []*spec.Operator, initErrs map[uint64]error) []*spec.Operator {
filteredOps := make([]*spec.Operator, 0, len(allOps))
for _, op := range allOps {
if _, found := initErrs[op.ID]; !found {
filteredOps = append(filteredOps, op)
}
}
return filteredOps
}

0 comments on commit 08425ce

Please sign in to comment.