diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c1048822c..2d14a9e9ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - [cronos#489](https://github.com/crypto-org-chain/cronos/pull/489) Enable jemalloc memory allocator, and update rocksdb src to `v6.29.5`. - [cronos#511](https://github.com/crypto-org-chain/cronos/pull/511) Replace ibc-hook with ibc middleware, use ibc-go upstream version. - [cronos#550](https://github.com/crypto-org-chain/cronos/pull/550) Support basic json-rpc apis on pruned nodes. +- [cronos#549](https://github.com/crypto-org-chain/cronos/pull/549) Use custom tx indexer feature of ethermint. *May 3, 2022* diff --git a/README.md b/README.md index 0485eeb99d..efe61e5f73 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ pystarport supervisorctl stop all - [Technical Documentation](http://cronos.org/docs) - Community chatrooms (non-technical): [Discord](https://discord.gg/nsp9JTC) [Telegram](https://t.me/CryptoComOfficial) - Developer community channel (technical): [![Support Server](https://img.shields.io/discord/783264383978569728.svg?color=7289da&label=Cronos&logo=discord&style=flat-square)](https://discord.gg/pahqHz26q4) -- [Ethermint](https://github.com/tharsis/ethermint) by Tharsis +- [Ethermint](https://github.com/evmos/ethermint) by Tharsis - [Cosmos SDK documentation](https://docs.cosmos.network) - [Cosmos Discord](https://discord.gg/W8trcGV) - [Pystarport](https://github.com/crypto-com/pystarport/blob/main/README.md) diff --git a/app/app.go b/app/app.go index bc72a8e322..bf75165530 100644 --- a/app/app.go +++ b/app/app.go @@ -644,7 +644,10 @@ func New( minttypes.ModuleName, crisistypes.ModuleName, ibchost.ModuleName, + // evm module denomination is used by the feemarket module, in AnteHandle evmtypes.ModuleName, + // NOTE: feemarket need to be initialized before genutil module: + // gentx transactions use MinGasPriceDecorator.AnteHandle feemarkettypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, diff --git a/go.mod b/go.mod index 0ddce1a674..245d5b4c97 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/cosmos/cosmos-sdk v0.46.0 github.com/cosmos/ibc-go/v5 v5.0.0-beta1 github.com/ethereum/go-ethereum v1.10.19 - github.com/evmos/ethermint v0.6.1-0.20220810223338-b1cd16e5bfb1 + github.com/evmos/ethermint v0.6.1-0.20220814092117-f11bc3559467 github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.5.2 github.com/gorilla/mux v1.8.0 diff --git a/go.sum b/go.sum index 49b5c44442..95fdd0d319 100644 --- a/go.sum +++ b/go.sum @@ -426,8 +426,8 @@ github.com/esimonov/ifshort v1.0.4/go.mod h1:Pe8zjlRrJ80+q2CxHLfEOfTwxCZ4O+MuhcH github.com/ethereum/go-ethereum v1.10.19 h1:EOR5JbL4MD5yeOqv8W2iC1s4NximrTjqFccUz8lyBRA= github.com/ethereum/go-ethereum v1.10.19/go.mod h1:IJBNMtzKcNHPtllYihy6BL2IgK1u+32JriaTbdt4v+w= github.com/ettle/strcase v0.1.1/go.mod h1:hzDLsPC7/lwKyBOywSHEP89nt2pDgdy+No1NBA9o9VY= -github.com/evmos/ethermint v0.6.1-0.20220810223338-b1cd16e5bfb1 h1:lIWSElIU+zcLzEGXsQU7pDEzHlh3mu12BZTToXuBdwA= -github.com/evmos/ethermint v0.6.1-0.20220810223338-b1cd16e5bfb1/go.mod h1:3UVQJyCBB9tW3zvtmqGtVTfSRgNBFP29izugIxyizQE= +github.com/evmos/ethermint v0.6.1-0.20220814092117-f11bc3559467 h1:5MJ8N97jA/zXmEdkhxPV+Ccv5/jroGp9Iq26DC9c95s= +github.com/evmos/ethermint v0.6.1-0.20220814092117-f11bc3559467/go.mod h1:3UVQJyCBB9tW3zvtmqGtVTfSRgNBFP29izugIxyizQE= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= diff --git a/gomod2nix.toml b/gomod2nix.toml index 600086a73b..48e0ce7500 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -158,8 +158,8 @@ schema = 3 version = "v1.10.19" hash = "sha256-7FPnTGcCb8Xd1QVR+6PmGTaHdTY1mm/8osFTW1JLuG8=" [mod."github.com/evmos/ethermint"] - version = "v0.6.1-0.20220810223338-b1cd16e5bfb1" - hash = "sha256-gwr9r+HTR5MRj8MEDWv3VTcwLCyzdfkHS+z/CkJfglQ=" + version = "v0.6.1-0.20220814092117-f11bc3559467" + hash = "sha256-gpnOKw6jq8BVbUKdq5MhFwmXESI+tAGbETvh4fjQsvs=" [mod."github.com/felixge/httpsnoop"] version = "v1.0.1" hash = "sha256-TNXnnC/ZGNY9lInAcES1cBGqIdEljKuh5LH/khVFjVk=" diff --git a/integration_tests/configs/enable-indexer.jsonnet b/integration_tests/configs/enable-indexer.jsonnet new file mode 100644 index 0000000000..3b42c70b88 --- /dev/null +++ b/integration_tests/configs/enable-indexer.jsonnet @@ -0,0 +1,25 @@ +local config = import 'default.jsonnet'; + +config { + 'cronos_777-1'+: { + config+: { + tx_index+: { + indexer: 'null', + }, + }, + 'app-config'+: { + 'json-rpc'+: { + 'enable-indexer': true, + }, + }, + genesis+: { + app_state+: { + feemarket+: { + params+: { + min_gas_multiplier: '0', + }, + }, + }, + }, + }, +} diff --git a/integration_tests/conftest.py b/integration_tests/conftest.py index 4bb6b27e24..980d4a9627 100644 --- a/integration_tests/conftest.py +++ b/integration_tests/conftest.py @@ -1,9 +1,10 @@ import os import sys +from pathlib import Path import pytest -from .network import setup_cronos, setup_geth +from .network import setup_cronos, setup_custom_cronos, setup_geth dir = os.path.dirname(os.path.realpath(__file__)) sys.path.append(dir + "/protobuf") @@ -41,10 +42,17 @@ def __exit__(self, _1, _2, _3): yield SuspendGuard() -@pytest.fixture(scope="session") -def cronos(tmp_path_factory): - path = tmp_path_factory.mktemp("cronos") - yield from setup_cronos(path, 26650) +@pytest.fixture(scope="session", params=[True]) +def cronos(request, tmp_path_factory): + enable_indexer = request.param + if enable_indexer: + path = tmp_path_factory.mktemp("indexer") + yield from setup_custom_cronos( + path, 27000, Path(__file__).parent / "configs/enable-indexer.jsonnet" + ) + else: + path = tmp_path_factory.mktemp("cronos") + yield from setup_cronos(path, 26650) @pytest.fixture(scope="session") diff --git a/scripts/devnet.yaml b/scripts/devnet.yaml index a1aee17ae8..b3db7c6a64 100644 --- a/scripts/devnet.yaml +++ b/scripts/devnet.yaml @@ -2,11 +2,15 @@ dotenv: .env cronos_777-1: cmd: ./build/cronosd start-flags: "--trace --unsafe-experimental" + config: + tx_index: + indexer: "null" app-config: json-rpc: address: "0.0.0.0:{EVMRPC_PORT}" ws-address: "0.0.0.0:{EVMRPC_PORT_WS}" api: "eth,net,web3,debug,cronos" + enable-indexer: true validators: - coins: 1000000000000000000stake,1000000000000000000basetcro staked: 1000000000000000000stake diff --git a/third_party/proto/ethermint/types/v1/indexer.proto b/third_party/proto/ethermint/types/v1/indexer.proto new file mode 100644 index 0000000000..9b77d6888a --- /dev/null +++ b/third_party/proto/ethermint/types/v1/indexer.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; +package ethermint.types.v1; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/evmos/ethermint/types"; + +message TxResult { + option (gogoproto.goproto_getters) = false; + + int64 height = 1; + uint32 tx_index = 2; + uint32 msg_index = 3; + + // eth tx index, -1 if not found + int32 eth_tx_index = 4; + bool failed = 5; + uint64 gas_used = 6; + // the cumulative gas used within current batch tx + uint64 cumulative_gas_used = 7; +} diff --git a/x/cronos/rpc/api.go b/x/cronos/rpc/api.go index ea1281f06c..7437492945 100644 --- a/x/cronos/rpc/api.go +++ b/x/cronos/rpc/api.go @@ -40,8 +40,8 @@ func init() { } // CreateCronosRPCAPIs creates extension json-rpc apis -func CreateCronosRPCAPIs(ctx *server.Context, clientCtx client.Context, tmWSClient *rpcclient.WSClient, allowUnprotectedTxs bool) []rpc.API { - evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, allowUnprotectedTxs) +func CreateCronosRPCAPIs(ctx *server.Context, clientCtx client.Context, tmWSClient *rpcclient.WSClient, allowUnprotectedTxs bool, indexer ethermint.EVMTxIndexer) []rpc.API { + evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, allowUnprotectedTxs, indexer) return []rpc.API{ { Namespace: CronosNamespace, @@ -126,11 +126,17 @@ func (api *CronosAPI) GetTransactionReceiptsByBlock(blockNrOrHash rpctypes.Block txResult := blockRes.TxsResults[i] // don't ignore the txs which exceed block gas limit. - if !backend.TxSuccessOrExceedsBlockGasLimit(txResult) { + if !rpctypes.TxSuccessOrExceedsBlockGasLimit(txResult) { continue } - parsedTxs, err := rpctypes.ParseTxResult(txResult) + tx, err := api.clientCtx.TxConfig.TxDecoder()(tx) + if err != nil { + api.logger.Debug("decoding failed", "error", err.Error()) + return nil, fmt.Errorf("failed to decode tx: %w", err) + } + + parsedTxs, err := rpctypes.ParseTxResult(txResult, tx) if err != nil { return nil, fmt.Errorf("failed to parse tx events: %d:%d, %v", resBlock.Block.Height, i, err) } @@ -141,24 +147,10 @@ func (api *CronosAPI) GetTransactionReceiptsByBlock(blockNrOrHash rpctypes.Block continue } - tx, err := api.clientCtx.TxConfig.TxDecoder()(tx) - if err != nil { - api.logger.Debug("decoding failed", "error", err.Error()) - return nil, fmt.Errorf("failed to decode tx: %w", err) - } - if len(parsedTxs.Txs) != len(tx.GetMsgs()) { return nil, fmt.Errorf("wrong number of tx events: %d", txIndex) } - if txResult.Code != 0 { - // tx failed, we should return gas limit as gas used, because that's how the fee get deducted. - for j := 0; j < len(parsedTxs.Txs); j++ { - gasLimit := tx.GetMsgs()[j].(*evmtypes.MsgEthereumTx).GetGas() - parsedTxs.Txs[j].GasUsed = gasLimit - } - } - msgCumulativeGasUsed := uint64(0) for msgIndex, msg := range tx.GetMsgs() { ethMsg, ok := msg.(*evmtypes.MsgEthereumTx) @@ -188,7 +180,7 @@ func (api *CronosAPI) GetTransactionReceiptsByBlock(blockNrOrHash rpctypes.Block return nil, err } - logs, err := parsedTx.ParseTxLogs() + logs, err := backend.TxLogsFromEvents(txResult.Events, parsedTx.MsgIndex) if err != nil { api.logger.Debug("failed to parse logs", "block", resBlock.Block.Height, "txIndex", txIndex, "msgIndex", msgIndex, "error", err.Error()) }