Skip to content

[PLT-700] Add MaxTxSearchResults cap to tx_search and block_search#3608

Open
amir-deris wants to merge 5 commits into
mainfrom
amir/plt-700-sei-tendermint-scan-cap
Open

[PLT-700] Add MaxTxSearchResults cap to tx_search and block_search#3608
amir-deris wants to merge 5 commits into
mainfrom
amir/plt-700-sei-tendermint-scan-cap

Conversation

@amir-deris

@amir-deris amir-deris commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds MaxTxSearchResults field to RPCConfig (default 10,000) with mapstructure tag max-tx-search-results
  • Applies the cap in TxSearch and BlockSearch after sort and before pagination — preserving order_by correctness while bounding response size and pagination work
  • Adds the field to DefaultRPCConfig(), ValidateBasic(), and the toml template
  • Emits a debug log when the cap truncates results so operators can detect broad queries hitting the limit
  • Context propagation from the HTTP request through to the KV scan loops (ctx.Done() checks) was already wired correctly; no changes needed there

API note

total_count now reflects the capped result set (min(matches, max-tx-search-results)), not the true match cardinality above the limit. Clients that need the full match count must use narrower queries or a dedicated indexer.

Files changed

  • sei-tendermint/config/config.go — new field + default + validation
  • sei-tendermint/config/toml.go — template entry
  • sei-tendermint/internal/rpc/core/env.go — debug log helper for cap truncation
  • sei-tendermint/internal/rpc/core/tx.go — cap applied in TxSearch
  • sei-tendermint/internal/rpc/core/blocks.go — cap applied in BlockSearch
  • sei-tendermint/internal/rpc/core/tx_test.go — unit tests
  • sei-tendermint/internal/rpc/core/block_search_test.go — unit tests

Follow-up

The RPC-layer cap does not bound KV indexer memory/CPU: the indexer still materialises and RPC still sorts the full match set before truncation.

Test plan

  • go test ./sei-tendermint/config/... ./sei-tendermint/internal/rpc/core/... -run 'TestRPCConfigValidateBasic|TestTxSearchCap|TestBlockSearchCap' passes
  • Review default value (10,000) is appropriate for production nodes
  • Confirm operators can set max-tx-search-results = 0 to disable the cap if needed

Adds a `max-tx-search-results` config field to RPCConfig (default 10,000)
and applies it in TxSearch and BlockSearch before pagination, preventing
unbounded result sets from materialising in memory on index-heavy queries.
Context propagation from the HTTP request through to the KV scan loops
was already wired correctly; no changes needed there.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cursor

cursor Bot commented Jun 18, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes public RPC semantics for total_count on broad queries and still sorts full indexer results before truncation, so heavy queries can stress nodes until indexer-level limiting exists.

Overview
Adds max-tx-search-results to RPC config (default 10,000; 0 turns the cap off) with validation and config.toml wiring.

TxSearch and BlockSearch truncate the match list after sorting and before pagination, so order_by stays correct and total_count is the capped size, not the full indexer match count.

Unit tests cover post-sort truncation, disabled cap, and when matches are under the limit.

Reviewed by Cursor Bugbot for commit 6008230. Bugbot is set up for automated code reviews on this repo. Configure here.

@amir-deris amir-deris self-assigned this Jun 18, 2026

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 146439f. Configure here.

Comment thread sei-tendermint/internal/rpc/core/tx.go Outdated
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedJun 18, 2026, 10:35 PM

Cap applied before sort caused TxSearch to return an arbitrary subset of
matches instead of the top N by order_by, and BlockSearch with order_by=desc
to omit the newest blocks entirely (indexer returns heights ascending).

Move the cap to after sort and before pagination so the truncation always
preserves the correct ordering intent.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.14%. Comparing base (4f5889e) to head (6008230).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3608      +/-   ##
==========================================
- Coverage   59.02%   58.14%   -0.88%     
==========================================
  Files        2215     2141      -74     
  Lines      182521   173981    -8540     
==========================================
- Hits       107734   101167    -6567     
+ Misses      65091    63819    -1272     
+ Partials     9696     8995     -701     
Flag Coverage Δ
sei-chain-pr 43.93% <100.00%> (?)
sei-db 70.41% <ø> (ø)
sei-db-state-db ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sei-tendermint/config/config.go 73.68% <100.00%> (+0.16%) ⬆️
sei-tendermint/config/toml.go 55.00% <ø> (ø)
sei-tendermint/internal/rpc/core/blocks.go 65.66% <100.00%> (+1.02%) ⬆️
sei-tendermint/internal/rpc/core/tx.go 68.49% <100.00%> (+3.70%) ⬆️

... and 74 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

amir-deris and others added 3 commits June 17, 2026 18:56
…Search

Covers three cases each: cap applied after sort (the ordering-correctness
invariant the cursor bot flagged), cap disabled (MaxTxSearchResults=0),
and results under the cap (full set returned unchanged).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants