Skip to content

chore (evmrpc): fix eth_getBlockTransactionCountByHash hash lookup consistency#3069

Open
mojtaba-esk wants to merge 1 commit intomainfrom
mojtaba/fix-eth_getBlockTransactionCountByHash-hash-lookup-consistency
Open

chore (evmrpc): fix eth_getBlockTransactionCountByHash hash lookup consistency#3069
mojtaba-esk wants to merge 1 commit intomainfrom
mojtaba/fix-eth_getBlockTransactionCountByHash-hash-lookup-consistency

Conversation

@mojtaba-esk
Copy link
Contributor

@mojtaba-esk mojtaba-esk commented Mar 13, 2026

Describe your changes and provide context

Closes PLT-164

Ref: PLT-164

Testing performed to validate your change

=== RUN   TestEVMRPCSpec/eth_getBlockTransactionCountByHash/get-block-n.iox
=== RUN   TestEVMRPCSpec/eth_getBlockTransactionCountByHash/get-genesis.iox
    --- PASS: TestEVMRPCSpec/eth_getBlockTransactionCountByHash/get-block-n.iox (0.00s)
    --- PASS: TestEVMRPCSpec/eth_getBlockTransactionCountByHash/get-genesis.iox (0.00s)

@mojtaba-esk mojtaba-esk requested review from masih and monty-sei March 13, 2026 13:47
@mojtaba-esk mojtaba-esk self-assigned this Mar 13, 2026
@mojtaba-esk mojtaba-esk changed the title chore (evmrpc): fix eth_getBlockTransactionCountByHash hash lookup co… chore (evmrpc): fix eth_getBlockTransactionCountByHash hash lookup consistency Mar 13, 2026
@github-actions
Copy link

github-actions bot commented Mar 13, 2026

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMar 13, 2026, 1:48 PM

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 92.59259% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.59%. Comparing base (c6b1a49) to head (3a6e260).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
evmrpc/block.go 92.59% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3069   +/-   ##
=======================================
  Coverage   58.58%   58.59%           
=======================================
  Files        2080     2080           
  Lines      171656   171661    +5     
=======================================
+ Hits       100567   100577   +10     
+ Misses      62166    62159    -7     
- Partials     8923     8925    +2     
Flag Coverage Δ
sei-chain-pr 67.33% <92.59%> (?)
sei-db 70.41% <ø> (ø)

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

Files with missing lines Coverage Δ
evmrpc/block.go 78.20% <92.59%> (+2.14%) ⬆️
🚀 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.

Copy link
Collaborator

@masih masih left a comment

Choose a reason for hiding this comment

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

No blockers, left a few suggestions.

Also worth looking at:

  • GetBlockReceipts and GetBlockNumberByNrOrHash which are not covered by fixes here. If a client passes the genesis hash to eth_getBlockReceipts, it will fail with the same error this PR fixes for the other two endpoints.
  • GetBlockTransactionCountByNumber("0x0") also needs fixing right?
  • GetBlockByNumberExcludeTraceFail needs genesis check too.

🚀

// must recognize this so that count/block-by-hash stay consistent with block-by-number.
var GenesisBlockHash = common.HexToHash("0xF9D3845DF25B43B1C6926F3CEDA6845C17F5624E12212FD8847D0BA01DA1AB9E")

func encodeGenesisBlock() map[string]interface{} {
Copy link
Collaborator

Choose a reason for hiding this comment

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

use any instead of interface{} whenever you can. I am hoping to slowly phase out the old syntax.


// GenesisBlockHash is the block hash returned by GetBlockByNumber("0x0"). Hash-based lookups
// must recognize this so that count/block-by-hash stay consistent with block-by-number.
var GenesisBlockHash = common.HexToHash("0xF9D3845DF25B43B1C6926F3CEDA6845C17F5624E12212FD8847D0BA01DA1AB9E")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I recommend not exporting this variable if we don't need to.

Suggested change
var GenesisBlockHash = common.HexToHash("0xF9D3845DF25B43B1C6926F3CEDA6845C17F5624E12212FD8847D0BA01DA1AB9E")
var genesisBlockHash = common.HexToHash("0xF9D3845DF25B43B1C6926F3CEDA6845C17F5624E12212FD8847D0BA01DA1AB9E")

func encodeGenesisBlock() map[string]interface{} {
return map[string]interface{}{
"number": (*hexutil.Big)(big.NewInt(0)),
"hash": "0xF9D3845DF25B43B1C6926F3CEDA6845C17F5624E12212FD8847D0BA01DA1AB9E",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Extract the hash as a const and use in both places?

startTime := time.Now()
defer recordMetricsWithError(fmt.Sprintf("%s_getBlockTransactionCountByHash", a.namespace), a.connectionType, startTime, returnErr)
if blockHash == GenesisBlockHash {
return a.getEvmTxCount(nil, 0), nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is correct but i worry that it is fragile. a simple refactor in getEvmTxCount could cause panics given the nil txs passed in.

Why not use hexutil.Uint(0) directly, or whatever that results in? You can even define it as a var/const.

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