ssvlabs / ssv-spec

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

Optimization Proposal: Eliminate Duplicate Validation Check to Improve Consensus Time #325

Open olegshmuelov opened 8 months ago

olegshmuelov commented 8 months ago

Description There appears to be a redundancy in the validation of consensus data, resulting in the same checks being conducted twice. This redundancy could be unnecessarily extending the time taken for consensus.

Details The validation check for the input data (byts) is performed twice:

  1. In the BaseRunner.decide method:
    // BaseRunner.decide method
    if err := runner.GetValCheckF()(byts); err != nil {
    return errors.Wrap(err, "input data invalid")
    }
  2. In the Controller.StartNewInstance method:
    // Controller.StartNewInstance method
    if err := c.GetConfig().GetValueCheckF()(value); err != nil {
    return errors.Wrap(err, "value invalid")
    }

    Given that BaseRunner.decide calls Controller.StartNewInstance, this results in the same validation check being performed twice on the same data.

Suggestion To optimize the consensus time, I propose removing one of these duplicate checks. My recommendation would be to keep the validation in the Controller.StartNewInstance method, as it seems more contextually appropriate for the responsibility of starting a new QBFT instance.

GalRogozinski commented 8 months ago

decide calls StartNewInstance so maybe we should do this check as soon as possible. Also som "duties" may not have an instance