fix: treat TLS errors as failover-worthy and remove unsafe start-block fallback#102
Open
vietddude wants to merge 2 commits into
Open
fix: treat TLS errors as failover-worthy and remove unsafe start-block fallback#102vietddude wants to merge 2 commits into
vietddude wants to merge 2 commits into
Conversation
dbcc9a4 to
3101c43
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Production logs for
bsc_mainnet-1revealed two distinct bugs:remote error: tls: internal errormatched no pattern inanalyzeError()→ classified asgeneric_error(markUnhealthy=false) → the provider stayedhealthyand the indexer kept hammering the broken endpoint.determineStartingBlock()fell straight back toconfig.StartBlock. Root cause:GetLatestBlockcollapsed "key absent (first run)" and "store down" into the same error, so a transient outage at boot could silently rewind the indexer to an old block and re-index everything.Changes
1. TLS errors are now failover-worthy (
internal/rpc/failover.go)tls_errorpattern (tls: internal error,tls handshake,handshake failure,remote error: tls) withmarkUnhealthy: true, 2m cooldown → the provider is cooled down and rotated away.2. Distinguish "not found" from "store error" (
pkg/store/blockstore/store.go)GetLatestBlockreturns(0, nil)for a missing key (kvstore.ErrKeyNotFound— Consul/Badger), and only propagates genuine store errors.3. Drop the
config.StartBlockfallback, anchor on chain head (internal/worker/regular.go)determineStartingBlock: if KV has a prior block → resume (+ queue the gap for catchup); cold start / store down →waitForChainHead()waits until the chain responds (honoringctx).getLatestBlockWithRetrydoes bounded retries on the resume-from-KV path.config.StartBlock(config field kept, now unused).4. Cleanup / refactor (
internal/worker/regular.go)queueCatchupRanges, shared bydetermineStartingBlockandskipAheadIfLagging(removed duplication).processRegularBlocks(~90 → ~45 lines) intoprocessBatch+commitProgress.checkContinuity(only referenced by a test).Tests
internal/rpc/failover_test.go: TLS error blacklists the provider (tls_error).internal/worker/regular_test.go:determineStartingBlockcases — store down + chain up, wait-for-head (chain fails transiently then recovers), cold start, ctx-cancel → 0, resume from KV.pkg/store/blockstore/store_test.go:GetLatestBlockreturns(0, nil)on missing key, propagates real store errors.go build ./...,go vet, and all tests in the affected packages pass.