Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: customer tx indexer feature is not enabled #549

Merged
merged 4 commits into from
Aug 16, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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="
Expand Down
25 changes: 25 additions & 0 deletions integration_tests/configs/enable-indexer.jsonnet
Original file line number Diff line number Diff line change
@@ -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',
},
},
},
},
},
}
18 changes: 13 additions & 5 deletions integration_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions scripts/devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions third_party/proto/ethermint/types/v1/indexer.proto
Original file line number Diff line number Diff line change
@@ -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;
}
30 changes: 11 additions & 19 deletions x/cronos/rpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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())
}
Expand Down