Skip to content

Conversation

@brbrr
Copy link
Contributor

@brbrr brbrr commented Nov 24, 2025

fixes #3257

@brbrr brbrr self-assigned this Nov 24, 2025
Copilot AI review requested due to automatic review settings November 24, 2025 10:26
Copilot finished reviewing on behalf of brbrr November 24, 2025 10:28
Copy link
Contributor

Copilot AI left a comment

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 optimizes the TransactionByBlockIDAndIndex method by fetching only the block number instead of the full block header. It introduces a new BlockNumberByHash method in the blockchain reader interface to support this optimization. However, the implementation has critical bugs that break existing functionality for latest and l1Accepted block ID types.

  • Adds BlockNumberByHash method to blockchain reader interface for efficient block number lookup
  • Refactors TransactionByBlockIDAndIndex to avoid fetching full headers for hash-based lookups
  • Introduces bugs for latest and l1Accepted block ID types

Reviewed changes

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

File Description
rpc/v9/transaction.go Refactors TransactionByBlockIDAndIndex to use block number directly instead of fetching full header, but incorrectly returns ErrBlockNotFound for latest and l1Accepted block types
blockchain/blockchain.go Adds BlockNumberByHash interface method and implementation to retrieve block number from hash without fetching full header

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
case number:
blockNumber = blockID.Number()
case l1Accepted, preConfirmed, latest:
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The latest and l1Accepted cases should resolve to their respective block numbers, not return ErrBlockNotFound. Based on blockHeaderByID in helpers.go (lines 81-93), latest should use HeadsHeader() to get the block number, and l1Accepted should call L1Head() to get the block number. The current implementation breaks existing functionality for these block ID types.

Suggested change
case l1Accepted, preConfirmed, latest:
case l1Accepted:
header := h.L1Head()
if header == nil {
return nil, rpccore.ErrBlockNotFound
}
blockNumber = header.Number
case latest:
header := h.HeadsHeader()
if header == nil {
return nil, rpccore.ErrBlockNotFound
}
blockNumber = header.Number
case preConfirmed:

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

l1Accepted should be like this, but use ChainHeight() for latest and PendingData() for preconfirmed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

preConfirmed case is covered above the switch case. Also, it seems that we could follow the same logic for latest (assuming h.bcReader.Head() is better than following default code path)

Co-authored-by: Dat Duong <[email protected]>
Signed-off-by: Yaroslav Kukharuk <[email protected]>
}

txn, err := h.bcReader.TransactionByBlockNumberAndIndex(header.Number, uint64(txIndex))
txn, err := h.bcReader.TransactionByBlockNumberAndIndex(blockNumber, uint64(txIndex))
Copy link
Contributor

Choose a reason for hiding this comment

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

We're having 4 versions in v6, v7, v8 and v9, please also fix for the other versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, I'll update other versions, once the v9 implementation is good enough :)

@codecov
Copy link

codecov bot commented Nov 25, 2025

Codecov Report

❌ Patch coverage is 88.15789% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.17%. Comparing base (584e500) to head (008aa87).

Files with missing lines Patch % Lines
rpc/v9/transaction.go 83.33% 3 Missing and 1 partial ⚠️
blockchain/blockchain.go 0.00% 3 Missing ⚠️
rpc/v8/transaction.go 88.88% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3296      +/-   ##
==========================================
- Coverage   76.20%   76.17%   -0.04%     
==========================================
  Files         346      346              
  Lines       32690    32745      +55     
==========================================
+ Hits        24912    24942      +30     
- Misses       5987     6007      +20     
- Partials     1791     1796       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@brbrr brbrr changed the title chore(rpcv9): Fetch only block number for TransactionByBlockIDAndIndex chore(rpc): Fetch only block number for TransactionByBlockIDAndIndex Nov 26, 2025
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.

starknet_getTransactionByBlockIdAndIndex doesn't have to query block header

3 participants