diff --git a/protocol/v2/qbft/controller/controller.go b/protocol/v2/qbft/controller/controller.go index 164509be95..c262eeee95 100644 --- a/protocol/v2/qbft/controller/controller.go +++ b/protocol/v2/qbft/controller/controller.go @@ -53,17 +53,18 @@ func NewController( } // StartNewInstance will start a new QBFT instance, if can't will return error -func (c *Controller) StartNewInstance(logger *zap.Logger, height specqbft.Height, value []byte) (*instance.Instance, error) { +func (c *Controller) StartNewInstance(logger *zap.Logger, height specqbft.Height, value []byte) error { + if err := c.GetConfig().GetValueCheckF()(value); err != nil { - return nil, errors.Wrap(err, "value invalid") + return errors.Wrap(err, "value invalid") } if height < c.Height { - return nil, errors.New("attempting to start an instance with a past height") + return errors.New("attempting to start an instance with a past height") } if c.StoredInstances.FindInstance(height) != nil { - return nil, errors.New("instance already running") + return errors.New("instance already running") } c.Height = height @@ -71,8 +72,7 @@ func (c *Controller) StartNewInstance(logger *zap.Logger, height specqbft.Height newInstance := c.addAndStoreNewInstance() newInstance.Start(logger, value, height) c.forceStopAllInstanceExceptCurrent() - - return newInstance, nil + return nil } func (c *Controller) forceStopAllInstanceExceptCurrent() { diff --git a/protocol/v2/qbft/spectest/controller_type.go b/protocol/v2/qbft/spectest/controller_type.go index 75a860bba9..bf0f81a073 100644 --- a/protocol/v2/qbft/spectest/controller_type.go +++ b/protocol/v2/qbft/spectest/controller_type.go @@ -148,7 +148,7 @@ func testBroadcastedDecided( } func runInstanceWithData(t *testing.T, logger *zap.Logger, height specqbft.Height, contr *controller.Controller, runData *spectests.RunInstanceData) error { - _, err := contr.StartNewInstance(logger, height, runData.InputValue) + err := contr.StartNewInstance(logger, height, runData.InputValue) var lastErr error if err != nil { lastErr = err diff --git a/protocol/v2/ssv/runner/runner.go b/protocol/v2/ssv/runner/runner.go index 80071fb4e0..152a31f913 100644 --- a/protocol/v2/ssv/runner/runner.go +++ b/protocol/v2/ssv/runner/runner.go @@ -300,13 +300,16 @@ func (b *BaseRunner) decide(logger *zap.Logger, runner Runner, slot phase0.Slot, return errors.Wrap(err, "input data invalid") } - newInstance, err := runner.GetBaseRunner().QBFTController.StartNewInstance(logger, + if err := runner.GetBaseRunner().QBFTController.StartNewInstance(logger, specqbft.Height(slot), byts, - ) - if err != nil { + ); err != nil { return errors.Wrap(err, "could not start new QBFT instance") } + newInstance := runner.GetBaseRunner().QBFTController.StoredInstances.FindInstance(specqbft.Height(slot)) // TODO confirm correctness + if newInstance == nil { + return errors.New("could not find newly created QBFT instance") + } runner.GetBaseRunner().State.RunningInstance = newInstance