Skip to content

Commit

Permalink
Merge pull request #6415 from filecoin-project/fix/getblock
Browse files Browse the repository at this point in the history
feat: fix GetBlock for null rounds by returning nil
  • Loading branch information
simlecode authored Oct 15, 2024
2 parents ed28098 + 651409a commit 8f3035f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/submodule/eth/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func (e *ethAPIDummy) EthGetBlockByHash(ctx context.Context, blkHash types.EthHa
return types.EthBlock{}, ErrModuleDisabled
}

func (e *ethAPIDummy) EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (types.EthBlock, error) {
return types.EthBlock{}, ErrModuleDisabled
func (e *ethAPIDummy) EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (*types.EthBlock, error) {
return nil, ErrModuleDisabled
}

func (e *ethAPIDummy) EthGetTransactionByHash(ctx context.Context, txHash *types.EthHash) (*types.EthTx, error) {
Expand Down
17 changes: 14 additions & 3 deletions app/submodule/eth/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,23 @@ func (a *ethAPI) parseBlkParam(ctx context.Context, blkParam string, strict bool
}
}

func (a *ethAPI) EthGetBlockByNumber(ctx context.Context, blkParam string, fullTxInfo bool) (types.EthBlock, error) {
func (a *ethAPI) EthGetBlockByNumber(ctx context.Context, blkParam string, fullTxInfo bool) (*types.EthBlock, error) {
// Get the tipset for the specified block parameter
ts, err := a.parseBlkParam(ctx, blkParam, true)
if err != nil {
return types.EthBlock{}, err
if err == ErrNullRound {
// Return nil for null rounds
return nil, nil
}
return nil, xerrors.Errorf("failed to get tipset: %w", err)
}
return newEthBlockFromFilecoinTipSet(ctx, ts, fullTxInfo, a.em.chainModule.MessageStore, a.em.chainModule.Stmgr)
// Create an Ethereum block from the Filecoin tipset
block, err := newEthBlockFromFilecoinTipSet(ctx, ts, fullTxInfo, a.em.chainModule.MessageStore, a.em.chainModule.Stmgr)
if err != nil {
return nil, xerrors.Errorf("failed to create Ethereum block: %w", err)
}

return &block, nil
}

func (a *ethAPI) EthGetTransactionByHash(ctx context.Context, txHash *types.EthHash) (*types.EthTx, error) {
Expand Down
2 changes: 1 addition & 1 deletion venus-shared/api/chain/v1/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type IETH interface {
EthGetBlockTransactionCountByHash(ctx context.Context, blkHash types.EthHash) (types.EthUint64, error) //perm:read

EthGetBlockByHash(ctx context.Context, blkHash types.EthHash, fullTxInfo bool) (types.EthBlock, error) //perm:read
EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (types.EthBlock, error) //perm:read
EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (*types.EthBlock, error) //perm:read
EthGetTransactionByHash(ctx context.Context, txHash *types.EthHash) (*types.EthTx, error) //perm:read
EthGetTransactionByHashLimited(ctx context.Context, txHash *types.EthHash, limit abi.ChainEpoch) (*types.EthTx, error) //perm:read
EthGetTransactionHashByCid(ctx context.Context, cid cid.Cid) (*types.EthHash, error) //perm:read
Expand Down
4 changes: 2 additions & 2 deletions venus-shared/api/chain/v1/mock/mock_fullnode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions venus-shared/api/chain/v1/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion venus-shared/compatible-checks/api-diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v1.FullNode <> github.c
+ Concurrent
- CreateBackup
- Discover
> EthGetBlockByNumber {[func(context.Context, string, bool) (types.EthBlock, error) <> func(context.Context, string, bool) (*ethtypes.EthBlock, error)] base=func out type: #0 input; nested={[types.EthBlock <> *ethtypes.EthBlock] base=type kinds: struct != ptr; nested=nil}}
- EthGetBlockReceipts
- EthGetBlockReceiptsLimited
- EthSendRawTransactionUntrusted
Expand Down

0 comments on commit 8f3035f

Please sign in to comment.