rpc: optimize tx index lookup (#810)

Closes: #760

Solution:
- emit tx index to cosmos events
- rpc side try to use the events, but fallback to heavier approach when fails.

Update rpc/ethereum/namespaces/eth/api.go

changelog

fix lint

fix TxIndexFromEvents

fix

Update rpc/ethereum/backend/backend.go

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
yihuang
2021-12-16 22:30:22 +00:00
committed by GitHub
co-authored by Federico Kunze Küllmer
parent e752d80e9f
commit 514785bd89
7 changed files with 182 additions and 79 deletions
+4
View File
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmtypes "github.com/tendermint/tendermint/types"
@@ -26,6 +27,7 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
sender := msg.From
tx := msg.AsTransaction()
txIndex := k.GetTxIndexTransient()
response, err := k.ApplyTransaction(tx)
if err != nil {
@@ -36,6 +38,8 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
sdk.NewAttribute(sdk.AttributeKeyAmount, tx.Value().String()),
// add event for ethereum transaction hash format
sdk.NewAttribute(types.AttributeKeyEthereumTxHash, response.Hash),
// add event for index of valid ethereum tx
sdk.NewAttribute(types.AttributeKeyTxIndex, strconv.FormatInt(int64(txIndex), 10)),
}
if len(ctx.TxBytes()) > 0 {
+1
View File
@@ -15,6 +15,7 @@ The `x/evm` module emits the Cosmos SDK events after a state execution. The EVM
| ethereum_tx | `"contract"` | `{hex_address}` |
| ethereum_tx | `"txHash"` | `{tendermint_hex_hash}` |
| ethereum_tx | `"ethereumTxHash"` | `{hex_hash}` |
| ethereum_tx | `"txIndex"` | `{tx_index}` |
| tx_log | `"txLog"` | `{tx_log}` |
| message | `"sender"` | `{eth_address}` |
| message | `"action"` | `"ethereum"` |
+1
View File
@@ -10,6 +10,7 @@ const (
AttributeKeyRecipient = "recipient"
AttributeKeyTxHash = "txHash"
AttributeKeyEthereumTxHash = "ethereumTxHash"
AttributeKeyTxIndex = "txIndex"
AttributeKeyTxType = "txType"
AttributeKeyTxLog = "txLog"
// tx failed in eth vm execution