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/internal/expingest: Emit error log after 3 failed attempts to validate state #1918

Merged
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
17 changes: 16 additions & 1 deletion services/horizon/internal/expingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ type System struct {

// stateVerificationRunning is true when verification routine is currently
// running.
stateVerificationMutex sync.Mutex
stateVerificationMutex sync.Mutex
// number of consecutive state verification runs which encountered errors
stateVerificationErrors int
stateVerificationRunning bool
disableStateVerification bool
}
Expand Down Expand Up @@ -370,6 +372,19 @@ func (s *System) setStateReady() {
s.stateReady = true
}

func (s *System) incrementStateVerificationErrors() int {
s.stateVerificationMutex.Lock()
defer s.stateVerificationMutex.Unlock()
s.stateVerificationErrors++
return s.stateVerificationErrors
}

func (s *System) resetStateVerificationErrors() {
s.stateVerificationMutex.Lock()
defer s.stateVerificationMutex.Unlock()
s.stateVerificationErrors = 0
}

func (s *System) Shutdown() {
log.Info("Shutting down ingestion system...")
s.session.Shutdown()
Expand Down
14 changes: 11 additions & 3 deletions services/horizon/internal/expingest/pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (
type pType string

const (
statePipeline pType = "state_pipeline"
ledgerPipeline pType = "ledger_pipeline"
statePipeline pType = "state_pipeline"
ledgerPipeline pType = "ledger_pipeline"
stateVerificationErrorThreshold = 3
)

func accountsStateNode(q *history.Q) *supportPipeline.PipelineNode {
Expand Down Expand Up @@ -274,12 +275,19 @@ func postProcessingHook(
go func() {
err := system.verifyState()
if err != nil {
errorCount := system.incrementStateVerificationErrors()
switch errors.Cause(err).(type) {
case verify.StateError:
markStateInvalid(historySession, err)
default:
log.WithField("err", err).Error("State verification errored")
logger := log.WithField("err", err).Warn
if errorCount >= stateVerificationErrorThreshold {
logger = log.WithField("err", err).Error
}
logger("State verification errored")
}
} else {
system.resetStateVerificationErrors()
}
}()
}
Expand Down