From b130684bcab26a3e427f0d5bc0fbc76186ea07b7 Mon Sep 17 00:00:00 2001 From: vladmair Date: Mon, 14 Oct 2024 18:14:50 +0800 Subject: [PATCH 1/2] feat: fix GetBlock for null rounds by returning nil --- app/submodule/eth/dummy.go | 4 ++-- app/submodule/eth/eth_api.go | 17 ++++++++++++++--- venus-shared/api/chain/v1/eth.go | 2 +- venus-shared/api/chain/v1/mock/mock_fullnode.go | 4 ++-- venus-shared/api/chain/v1/proxy_gen.go | 4 ++-- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/submodule/eth/dummy.go b/app/submodule/eth/dummy.go index 254d01a282..0c9a74c9c5 100644 --- a/app/submodule/eth/dummy.go +++ b/app/submodule/eth/dummy.go @@ -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) { diff --git a/app/submodule/eth/eth_api.go b/app/submodule/eth/eth_api.go index 4e7a23869b..9f6fcea255 100644 --- a/app/submodule/eth/eth_api.go +++ b/app/submodule/eth/eth_api.go @@ -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) { diff --git a/venus-shared/api/chain/v1/eth.go b/venus-shared/api/chain/v1/eth.go index 8636ae4702..f0c1a84ec1 100644 --- a/venus-shared/api/chain/v1/eth.go +++ b/venus-shared/api/chain/v1/eth.go @@ -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 diff --git a/venus-shared/api/chain/v1/mock/mock_fullnode.go b/venus-shared/api/chain/v1/mock/mock_fullnode.go index 4461c949a7..45e79c94cc 100644 --- a/venus-shared/api/chain/v1/mock/mock_fullnode.go +++ b/venus-shared/api/chain/v1/mock/mock_fullnode.go @@ -610,10 +610,10 @@ func (mr *MockFullNodeMockRecorder) EthGetBlockByHash(arg0, arg1, arg2 interface } // EthGetBlockByNumber mocks base method. -func (m *MockFullNode) EthGetBlockByNumber(arg0 context.Context, arg1 string, arg2 bool) (types.EthBlock, error) { +func (m *MockFullNode) EthGetBlockByNumber(arg0 context.Context, arg1 string, arg2 bool) (*types.EthBlock, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "EthGetBlockByNumber", arg0, arg1, arg2) - ret0, _ := ret[0].(types.EthBlock) + ret0, _ := ret[0].(*types.EthBlock) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/venus-shared/api/chain/v1/proxy_gen.go b/venus-shared/api/chain/v1/proxy_gen.go index abb7cef208..7f90228407 100644 --- a/venus-shared/api/chain/v1/proxy_gen.go +++ b/venus-shared/api/chain/v1/proxy_gen.go @@ -884,7 +884,7 @@ type IETHStruct struct { EthGasPrice func(ctx context.Context) (types.EthBigInt, error) `perm:"read"` EthGetBalance func(ctx context.Context, address types.EthAddress, blkParam types.EthBlockNumberOrHash) (types.EthBigInt, error) `perm:"read"` EthGetBlockByHash func(ctx context.Context, blkHash types.EthHash, fullTxInfo bool) (types.EthBlock, error) `perm:"read"` - EthGetBlockByNumber func(ctx context.Context, blkNum string, fullTxInfo bool) (types.EthBlock, error) `perm:"read"` + EthGetBlockByNumber func(ctx context.Context, blkNum string, fullTxInfo bool) (*types.EthBlock, error) `perm:"read"` EthGetBlockTransactionCountByHash func(ctx context.Context, blkHash types.EthHash) (types.EthUint64, error) `perm:"read"` EthGetBlockTransactionCountByNumber func(ctx context.Context, blkNum types.EthUint64) (types.EthUint64, error) `perm:"read"` EthGetCode func(ctx context.Context, address types.EthAddress, blkParam types.EthBlockNumberOrHash) (types.EthBytes, error) `perm:"read"` @@ -942,7 +942,7 @@ func (s *IETHStruct) EthGetBalance(p0 context.Context, p1 types.EthAddress, p2 t func (s *IETHStruct) EthGetBlockByHash(p0 context.Context, p1 types.EthHash, p2 bool) (types.EthBlock, error) { return s.Internal.EthGetBlockByHash(p0, p1, p2) } -func (s *IETHStruct) EthGetBlockByNumber(p0 context.Context, p1 string, p2 bool) (types.EthBlock, error) { +func (s *IETHStruct) EthGetBlockByNumber(p0 context.Context, p1 string, p2 bool) (*types.EthBlock, error) { return s.Internal.EthGetBlockByNumber(p0, p1, p2) } func (s *IETHStruct) EthGetBlockTransactionCountByHash(p0 context.Context, p1 types.EthHash) (types.EthUint64, error) { From 651409a773980ffe44e271589ceb7199ad772643 Mon Sep 17 00:00:00 2001 From: vladmair Date: Tue, 15 Oct 2024 09:04:58 +0800 Subject: [PATCH 2/2] make api-diff.txt --- venus-shared/compatible-checks/api-diff.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/venus-shared/compatible-checks/api-diff.txt b/venus-shared/compatible-checks/api-diff.txt index dde37e80b8..4d839cac2c 100644 --- a/venus-shared/compatible-checks/api-diff.txt +++ b/venus-shared/compatible-checks/api-diff.txt @@ -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