Skip to content

fix 400 error on /cosmos/tx/v1beta1/txs/block/ with block with no transactions#3259

Open
h45hc47 wants to merge 3 commits into
sei-protocol:mainfrom
h45hc47:main
Open

fix 400 error on /cosmos/tx/v1beta1/txs/block/ with block with no transactions#3259
h45hc47 wants to merge 3 commits into
sei-protocol:mainfrom
h45hc47:main

Conversation

@h45hc47
Copy link
Copy Markdown

@h45hc47 h45hc47 commented Apr 16, 2026

The current condition offset >= blockTxsLn incorrectly rejects valid requests when offset = 0 and blockTxsLn = 0, so on empty blocks node return error

{
    "code": 3,
    "message": "out of range: cannot paginate 0 txs with offset 0 and limit 100: invalid request: invalid request",
    "details": []
}

Changing to offset > blockTxsLn is save because:

  1. Iteration bounds are protected: the actual transaction processing loops have their own bounds checking:
    • Forward pagination: i < blockTxsLn && count != limit
    • Reverse pagination: i > 0 && count != limit
  2. Invalid offsets are still rejected: offsets greater than the number of transactions (like offset = 1 when blockTxsLn = 0) will still be properly rejected

Now node return valid response on empty blocks.

Issue: #3239

@cursor
Copy link
Copy Markdown

cursor Bot commented May 24, 2026

PR Summary

Low Risk
Single boundary-condition change in gRPC pagination; no auth, state, or consensus impact.

Overview
Fixes GetBlockWithTxs so /cosmos/tx/v1beta1/txs/block/ no longer returns 400 on blocks with zero transactions when offset is 0.

The out-of-range check is tightened from offset >= blockTxsLn to offset > blockTxsLn, so an empty block with default pagination is accepted and returns an empty txs list instead of "cannot paginate 0 txs with offset 0". Offsets past the tx count are still rejected; forward/reverse loops already bound iteration.

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

Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 2b5cb8b. Configure here.

blockTxsLn := uint64(len(blockTxs))
txs := make([]*txtypes.Tx, 0, limit)
if offset >= blockTxsLn {
if offset > blockTxsLn {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Out-of-bounds panic in reverse pagination path

High Severity

Changing the guard from offset >= blockTxsLn to offset > blockTxsLn now allows offset == blockTxsLn (when non-zero) to pass through. In the reverse pagination loop, the first iteration calls decodeTxAt(offset) which accesses blockTxs[blockTxsLn] — an out-of-bounds index that causes a runtime panic. For example, a block with 5 txs and offset=5 with reverse=true would crash the node. The fix for empty blocks is correct, but needs an additional bounds check for reverse pagination when offset == blockTxsLn > 0.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 2b5cb8b. Configure here.

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.

1 participant