evmrpc: refactor getHeader to always require tmBlock, fix CurrentHeader block fetch#3274
evmrpc: refactor getHeader to always require tmBlock, fix CurrentHeader block fetch#3274amir-deris wants to merge 2 commits intomainfrom
Conversation
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3274 +/- ##
=======================================
Coverage 59.30% 59.30%
=======================================
Files 2071 2071
Lines 169814 169816 +2
=======================================
+ Hits 100707 100709 +2
Misses 60333 60333
Partials 8774 8774
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
| func (b *Backend) CurrentHeader() *ethtypes.Header { | ||
| header := b.getHeader(context.Background(), big.NewInt(b.ctxProvider(LatestCtxHeight).BlockHeight()), nil) | ||
| height := b.ctxProvider(LatestCtxHeight).BlockHeight() | ||
| ctx := context.Background() |
There was a problem hiding this comment.
Out of scope for this PR, but a first glance this seems off but something to look into later.
There was a problem hiding this comment.
That is a good point. I actually tried passing in context as an argument for CurrentHeader, but the issue is the Backend is supposed to implement the interface in go ethereum:
https://github.com/ethereum/go-ethereum/blob/master/internal/ethapi/backend.go#L64
and passing an extra argument breaks that contract.
Summary
getHeaderpreviously accepted an optionalblockNumber *big.Intand a nullabletmBlock, doing its own block fetch whentmBlockwas nil. This PR removes that dual path:getHeadernow always receives a non-niltmBlockand derives the height from it directly.CurrentHeaderis updated to accept acontext.Context, fetch the Tendermint block itself, and callgetHeaderwith it. A newfallbackEthereumHeaderWithoutTendermintBlockhelper handles the error path (block RPC unavailable).header.Timenow uses the actual block timestamp (tmBlock.Block.Time) instead oftime.Now(), andheader.ParentHashis always populated sincetmBlockis never nil.