Skip to content

fix(rpc): use the resolved block height for eth_getBlockReceipts results - #1286

Open
kriss39 wants to merge 4 commits into
cosmos:mainfrom
kriss39:fix/rpc-block-receipts-height
Open

kriss39 wants to merge 4 commits into
cosmos:mainfrom
kriss39:fix/rpc-block-receipts-height

Conversation

@kriss39

@kriss39 kriss39 commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Description

GetBlockReceipts resolved the requested block to a concrete height for the block lookup but then called BlockResults with blockNum.CmtHeight(), which is nil for the latest tag and makes CometBFT return the results of its current head. If a block was committed in between, the txs of block H were paired with the results of block H+1: EthMsgsFromCometBlock either panics with an index out of range (surfacing to the client as method handler crashed) or the receipts silently carry the status/gasUsed/logs of the wrong block. The resBlock == nil branch also dereferenced *blockNum.CmtHeight(), nil for latest.

This PR fetches the results of resBlock.Block.Height, like every other block query in the backend already does, and guards against a nil block.

Review notes:

  • rpc/backend/blocks.go: the two-line change in GetBlockReceipts.
  • tests/integration/rpc/backend/test_block_receipts.go: TestGetBlockReceiptsLatest registers Block(&10) with one indexed eth tx and a BlockResults(nil) mock that returns an empty newer block; on main it panics with index out of range [0] with length 0, with the fix it returns the receipt of block 10 and asserts that BlockResults is never called with a nil height.

Closes: #1280


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • tackled an existing issue or discussed with a team member
  • left instructions on how to review the changes
  • targeted the main branch

GetBlockReceipts resolved the requested block to a concrete height for the
block lookup but then called BlockResults with blockNum.CmtHeight(), which
is nil for the "latest" tag and makes CometBFT return the results of its
current head. If a block was committed in between, the txs of block H were
paired with the results of block H+1, which either panics with an index out
of range in EthMsgsFromCometBlock (surfacing as "method handler crashed")
or silently returns receipts with the wrong status/gasUsed/logs.

Always fetch the results of resBlock.Block.Height, like the other block
queries do, and guard against a nil block before dereferencing it.

Closes cosmos#1280
@kriss39
kriss39 requested a review from a team as a code owner September 13, 2026 20:28
@greptile-apps

greptile-apps Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.68%. Comparing base (6cc4bde) to head (47105b3).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
rpc/backend/blocks.go 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1286      +/-   ##
==========================================
+ Coverage   67.58%   67.68%   +0.09%     
==========================================
  Files         321      321              
  Lines       23467    23467              
==========================================
+ Hits        15861    15884      +23     
+ Misses       6426     6396      -30     
- Partials     1180     1187       +7     
Files with missing lines Coverage Δ
rpc/backend/blocks.go 73.22% <33.33%> (+13.38%) ⬆️

... and 2 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.

@kriss39
kriss39 force-pushed the fix/rpc-block-receipts-height branch from 656f637 to 1d9dd08 Compare September 22, 2026 11:49
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.

[Bug] eth_getBlockReceipts("latest") pairs the txs of block H with the results of block H+1 (panic / wrong receipts)

1 participant