Skip to content
2 changes: 1 addition & 1 deletion ante/evm/11_emit_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func EmitTxHashEvent(ctx sdk.Context, msg *evmtypes.MsgEthereumTx, blockTxIndex
ctx.EventManager().EmitEvent(
sdk.NewEvent(
evmtypes.EventTypeEthereumTx,
sdk.NewAttribute(evmtypes.AttributeKeyEthereumTxHash, msg.Hash().String()),
sdk.NewAttribute(evmtypes.AttributeKeyEthereumTxHash, msg.AsTransaction().Hash().String()),
sdk.NewAttribute(evmtypes.AttributeKeyTxIndex, strconv.FormatUint(blockTxIndex, 10)), // #nosec G115
),
)
Expand Down
2 changes: 1 addition & 1 deletion ante/tx_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (d TxListenerDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate boo
if ctx.IsCheckTx() && !simulate && d.pendingTxListener != nil {
for _, msg := range tx.GetMsgs() {
if ethTx, ok := msg.(*evmtypes.MsgEthereumTx); ok {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we leaving some *evmtypes.MsgEthereumTx as pointers instead of the interface?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that newly execute tx, for example tx coming through ante handler or mempool, would always use the latest evmtypes.MsgEthereumTx

d.pendingTxListener(ethTx.Hash())
d.pendingTxListener(ethTx.AsTransaction().Hash())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion indexer/kv_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (kv *KVIndexer) IndexBlock(block *cmttypes.Block, txResults []*abci.ExecTxR
var cumulativeGasUsed uint64
for msgIndex, msg := range tx.GetMsgs() {
ethMsg := msg.(*evmtypes.MsgEthereumTx)
txHash := ethMsg.Hash()
txHash := ethMsg.AsTransaction().Hash()

txResult := servertypes.TxResult{
Height: height,
Expand Down
2 changes: 1 addition & 1 deletion mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func (m *Mempool) removeCosmosTx(tx sdk.Tx, reason sdkmempool.RemoveReason) erro
func (m *Mempool) removeEVMTx(tx sdk.Tx, msgEthereumTx *evmtypes.MsgEthereumTx, reason sdkmempool.RemoveReason) error {
m.logger.Debug("Removing EVM transaction")

hash := msgEthereumTx.Hash()
hash := msgEthereumTx.AsTransaction().Hash()
if reason.Caller == sdkmempool.CallerRunTxFinalize {
_ = m.txTracker.IncludedInBlock(hash)
m.recordNonceAdvances(tx)
Expand Down
2 changes: 1 addition & 1 deletion rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type EVMBackend interface {
CometBlockByHash(ctx context.Context, blockHash common.Hash) (*tmrpctypes.ResultBlock, error)
BlockNumberFromComet(ctx context.Context, blockNrOrHash types.BlockNumberOrHash) (types.BlockNumber, error)
BlockNumberFromCometByHash(ctx context.Context, blockHash common.Hash) (*big.Int, error)
EthMsgsFromCometBlock(ctx context.Context, block *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults) []*evmtypes.MsgEthereumTx
EthMsgsFromCometBlock(ctx context.Context, block *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults) []evmtypes.RPCMsgEthereumTxI
BlockBloomFromCometBlock(ctx context.Context, blockRes *tmrpctypes.ResultBlockResults) (ethtypes.Bloom, error)
HeaderByNumber(ctx context.Context, blockNum types.BlockNumber) (*ethtypes.Header, error)
HeaderByHash(ctx context.Context, blockHash common.Hash) (*ethtypes.Header, error)
Expand Down
27 changes: 14 additions & 13 deletions rpc/backend/comet_to_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ func (b *Backend) EthMsgsFromCometBlock(
ctx context.Context,
resBlock *cmtrpctypes.ResultBlock,
blockRes *cmtrpctypes.ResultBlockResults,
) []*evmtypes.MsgEthereumTx {
) []evmtypes.RPCMsgEthereumTxI {
_, span := tracer.Start(ctx, "EthMsgsFromCometBlock")
defer span.End()
var result []*evmtypes.MsgEthereumTx
var result []evmtypes.RPCMsgEthereumTxI
block := resBlock.Block

txResults := blockRes.TxsResults
Expand All @@ -130,7 +130,7 @@ func (b *Backend) EthMsgsFromCometBlock(
}

for _, msg := range tx.GetMsgs() {
ethMsg, ok := msg.(*evmtypes.MsgEthereumTx)
ethMsg, ok := msg.(evmtypes.RPCMsgEthereumTxI)
if !ok {
continue
}
Expand Down Expand Up @@ -254,7 +254,7 @@ func (b *Backend) ReceiptsFromCometBlock(
ctx context.Context,
resBlock *cmtrpctypes.ResultBlock,
blockRes *cmtrpctypes.ResultBlockResults,
msgs []*evmtypes.MsgEthereumTx,
msgs []evmtypes.RPCMsgEthereumTxI,
) (result []*ethtypes.Receipt, err error) {
ctx, span := tracer.Start(ctx, "ReceiptsFromCometBlock")
defer func() { evmtrace.EndSpanErr(span, err) }()
Expand All @@ -269,9 +269,10 @@ func (b *Backend) ReceiptsFromCometBlock(
receipts := make([]*ethtypes.Receipt, len(msgs))
cumulatedGasUsed := uint64(0)
for i, ethMsg := range msgs {
txResult, err := b.GetTxByEthHash(ctx, ethMsg.Hash())
tx := ethMsg.AsTransaction()
txResult, err := b.GetTxByEthHash(ctx, tx.Hash())
if err != nil {
return nil, fmt.Errorf("tx not found: hash=%s, error=%s", ethMsg.Hash(), err.Error())
return nil, fmt.Errorf("tx not found: hash=%s, error=%s", tx.Hash().Hex(), err.Error())
}

// Resolve -1 sentinel: indexer hasn't assigned EthTxIndex yet.
Expand All @@ -285,9 +286,9 @@ func (b *Backend) ReceiptsFromCometBlock(

var effectiveGasPrice *big.Int
if baseFee != nil {
effectiveGasPrice = rpctypes.EffectiveGasPrice(ethMsg.Raw.Transaction, baseFee)
effectiveGasPrice = rpctypes.EffectiveGasPrice(tx, baseFee)
} else {
effectiveGasPrice = ethMsg.Raw.GasFeeCap()
effectiveGasPrice = tx.GasFeeCap()
}

var status uint64
Expand All @@ -298,8 +299,8 @@ func (b *Backend) ReceiptsFromCometBlock(
}

contractAddress := common.Address{}
if ethMsg.Raw.To() == nil {
contractAddress = crypto.CreateAddress(ethMsg.GetSender(), ethMsg.Raw.Nonce())
if tx.To() == nil {
contractAddress = crypto.CreateAddress(common.BytesToAddress(ethMsg.GetFrom().Bytes()), tx.Nonce())
}

msgIndex := int(txResult.MsgIndex) // #nosec G115 -- checked for int overflow already
Expand All @@ -315,7 +316,7 @@ func (b *Backend) ReceiptsFromCometBlock(
if txResult.EthTxIndex == -1 {
var err error
// Fallback to find tx index by iterating all valid eth transactions
txResult.EthTxIndex, err = b.FindEthTxIndexByHash(ctx, ethMsg.Hash(), resBlock, blockRes)
txResult.EthTxIndex, err = b.FindEthTxIndexByHash(ctx, ethMsg.AsTransaction().Hash(), resBlock, blockRes)
if err != nil {
return nil, err
}
Expand All @@ -325,15 +326,15 @@ func (b *Backend) ReceiptsFromCometBlock(

receipt := &ethtypes.Receipt{
// Consensus fields: These fields are defined by the Yellow Paper
Type: ethMsg.Raw.Type(),
Type: tx.Type(),
PostState: nil,
Status: status, // convert to 1=success, 0=failure
CumulativeGasUsed: cumulatedGasUsed,
Bloom: bloom,
Logs: logs,

// Implementation fields: These fields are added by geth when processing a transaction.
TxHash: ethMsg.Hash(),
TxHash: tx.Hash(),
ContractAddress: contractAddress,
GasUsed: txResult.GasUsed,
EffectiveGasPrice: effectiveGasPrice,
Expand Down
12 changes: 6 additions & 6 deletions rpc/backend/tx_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (b *Backend) GetTransactionByHash(ctx context.Context, txHash common.Hash)
}

// the `res.MsgIndex` is inferred from tx index, should be within the bound.
msg, ok := tx.GetMsgs()[res.MsgIndex].(*evmtypes.MsgEthereumTx)
msg, ok := tx.GetMsgs()[res.MsgIndex].(evmtypes.RPCMsgEthereumTxI)
if !ok {
return nil, errors.New("invalid ethereum tx")
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func (b *Backend) GetTransactionByHashPending(ctx context.Context, txHash common
continue
}

if msg.Hash() == txHash {
if msg.AsTransaction().Hash() == txHash {
// use zero block values since it's not included in a block yet
return rpctypes.NewTransactionFromMsg(
msg,
Expand Down Expand Up @@ -194,8 +194,8 @@ func (b *Backend) GetTransactionReceipt(ctx context.Context, hash common.Hash) (
return nil, fmt.Errorf("block result not found at height %d: %w", res.Height, err)
}

ethMsg := tx.GetMsgs()[res.MsgIndex].(*evmtypes.MsgEthereumTx)
receipts, err := b.ReceiptsFromCometBlock(ctx, resBlock, blockRes, []*evmtypes.MsgEthereumTx{ethMsg})
ethMsg := tx.GetMsgs()[res.MsgIndex].(evmtypes.RPCMsgEthereumTxI)
receipts, err := b.ReceiptsFromCometBlock(ctx, resBlock, blockRes, []evmtypes.RPCMsgEthereumTxI{ethMsg})
if err != nil {
return nil, fmt.Errorf("failed to get receipts from comet block")
}
Expand Down Expand Up @@ -391,7 +391,7 @@ func (b *Backend) GetTransactionByBlockAndIndex(ctx context.Context, block *cmtr
return nil, nil
}

var msg *evmtypes.MsgEthereumTx
var msg evmtypes.RPCMsgEthereumTxI
// find in tx indexer
res, err := b.GetTxByTxIndex(ctx, block.Block.Height, uint(idx))
if err == nil {
Expand All @@ -403,7 +403,7 @@ func (b *Backend) GetTransactionByBlockAndIndex(ctx context.Context, block *cmtr

var ok bool
// msgIndex is inferred from tx events, should be within bound.
msg, ok = tx.GetMsgs()[res.MsgIndex].(*evmtypes.MsgEthereumTx)
msg, ok = tx.GetMsgs()[res.MsgIndex].(evmtypes.RPCMsgEthereumTxI)
if !ok {
b.Logger.Debug("invalid ethereum tx", "height", block.Block.Header, "index", idx)
return nil, nil
Expand Down
16 changes: 8 additions & 8 deletions rpc/backend/tx_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ func TestReceiptsFromCometBlock(t *testing.T) {
}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
msgs := []*evmtypes.MsgEthereumTx{
msgs := []evmtypes.RPCMsgEthereumTxI{
buildMsgEthereumTx(t),
}
expectedTxResult := &servertypes.TxResult{
Expand All @@ -509,7 +509,7 @@ func TestReceiptsFromCometBlock(t *testing.T) {
}
mockIndexer := &MockIndexer{
txResults: map[common.Hash]*servertypes.TxResult{
msgs[0].Hash(): expectedTxResult,
msgs[0].AsTransaction().Hash(): expectedTxResult,
},
}
backend.Indexer = mockIndexer
Expand All @@ -519,7 +519,7 @@ func TestReceiptsFromCometBlock(t *testing.T) {
require.NoError(t, err)
require.Len(t, receipts, 1)
require.Equal(t, tc.expectedTxIndex, receipts[0].TransactionIndex)
require.Equal(t, msgs[0].Hash(), receipts[0].TxHash)
require.Equal(t, msgs[0].AsTransaction().Hash(), receipts[0].TxHash)
require.Equal(t, big.NewInt(height), receipts[0].BlockNumber)
require.Equal(t, ethtypes.ReceiptStatusSuccessful, receipts[0].Status)
})
Expand Down Expand Up @@ -560,8 +560,8 @@ func TestReceiptsLogIndexBlockGlobal(t *testing.T) {
return data
}

tx0Data := encodeTxResult(makeTxResponse(msg0.Hash().Hex(), 0))
tx1Data := encodeTxResult(makeTxResponse(msg1.Hash().Hex(), 1))
tx0Data := encodeTxResult(makeTxResponse(msg0.AsTransaction().Hash().Hex(), 0))
tx1Data := encodeTxResult(makeTxResponse(msg1.AsTransaction().Hash().Hex(), 1))

resBlock := &tmrpctypes.ResultBlock{
Block: &tmtypes.Block{Header: tmtypes.Header{Height: height}},
Expand All @@ -580,16 +580,16 @@ func TestReceiptsLogIndexBlockGlobal(t *testing.T) {

mockIndexer := &MockIndexer{
txResults: map[common.Hash]*servertypes.TxResult{
msg0.Hash(): {Height: height, TxIndex: 0, EthTxIndex: 0, MsgIndex: 0},
msg1.Hash(): {Height: height, TxIndex: 1, EthTxIndex: 1, MsgIndex: 0},
msg0.AsTransaction().Hash(): {Height: height, TxIndex: 0, EthTxIndex: 0, MsgIndex: 0},
msg1.AsTransaction().Hash(): {Height: height, TxIndex: 1, EthTxIndex: 1, MsgIndex: 0},
},
}
backend.Indexer = mockIndexer

mockEVMQueryClient := backend.QueryClient.QueryClient.(*mocks.EVMQueryClient)
mockEVMQueryClient.On("BaseFee", mock.Anything, mock.Anything).Return(&evmtypes.QueryBaseFeeResponse{}, nil)

msgs := []*evmtypes.MsgEthereumTx{msg0, msg1}
msgs := []evmtypes.RPCMsgEthereumTxI{msg0, msg1}
receipts, err := backend.ReceiptsFromCometBlock(rpctypes.NewContextWithHeight(1), resBlock, blockRes, msgs)
require.NoError(t, err)
require.Len(t, receipts, 2)
Expand Down
6 changes: 3 additions & 3 deletions rpc/backend/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (b *Backend) getAccountNonce(ctx context.Context, accAddr common.Address, p
// only supports `MsgEthereumTx` style tx
for _, tx := range pendingTxs {
for _, msg := range (*tx).GetMsgs() {
ethMsg, ok := msg.(*evmtypes.MsgEthereumTx)
ethMsg, ok := msg.(evmtypes.RPCMsgEthereumTxI)
if !ok {
// not ethereum tx
break
Expand Down Expand Up @@ -255,7 +255,7 @@ func (b *Backend) ProcessBlock(
}
txGasUsed := uint64(cometTxResult.GasUsed) // #nosec G115
for _, msg := range tx.GetMsgs() {
ethMsg, ok := msg.(*evmtypes.MsgEthereumTx)
ethMsg, ok := msg.(evmtypes.RPCMsgEthereumTxI)
if !ok {
continue
}
Expand Down Expand Up @@ -362,7 +362,7 @@ func unwrapBlockNOrHash(blockNOrHash types.BlockNumberOrHash) string {
func (b *Backend) FindEthTxIndexByHash(ctx context.Context, txHash common.Hash, block *cmtrpctypes.ResultBlock, blockRes *cmtrpctypes.ResultBlockResults) (int32, error) {
msgs := b.EthMsgsFromCometBlock(ctx, block, blockRes)
for i := range msgs {
if msgs[i].Hash() == txHash {
if msgs[i].AsTransaction().Hash() == txHash {
if i > math.MaxInt32 {
return -1, fmt.Errorf("tx index overflow")
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func ParseTxResult(result *abci.ExecTxResult, tx sdk.Tx) (*ParsedTxs, error) {
p.Txs[i].Failed = true

// replace gasUsed with gasLimit because that's what's actually deducted.
gasLimit := tx.GetMsgs()[i].(*evmtypes.MsgEthereumTx).GetGas()
gasLimit := tx.GetMsgs()[i].(evmtypes.RPCMsgEthereumTxI).GetGas()
p.Txs[i].GasUsed = gasLimit
}
}
Expand Down
10 changes: 5 additions & 5 deletions rpc/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ import (
)

// RawTxToEthTx returns a evm MsgEthereum transaction from raw tx bytes.
func RawTxToEthTx(clientCtx client.Context, txBz cmttypes.Tx) ([]*evmtypes.MsgEthereumTx, error) {
func RawTxToEthTx(clientCtx client.Context, txBz cmttypes.Tx) ([]evmtypes.RPCMsgEthereumTxI, error) {
tx, err := clientCtx.TxConfig.TxDecoder()(txBz)
if err != nil {
return nil, errorsmod.Wrap(errortypes.ErrJSONUnmarshal, err.Error())
}

ethTxs := make([]*evmtypes.MsgEthereumTx, len(tx.GetMsgs()))
ethTxs := make([]evmtypes.RPCMsgEthereumTxI, len(tx.GetMsgs()))
for i, msg := range tx.GetMsgs() {
ethTx, ok := msg.(*evmtypes.MsgEthereumTx)
ethTx, ok := msg.(evmtypes.RPCMsgEthereumTxI)
if !ok {
return nil, fmt.Errorf("invalid message type %T, expected %T", msg, &evmtypes.MsgEthereumTx{})
}
Expand Down Expand Up @@ -152,7 +152,7 @@ func MakeHeader(
// NewTransactionFromMsg returns a transaction that will serialize to the RPC
// representation, with the given location metadata set (if available).
func NewTransactionFromMsg(
msg *evmtypes.MsgEthereumTx,
msg evmtypes.RPCMsgEthereumTxI,
blockHash common.Hash,
blockNumber, blockTime, index uint64,
baseFee *big.Int,
Expand Down Expand Up @@ -410,7 +410,7 @@ func RPCMarshalHeader(head *ethtypes.Header, blockHash []byte) map[string]interf
//
// This method refers to go-ethereum v1.16.3 internal package method - RPCMarshalBlock
// (https://github.com/ethereum/go-ethereum/blob/d818a9af7bd5919808df78f31580f59382c53150/internal/ethapi/api.go#L929-L962)
func RPCMarshalBlock(block *ethtypes.Block, cmtBlock *cmtrpccore.ResultBlock, msgs []*evmtypes.MsgEthereumTx, inclTx bool, fullTx bool, config *ethparams.ChainConfig) (map[string]interface{}, error) {
func RPCMarshalBlock(block *ethtypes.Block, cmtBlock *cmtrpccore.ResultBlock, msgs []evmtypes.RPCMsgEthereumTxI, inclTx bool, fullTx bool, config *ethparams.ChainConfig) (map[string]interface{}, error) {
blockHash := cmtBlock.BlockID.Hash.Bytes()
fields := RPCMarshalHeader(block.Header(), blockHash)
fields["size"] = hexutil.Uint64(block.Size())
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/rpc/backend/test_backend_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ func (s *TestSuite) buildFormattedBlock(
validator sdk.AccAddress,
baseFee *big.Int,
) map[string]interface{} {
var msgs []*evmtypes.MsgEthereumTx
var msgs []evmtypes.RPCMsgEthereumTxI
if tx != nil {
msgs = []*evmtypes.MsgEthereumTx{tx}
msgs = []evmtypes.RPCMsgEthereumTxI{tx}
}
ethBlock := s.buildEthBlock(blockRes, resBlock, msgs, validator, baseFee)
res, err := rpctypes.RPCMarshalBlock(ethBlock, resBlock, msgs, true, fullTx, s.backend.ChainConfig())
Expand All @@ -195,7 +195,7 @@ func (s *TestSuite) buildFormattedBlock(
func (s *TestSuite) buildEthBlock(
blockRes *cmtrpctypes.ResultBlockResults,
resBlock *cmtrpctypes.ResultBlock,
msgs []*evmtypes.MsgEthereumTx,
msgs []evmtypes.RPCMsgEthereumTxI,
validator sdk.AccAddress,
baseFee *big.Int,
) *ethtypes.Block {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/rpc/backend/test_call_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func (s *TestSuite) TestSendRawTransaction() {
bytes, _ := rlp.EncodeToBytes(ethTx.AsTransaction())
return bytes
},
expHash: ethTx.Hash(),
expHash: ethTx.AsTransaction().Hash(),
expError: "queue is full",
},
{
Expand All @@ -374,7 +374,7 @@ func (s *TestSuite) TestSendRawTransaction() {
RegisterMempoolInsert(s.T(), s.Mempool(), cosmosTx, nil)
},
rawTx: func() []byte { return rlpEncodedBz },
expHash: ethTx.Hash(),
expHash: ethTx.AsTransaction().Hash(),
expPass: true,
},
}
Expand Down
Loading