fix(evmrpc): return null for out-of-range tx index and fix deferred error capture#3344
Conversation
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
| startTime := time.Now() | ||
| defer recordMetricsWithError("eth_getTransactionReceipt", t.connectionType, startTime, returnErr) | ||
| defer func() { | ||
| recordMetricsWithError("eth_getTransactionReceipt", t.connectionType, startTime, returnErr) |
There was a problem hiding this comment.
The previous format defer functionCall(...) captures arguments at the call site which results in returnErr be nil for recordMetricsWithError.
There was a problem hiding this comment.
A go convention that's worth following is to use _ prefix for named return variables to indicate that "this variable must never be directly set". I would stick with simple names too. e.g. _err.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3344 +/- ##
========================================
Coverage 59.16% 59.17%
========================================
Files 2097 2097
Lines 172613 172377 -236
========================================
- Hits 102129 102002 -127
+ Misses 61617 61533 -84
+ Partials 8867 8842 -25
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Problem
Two bugs in
evmrpc/tx.go:Deferred error capture was always nil —
defer recordMetricsWithError(...)was called directly rather than inside a closure, soreturnErrwas captured at defer-registration time (alwaysnil) instead of at function-return time. This caused metrics to never record actual errors.uint32 overflow returned an error instead of null —
eth_getTransactionByBlockNumberAndIndexandeth_getTransactionByBlockHashAndIndexreturned an RPC error when the transaction index exceededmath.MaxUint32. The Ethereum JSON-RPC spec requires these methods to returnnullfor an out-of-range index, not an error.Fix
defer recordMetricsWithError(...)calls in closures soreturnErris evaluated at return time.txUint32OverflowErrorso the overflow case can be distinguished from other errors.returnErr = nil) inGetTransactionByBlockNumberAndIndexandGetTransactionByBlockHashAndIndexto comply with the Ethereum JSON-RPC spec.Test plan
eth_getTransactionByBlockNumberAndIndexwith a tx index >0xFFFFFFFFreturnsnull, not an erroreth_getTransactionByBlockHashAndIndexwith a tx index >0xFFFFFFFFreturnsnull, not an error