Skip to content

Commit

Permalink
feat: fix GetBlock for null rounds by returning nil
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmair committed Oct 14, 2024
1 parent a550fc3 commit b130684
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 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.

0 comments on commit b130684

Please sign in to comment.