Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions evmrpc/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ func getTransactionReceipt(
// Fetch block once — used both for ante-failure receipt population and encoding.
height := int64(receipt.BlockNumber) //nolint:gosec
block, err := blockByNumberRespectingWatermarks(ctx, t.tmClient, t.watermarks, &height, 1)
// Ethereum JSON-RPC: receipt for a block above safe latest => null, not an error.
if errors.Is(err, ErrBlockHeightNotYetAvailable) {
return nil, nil
}
if err != nil {
return nil, err
}
Expand Down
47 changes: 47 additions & 0 deletions evmrpc/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/sei-protocol/sei-chain/sei-cosmos/crypto/hd"
"github.com/sei-protocol/sei-chain/sei-cosmos/crypto/keyring"
sdk "github.com/sei-protocol/sei-chain/sei-cosmos/types"
"github.com/sei-protocol/sei-chain/sei-tendermint/rpc/client/mock"
"github.com/sei-protocol/sei-chain/sei-tendermint/rpc/coretypes"
testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/x/evm/state"
"github.com/sei-protocol/sei-chain/x/evm/types"
Expand Down Expand Up @@ -290,6 +292,51 @@ func TestGetTransactionReceiptExcludeTraceFailLateReceipt(t *testing.T) {
}
}

// lowLatestTMClient reports a fixed LatestBlockHeight via Status, regardless
// of what blocks the receipt store contains.
type lowLatestTMClient struct {
mock.Client
latest int64
}

func (c *lowLatestTMClient) EvmNextPendingNonce(common.Address) uint64 { return 0 }

func (c *lowLatestTMClient) EvmProxy(common.Address) (*url.URL, bool) { return nil, false }

func (c *lowLatestTMClient) Status(context.Context) (*coretypes.ResultStatus, error) {
return &coretypes.ResultStatus{
SyncInfo: coretypes.SyncInfo{LatestBlockHeight: c.latest, EarliestBlockHeight: 1},
}, nil
}

// When the receipt's block sits above the safe-latest watermark (e.g. tendermint
// status lags the receipt store by a block), eth_getTransactionReceipt must
// return JSON null — the spec's "not yet mined" signal — so clients poll again,
// matching what eth_getBlockByNumber already does.
func TestGetTransactionReceiptReturnsNullAboveWatermark(t *testing.T) {
var hashBytes [32]byte
_, err := rand.Read(hashBytes[:])
require.NoError(t, err)
hash := common.Hash(hashBytes)

receiptHeight := int64(MockHeight8 + 100)
testkeeper.MustMockReceipt(t, EVMKeeper, Ctx, hash, &types.Receipt{
BlockNumber: uint64(receiptHeight),
TxHashHex: hash.Hex(),
Status: 1,
EffectiveGasPrice: 1000000,
})

tmClient := &lowLatestTMClient{latest: MockHeight8}
ctxProvider := func(int64) sdk.Context { return Ctx.WithBlockHeight(MockHeight8) }
watermarks := evmrpc.NewWatermarkManager(tmClient, ctxProvider, nil, nil)
txAPI := evmrpc.NewTransactionAPI(tmClient, EVMKeeper, ctxProvider, nil, t.TempDir(), evmrpc.ConnectionTypeHTTP, watermarks, evmrpc.NewBlockCache(8), &sync.Mutex{})

result, err := txAPI.GetTransactionReceipt(context.Background(), hash)
require.NoError(t, err)
require.Nil(t, result)
}

func TestCumulativeGasUsedPopulation(t *testing.T) {
blockHeight := int64(1000)
Ctx = Ctx.WithBlockHeight(blockHeight)
Expand Down
Loading