Skip to content

fix(state): propagate tx indexer database errors - #1357

Merged
lklimek merged 2 commits into
v1.6-devfrom
fix/state-indexer-errors
Jun 19, 2026
Merged

lklimek merged 2 commits into
v1.6-devfrom
fix/state-indexer-errors

Conversation

@lklimek

@lklimek lklimek commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

On the synchronous tx-search RPC path, the tx KV indexer panicked on DB read errors instead of returning them — a transient store error would crash the query path.

Changes

  • In internal/state/indexer/tx/kv/kv.go, Get, match, and matchRange now propagate DB read/iteration errors as returned errors instead of panic, so a transient store failure fails the tx-search query gracefully. (Key-encoding helpers keep their encode-cannot-fail panics; those are not on the DB-read path.)

🤖 Generated with Claude Code

The tx KV indexer returned database read failures by panicking inside
Get, match, and matchRange. These run synchronously on the tx-search RPC
path, so a transient storage error terminated the query path instead of
surfacing as a query error.

Convert the storage-error panics to error returns, matching the block KV
indexer sibling: iterator-creation failures and post-iteration
Iterator.Error() failures in match/matchRange now return through Search,
and Get returns a wrapped error. The match/matchRange signatures gain an
error return and Search propagates it. Programming-invariant guards (the
unhandled-operator default and the key-encoding marshalling helpers) keep
their panics. Also converts the match function's untagged switch to a
tagged switch on c.Op (staticcheck QF1002).

Adds table-driven tests covering creation-time and post-iteration
storage errors for Get, match (=, EXISTS, CONTAINS), and matchRange.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@lklimek
lklimek requested a review from QuantumExplorer as a code owner June 17, 2026 13:39
@thepastaclaw

thepastaclaw commented Jun 17, 2026 •

Copy link
Copy Markdown

✅ Review complete (commit f7cd35d)

@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f9066910-cf4b-44ed-bf11-17efa41f4de9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/state-indexer-errors

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

PR #1357 is a clean, well-scoped defensive fix that converts panics from transient DB read failures into propagated errors on the tx-search RPC path in internal/state/indexer/tx/kv/kv.go. The encoding helpers that retain panics (primaryKey/secondaryKey/prefix*) are correctly left alone since they encode literals that cannot fail in practice. Test coverage is solid: the new errorDB/errorIterator harness exercises all three match operators (TEq/TExists/TContains), matchRange, both iterator-open and post-iteration Error() failure modes, and the hash-lookup Get path. No consensus, signing, BLS, quorum, or trust-boundary defects were introduced or exposed.

💬 1 nitpick(s)

Comment thread internal/state/indexer/tx/kv/kv.go Resolved
Four bare `it.Error()` returns in the tx/kv indexer (TEq, TExists,
TContains, and matchRange loops) were emitting raw errors with no
breadcrumb, while the corresponding iterator-open failures had proper
`fmt.Errorf` context. Wrap all four with
"prefix iterator failed during scan: %w" so callers get consistent,
actionable error messages.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

PR #1357 is a narrow, well-scoped defensive fix that converts panics from transient DB read failures in the tx-search RPC path (internal/state/indexer/tx/kv/kv.go) into propagated errors. Head f7cd35d resolves the only prior nit by wrapping all four post-iteration it.Error() returns with prefix iterator failed during scan: %w. Verified directly against the file: lines 311, 335, 366, 470 are wrapped; remaining panics are encode-cannot-fail assertions. No in-scope findings from either agent.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the synchronous tx-search RPC path to gracefully handle transient KV indexer storage failures by returning errors instead of panicking, preventing DB read/iteration errors from crashing the query path.

Changes:

  • Updated TxIndex.Get to return wrapped DB read errors rather than panicking.
  • Refactored match and matchRange to return (map[string][]byte, error) and propagate iterator open/scan errors up through Search.
  • Added focused regression tests to ensure Get/Search never panic and surface injected store errors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/state/indexer/tx/kv/kv.go Propagates KV store read/iterator errors through Get/match/matchRange/Search instead of panicking.
internal/state/indexer/tx/kv/kv_errors_test.go Adds tests that inject DB failures (Get, iterator open, iterator Error) and assert errors are returned without panics.

@lklimek
lklimek merged commit f920675 into v1.6-dev Jun 19, 2026
17 checks passed
@lklimek
lklimek deleted the fix/state-indexer-errors branch June 19, 2026 08:37
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.

3 participants