diff --git a/consensus/polybft/state_sync_manager.go b/consensus/polybft/state_sync_manager.go index 0af07d68ba..6e54e3ba04 100644 --- a/consensus/polybft/state_sync_manager.go +++ b/consensus/polybft/state_sync_manager.go @@ -159,24 +159,14 @@ func (s *stateSyncManager) saveVote(msg *TransportMessage) error { valSet := s.validatorSet s.lock.RUnlock() - if valSet == nil || msg.EpochNumber < epoch || msg.EpochNumber > epoch+1{ - return nil - } - - if msg.EpochNumber == epoch+1 { - if err := s.state.EpochStore.insertEpoch(epoch+1, nil); err != nil { - return fmt.Errorf("error saving msg vote from a future epoch: %d. Error: %w", epoch+1, err) - } - } + if valSet == nil || msg.EpochNumber < epoch || msg.EpochNumber > epoch+1 { + // Epoch metadata is undefined or received a message for the irrelevant epoch return nil } - if msg.EpochNumber != epoch && msg.EpochNumber != epoch+1 { - // Epoch metadata is undefined or received a message for the irrelevant epoch - return nil - } else if msg.EpochNumber == epoch+1 { + if msg.EpochNumber == epoch+1 { if err := s.state.EpochStore.insertEpoch(epoch+1, nil); err != nil { - return fmt.Errorf("error inserting epoch: %w", err) + return fmt.Errorf("error saving msg vote from a future epoch: %d. Error: %w", epoch+1, err) } } diff --git a/consensus/polybft/state_sync_manager_test.go b/consensus/polybft/state_sync_manager_test.go index f3c5718097..fbbf46dc23 100644 --- a/consensus/polybft/state_sync_manager_test.go +++ b/consensus/polybft/state_sync_manager_test.go @@ -150,7 +150,8 @@ func TestStateSyncManager_MessagePool(t *testing.T) { msg, err := val.sign(vals.GetValidator("0"), signer.DomainStateReceiver) require.NoError(t, err) - msg.EpochNumber = 1 + // invalid epoch +2 + msg.EpochNumber = 2 require.NoError(t, s.saveVote(msg))