Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services/horizon: Skip state verification on GetExpStateInvalid error #4523

Merged
merged 3 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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