ssvlabs/ssv-spec

Optimization Suggestion: Reduce Redundant Calls to SignedMessage.Validate in QBFT Message Processing

Opened this issue · 0 comments

Details
The method SignedMessage.Validate is being called multiple times across different functions, which may lead to inefficiencies in processing.
The method SignedMessage.Validate is redundantly invoked in several places:

  1. Within the Instance.BaseMsgValidation method:
// Instance.BaseMsgValidation method
if err := msg.Validate(); err != nil {
    return errors.Wrap(err, "invalid signed message")
}
  1. Also in other functions such as isValidProposal, validSignedPrepareForHeightRoundAndRoot, validateCommit, and validRoundChangeForData. For example, in isValidProposal:
// isValidProposal function
if err := signedProposal.Validate(); err != nil {
    return errors.Wrap(err, "proposal invalid")
}

Proposed Solution
We can call SignedMessage.Validate only once at the beginning to avoid repeating it.