ssvlabs / ssv-spec

GNU General Public License v3.0
25 stars 22 forks source link

Improve Round-Change validation #358

Open MatheusFranco99 opened 7 months ago

MatheusFranco99 commented 7 months ago

Overview

This PR aims to improve the Round-Change validation functions.

The reason is that, from benchmark tests, Round-Change message processing showed unexpectedly high latency. This performance hurdle comes from:

Changes

  1. The validSignedPrepareForHeightRoundAndRoot function was refactored by the following way:
    • a new validPrepareForHeightRoundAndRoot function that performs all the message fields and logic checks.
    • validSignedPrepareForHeightRoundAndRoot now calls validPrepareForHeightRoundAndRoot and then, if there is no error, it verifies the signature.
  2. getRoundChangeJustification, now, calls validPrepareForHeightRoundAndRoot to validate the Prepare messages (for a round and root) without verifying the signature.
  3. Once a quorum of Round-Change messages is reached, the Proposal justification validation for the Proposal creation will not verify signatures (since container messages are already verified). This is accomplished by adding a flag verifySignatures to the isProposalJustification function. For received Proposal messages, the flag is set to true, and, for Proposal validation for creation, the flag is set to false.
  4. The validRoundChangeForData function is refactored to validSignedRoundChangeForData.
  5. A new validRoundChangeForData function is created with similar behavior to validSignedRoundChangeForData but without verifying signatures.

Performance Comparison

All times are in milliseconds.

Due to the change no. 2, we get the following Round-Change processing improvement:

1st 2nd 3rd (quorum)
Old 4.5 9.5 21.5
New 4.5 4.8 21.5
Due to the changes no. 2 and 3, we get the following Round-Change processing improvement: 1st 2nd 3rd (quorum)
Old 4.5 9.5 21.5
New 4.5 4.8 5