Skip to content

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

Merged
mojtaba-esk merged 7 commits into
mainfrom
mojtaba/fix-eth_getBlockTransactionCountByHash-hash-lookup-consistency
Mar 17, 2026
Merged

chore (evmrpc): fix eth_getBlockTransactionCountByHash hash lookup consistency#3069
mojtaba-esk merged 7 commits into
mainfrom
mojtaba/fix-eth_getBlockTransactionCountByHash-hash-lookup-consistency

Conversation

@mojtaba-esk

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

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented Mar 13, 2026

Copy link
Copy Markdown

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMar 17, 2026, 4:33 PM

@codecov

codecov Bot commented Mar 13, 2026

Copy link
Copy Markdown

Codecov Report

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

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

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3069      +/-   ##
==========================================
+ Coverage   58.42%   58.59%   +0.17%     
==========================================
  Files        2088     2080       -8     
  Lines      172102   171503     -599     
==========================================
- Hits       100547   100491      -56     
+ Misses      62618    62105     -513     
+ Partials     8937     8907      -30     
Flag Coverage Δ
sei-chain-pr 67.24% <92.85%> (?)
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 76.89% <92.85%> (+0.84%) ⬆️

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

@masih masih left a comment

Copy link
Copy Markdown
Collaborator

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.

🚀

Comment thread evmrpc/block.go Outdated
// 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
Copy Markdown
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.

Comment thread evmrpc/block.go Outdated
Comment thread evmrpc/block.go Outdated
func encodeGenesisBlock() map[string]interface{} {
return map[string]interface{}{
"number": (*hexutil.Big)(big.NewInt(0)),
"hash": "0xF9D3845DF25B43B1C6926F3CEDA6845C17F5624E12212FD8847D0BA01DA1AB9E",

Copy link
Copy Markdown
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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah b/c it used more than once, it makes sense to do it.

Comment thread evmrpc/block.go Outdated
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
Copy Markdown
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well when it is nil it does not go to the loop, but you're right in sense of being fragile so I will have a package-level *hexutil.Uint(0) (genesisBlockTxCount) for the genesis block only and so avoid depending on its handling of nil.

mojtaba-esk and others added 3 commits March 16, 2026 10:16
@mojtaba-esk mojtaba-esk requested a review from masih March 16, 2026 08:12
@mojtaba-esk

Copy link
Copy Markdown
Contributor Author

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.

🚀

Thank you Masih jan for the insight, yes I think it worth tracking them and make sure we get consistent behaviour across the endpoints.
3 followups are created to cover that:
https://linear.app/seilabs/issue/PLT-189/evmrpc-accept-genesis-block-hash-in-getblockreceipts-and
https://linear.app/seilabs/issue/PLT-190/evmrpc-sei-getblockbynumberexcludetracefail0x0-should-return-synthetic
https://linear.app/seilabs/issue/PLT-191/evmrpc-getblocktransactioncountbynumber0x0-short-circuit-for

@mojtaba-esk mojtaba-esk enabled auto-merge March 16, 2026 15:02
@mojtaba-esk mojtaba-esk requested a review from bdchatham March 16, 2026 16:35
@mojtaba-esk mojtaba-esk added this pull request to the merge queue Mar 17, 2026
@mojtaba-esk mojtaba-esk removed this pull request from the merge queue due to a manual request Mar 17, 2026
@mojtaba-esk mojtaba-esk added this pull request to the merge queue Mar 17, 2026
Merged via the queue into main with commit 4282c07 Mar 17, 2026
38 checks passed
@mojtaba-esk mojtaba-esk deleted the mojtaba/fix-eth_getBlockTransactionCountByHash-hash-lookup-consistency branch March 17, 2026 17:15
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.

3 participants