Skip to content

fix(worker): don't queue catchup from genesis on cold start#105

Open
vietddude wants to merge 1 commit into
mainfrom
fix/catchup-cold-start-issue-104
Open

fix(worker): don't queue catchup from genesis on cold start#105
vietddude wants to merge 1 commit into
mainfrom
fix/catchup-cold-start-issue-104

Conversation

@vietddude

Copy link
Copy Markdown
Collaborator

Problem

Fixes #104 — regression from #102.

PR #102 changed GetLatestBlock to return (0, nil) for a missing key (cold start) instead of an error. CatchupWorker.loadCatchupProgress was not updated: it saw err == nil and treated latest = 0 as a real indexed block, so starting a brand-new chain queued a catchup range from block 1 to chain head — on BSC that's ~109M blocks split into ~5.4M sub-ranges — and hung batch-saving them to the KV store, while also being set up to re-index the whole chain from genesis.

Changes

  • internal/worker/catchup.go: skip catchup-range creation when latest == 0 — a cold start has no prior progress to catch up from; the regular worker anchors on chain head (as designed in fix: treat TLS errors as failover-worthy and remove unsafe start-block fallback #102). Also removed an unreachable head <= latest branch.
  • internal/worker/regular_test.go: regression tests — cold start queues nothing; resume from KV queues exactly the gap.

Audited all other workers (regular, rescanner, recovery, manual, mempool, bloom_sync) — no other call site assumes the old error-on-missing-key behavior.

Note for operators

Deployments that ran the broken build against a new chain may have millions of junk catchup ranges persisted in Consul/Badger — delete that chain's catchup keys before restarting.

go build ./..., go vet, and all tests in the affected packages pass.

Since PR #102, GetLatestBlock returns (0, nil) for a missing key instead
of an error. CatchupWorker.loadCatchupProgress still treated 0 as a real
indexed block, so starting a new chain queued a catchup range from block
1 to chain head (millions of sub-ranges) and hung batch-saving them.

Skip range creation when latest == 0: a cold start has no prior progress
to catch up from; the regular worker anchors on chain head instead.

Fixes #104
@vietddude vietddude requested a review from anhthii July 10, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PR 102 introduce a regression bug: when start indexing a new chain, it starts from block 0 and hang

1 participant