Skip to content

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

Open
mojtaba-esk wants to merge 4 commits intomainfrom
mojtaba/fix-eth_getBlockTransactionCountByHash-hash-lookup-consistency
Open

chore (evmrpc): fix eth_getBlockTransactionCountByHash hash lookup consistency#3069
mojtaba-esk wants to merge 4 commits 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 16, 2026, 8:13 AM

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 92.85714% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.58%. Comparing base (bb2c5b3) to head (a48df15).

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.41%   58.58%   +0.16%     
==========================================
  Files        2081     2080       -1     
  Lines      171790   171579     -211     
==========================================
+ Hits       100352   100520     +168     
+ Misses      62504    62140     -364     
+ Partials     8934     8919      -15     
Flag Coverage Δ
sei-chain-pr 67.24% <92.85%> (?)
sei-db 70.41% <ø> (-0.22%) ⬇️

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 41 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.

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.

🚀

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

evmrpc/block.go Outdated
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?

Copy link
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.

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
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
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
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
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