fix: Eth JSON-RPC API: eth_getTransactionByHash should return nil when not found.

This commit is contained in:
Raúl Kripalani 2022-12-22 11:47:46 +00:00
parent e7aa7cb04f
commit bb5cb19607

View File

@ -237,19 +237,22 @@ func (a *EthModule) EthGetTransactionByHash(ctx context.Context, txHash *ethtype
// if not found, try to get it from the mempool // if not found, try to get it from the mempool
pending, err := a.MpoolAPI.MpoolPending(ctx, types.EmptyTSK) pending, err := a.MpoolAPI.MpoolPending(ctx, types.EmptyTSK)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot get pending txs from mpool: %v", err) // inability to fetch mpool pending transactions is an internal node error
// that needs to be reported as-is
return nil, fmt.Errorf("cannot get pending txs from mpool: %s", err)
} }
for _, p := range pending { for _, p := range pending {
if p.Cid() == cid { if p.Cid() == cid {
tx, err := newEthTxFromFilecoinMessage(ctx, p, a.StateAPI) tx, err := newEthTxFromFilecoinMessage(ctx, p, a.StateAPI)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot get parse message into tx: %v", err) return nil, fmt.Errorf("could not convert Filecoin message into tx: %s", err)
} }
return &tx, nil return &tx, nil
} }
} }
return nil, fmt.Errorf("cannot find cid %v from the mpool", cid) // Ethereum clients expect an empty response when the message was not found
return nil, nil
} }
func (a *EthModule) EthGetTransactionCount(ctx context.Context, sender ethtypes.EthAddress, blkParam string) (ethtypes.EthUint64, error) { func (a *EthModule) EthGetTransactionCount(ctx context.Context, sender ethtypes.EthAddress, blkParam string) (ethtypes.EthUint64, error) {