Skip to content

Commit c674554

Browse files
feat: fix GetBlock for null rounds by returning nil (#12529)
* update pb version * docs: update changelog * fix: remove redundant code in sectors.go * feat: Update EthGetBlockByNumber to return pointer to EthBlock * fix TestGetBlockByNumber * fix: Remove unnecessary assertions tests * Update eth_api_test.go * feat: Refactor EthGetBlockByNumber test in fevm_test.go --------- Co-authored-by: Aarsh Shah <[email protected]>
1 parent 2687f13 commit c674554

File tree

16 files changed

+135
-40
lines changed

16 files changed

+135
-40
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
## Improvements
1414

15-
- Update `TestEthGetTransactionCount` to test for `earliest`, `pending` and `finalized`. ([filecoin-project/lotus#12448](https://github.com/filecoin-project/lotus/pull/12448))
15+
16+
- Update `EthGetBlockByNumber` to return a pointer to ethtypes.EthBlock or nil for null rounds. ([filecoin-project/lotus#12529](https://github.com/filecoin-project/lotus/pull/12529))
1617
- Reduce size of embedded genesis CAR files by removing WASM actor blocks and compressing with zstd. This reduces the `lotus` binary size by approximately 10 MiB. ([filecoin-project/lotus#12439](https://github.com/filecoin-project/lotus/pull/12439))
1718
- Add ChainSafe operated Calibration archival node to the bootstrap list ([filecoin-project/lotus#12517](https://github.com/filecoin-project/lotus/pull/12517))
1819

api/api_full.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ type FullNode interface {
775775
EthGetBlockTransactionCountByHash(ctx context.Context, blkHash ethtypes.EthHash) (ethtypes.EthUint64, error) //perm:read
776776

777777
EthGetBlockByHash(ctx context.Context, blkHash ethtypes.EthHash, fullTxInfo bool) (ethtypes.EthBlock, error) //perm:read
778-
EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (ethtypes.EthBlock, error) //perm:read
778+
EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (*ethtypes.EthBlock, error) //perm:read
779779
EthGetTransactionByHash(ctx context.Context, txHash *ethtypes.EthHash) (*ethtypes.EthTx, error) //perm:read
780780
EthGetTransactionByHashLimited(ctx context.Context, txHash *ethtypes.EthHash, limit abi.ChainEpoch) (*ethtypes.EthTx, error) //perm:read
781781
EthGetTransactionHashByCid(ctx context.Context, cid cid.Cid) (*ethtypes.EthHash, error) //perm:read

api/api_gateway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ type Gateway interface {
9898
EthGetBlockTransactionCountByNumber(ctx context.Context, blkNum ethtypes.EthUint64) (ethtypes.EthUint64, error)
9999
EthGetBlockTransactionCountByHash(ctx context.Context, blkHash ethtypes.EthHash) (ethtypes.EthUint64, error)
100100
EthGetBlockByHash(ctx context.Context, blkHash ethtypes.EthHash, fullTxInfo bool) (ethtypes.EthBlock, error)
101-
EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (ethtypes.EthBlock, error)
101+
EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (*ethtypes.EthBlock, error)
102102
EthGetTransactionByHash(ctx context.Context, txHash *ethtypes.EthHash) (*ethtypes.EthTx, error)
103103
EthGetTransactionByHashLimited(ctx context.Context, txHash *ethtypes.EthHash, limit abi.ChainEpoch) (*ethtypes.EthTx, error)
104104
EthGetTransactionHashByCid(ctx context.Context, cid cid.Cid) (*ethtypes.EthHash, error)

api/mocks/mock_full.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/proxy_gen.go

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/openrpc/full.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,7 +2866,7 @@
28662866
},
28672867
{
28682868
"name": "Filecoin.EthGetBlockByNumber",
2869-
"description": "```go\nfunc (s *FullNodeStruct) EthGetBlockByNumber(p0 context.Context, p1 string, p2 bool) (ethtypes.EthBlock, error) {\n\tif s.Internal.EthGetBlockByNumber == nil {\n\t\treturn *new(ethtypes.EthBlock), ErrNotSupported\n\t}\n\treturn s.Internal.EthGetBlockByNumber(p0, p1, p2)\n}\n```",
2869+
"description": "```go\nfunc (s *FullNodeStruct) EthGetBlockByNumber(p0 context.Context, p1 string, p2 bool) (*ethtypes.EthBlock, error) {\n\tif s.Internal.EthGetBlockByNumber == nil {\n\t\treturn nil, ErrNotSupported\n\t}\n\treturn s.Internal.EthGetBlockByNumber(p0, p1, p2)\n}\n```",
28702870
"summary": "",
28712871
"paramStructure": "by-position",
28722872
"params": [
@@ -2902,8 +2902,8 @@
29022902
}
29032903
],
29042904
"result": {
2905-
"name": "ethtypes.EthBlock",
2906-
"description": "ethtypes.EthBlock",
2905+
"name": "*ethtypes.EthBlock",
2906+
"description": "*ethtypes.EthBlock",
29072907
"summary": "",
29082908
"schema": {
29092909
"examples": [

build/openrpc/gateway.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,7 +2213,7 @@
22132213
},
22142214
{
22152215
"name": "Filecoin.EthGetBlockByNumber",
2216-
"description": "```go\nfunc (s *GatewayStruct) EthGetBlockByNumber(p0 context.Context, p1 string, p2 bool) (ethtypes.EthBlock, error) {\n\tif s.Internal.EthGetBlockByNumber == nil {\n\t\treturn *new(ethtypes.EthBlock), ErrNotSupported\n\t}\n\treturn s.Internal.EthGetBlockByNumber(p0, p1, p2)\n}\n```",
2216+
"description": "```go\nfunc (s *GatewayStruct) EthGetBlockByNumber(p0 context.Context, p1 string, p2 bool) (*ethtypes.EthBlock, error) {\n\tif s.Internal.EthGetBlockByNumber == nil {\n\t\treturn nil, ErrNotSupported\n\t}\n\treturn s.Internal.EthGetBlockByNumber(p0, p1, p2)\n}\n```",
22172217
"summary": "There are not yet any comments for this method.",
22182218
"paramStructure": "by-position",
22192219
"params": [
@@ -2249,8 +2249,8 @@
22492249
}
22502250
],
22512251
"result": {
2252-
"name": "ethtypes.EthBlock",
2253-
"description": "ethtypes.EthBlock",
2252+
"name": "*ethtypes.EthBlock",
2253+
"description": "*ethtypes.EthBlock",
22542254
"summary": "",
22552255
"schema": {
22562256
"examples": [

gateway/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ type TargetAPI interface {
119119
EthGetBlockTransactionCountByNumber(ctx context.Context, blkNum ethtypes.EthUint64) (ethtypes.EthUint64, error)
120120
EthGetBlockTransactionCountByHash(ctx context.Context, blkHash ethtypes.EthHash) (ethtypes.EthUint64, error)
121121
EthGetBlockByHash(ctx context.Context, blkHash ethtypes.EthHash, fullTxInfo bool) (ethtypes.EthBlock, error)
122-
EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (ethtypes.EthBlock, error)
122+
EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (*ethtypes.EthBlock, error)
123123
EthGetTransactionByHashLimited(ctx context.Context, txHash *ethtypes.EthHash, limit abi.ChainEpoch) (*ethtypes.EthTx, error)
124124
EthGetTransactionHashByCid(ctx context.Context, cid cid.Cid) (*ethtypes.EthHash, error)
125125
EthGetMessageCidByTransactionHash(ctx context.Context, txHash *ethtypes.EthHash) (*cid.Cid, error)

gateway/proxy_eth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ func (gw *Node) EthGetBlockByHash(ctx context.Context, blkHash ethtypes.EthHash,
188188
return gw.target.EthGetBlockByHash(ctx, blkHash, fullTxInfo)
189189
}
190190

191-
func (gw *Node) EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (ethtypes.EthBlock, error) {
191+
func (gw *Node) EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (*ethtypes.EthBlock, error) {
192192
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
193-
return ethtypes.EthBlock{}, err
193+
return nil, err
194194
}
195195

196196
if err := gw.checkBlkParam(ctx, blkNum, 0); err != nil {
197-
return ethtypes.EthBlock{}, err
197+
return nil, err
198198
}
199199

200200
return gw.target.EthGetBlockByNumber(ctx, blkNum, fullTxInfo)

itests/eth_api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ func TestEthBlockNumberAliases(t *testing.T) {
408408

409409
head := client.WaitTillChain(ctx, kit.HeightAtLeast(policy.ChainFinality+100))
410410
// latest should be head-1 (parents)
411-
var latestEthBlk ethtypes.EthBlock
411+
var latestEthBlk *ethtypes.EthBlock
412412
for {
413413
var err error
414414
latestEthBlk, err = client.EVM().EthGetBlockByNumber(ctx, "latest", true)

0 commit comments

Comments
 (0)