Skip to content

Commit

Permalink
services/horizon: Skip state verification on GetExpStateInvalid error (
Browse files Browse the repository at this point in the history
…#4523)

Return from `maybeVerifyState` when `GetExpStateInvalid` returns an error.
`stateInvalid` may be incorrect in such case.
  • Loading branch information
bartekn authored Aug 10, 2022
1 parent ee063a7 commit 6ecfa3f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 5 additions & 2 deletions services/horizon/internal/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,11 @@ func (s *system) runStateMachine(cur stateMachineNode) error {

func (s *system) maybeVerifyState(lastIngestedLedger uint32) {
stateInvalid, err := s.historyQ.GetExpStateInvalid(s.ctx)
if err != nil && !isCancelledError(err) {
log.WithField("err", err).Error("Error getting state invalid value")
if err != nil {
if !isCancelledError(err) {
log.WithField("err", err).Error("Error getting state invalid value")
}
return
}

// Run verification routine only when...
Expand Down
14 changes: 11 additions & 3 deletions services/horizon/internal/ingest/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestStateMachineRunReturnsErrorWhenNextStateIsShutdownWithError(t *testing.
assert.EqualError(t, err, "invalid range: [0, 0]")
}

func TestMaybeVerifyStateGetExpStateInvalidDBErrCancelOrContextCanceled(t *testing.T) {
func TestMaybeVerifyStateGetExpStateInvalidError(t *testing.T) {
historyQ := &mockDBQ{}
system := &system{
historyQ: historyQ,
Expand All @@ -180,13 +180,21 @@ func TestMaybeVerifyStateGetExpStateInvalidDBErrCancelOrContextCanceled(t *testi
defer func() { log = oldLogger }()

historyQ.On("GetExpStateInvalid", system.ctx).Return(false, db.ErrCancelled).Once()
system.maybeVerifyState(0)
system.maybeVerifyState(63)
system.wg.Wait()

historyQ.On("GetExpStateInvalid", system.ctx).Return(false, context.Canceled).Once()
system.maybeVerifyState(0)
system.maybeVerifyState(63)
system.wg.Wait()

logged := done()
assert.Len(t, logged, 0)

// Ensure state verifier does not start also for any other error
historyQ.On("GetExpStateInvalid", system.ctx).Return(false, errors.New("my error")).Once()
system.maybeVerifyState(63)
system.wg.Wait()

historyQ.AssertExpectations(t)
}
func TestMaybeVerifyInternalDBErrCancelOrContextCanceled(t *testing.T) {
Expand Down

0 comments on commit 6ecfa3f

Please sign in to comment.