Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

fix: align filter rule for debug trace block #1688

Merged
merged 11 commits into from
Mar 23, 2023
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (deps) [#1168](https://github.com/evmos/ethermint/pull/1168) Upgrade Cosmos SDK to [`v0.46.6`]

### Bug Fixes

* (rpc) [#1688](https://github.com/evmos/ethermint/pull/1688) Align filter rule for `debug_traceBlockByNumber`

## [v0.21.0] - 2023-01-26

### State Machine Breaking
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ schema = 3
version = "v2.0.3"
hash = "sha256-5VsJMQzJSNd4F7yAl3iF/q6JodWOlE4dUvTQ0UGPe+k="
[mod."github.com/holiman/uint256"]
version = "v1.2.1"
hash = "sha256-1N+MvvzTIegV1UPEGUVyxBZaxczId/Z/BUVcnx7ckHE="
version = "v1.2.2"
hash = "sha256-mM0aeaqIwaNG7X3THx0HOCMPLKYK1DIvvuMLXClPAZg="
[mod."github.com/huin/goupnp"]
version = "v1.0.3"
hash = "sha256-EMGmTdoQhP2bVbCPX37hes5krqXn6NFexfnKr9E5u8I="
Expand Down
11 changes: 10 additions & 1 deletion rpc/backend/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
rpctypes "github.com/evmos/ethermint/rpc/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/pkg/errors"
Expand Down Expand Up @@ -142,11 +143,19 @@ func (b *Backend) TraceBlock(height rpctypes.BlockNumber,
// If there are no transactions return empty array
return []*evmtypes.TxTraceResult{}, nil
}

blockRes, err := b.TendermintBlockResultByNumber(&block.Block.Height)
if err != nil {
b.logger.Debug("block result not found", "height", block.Block.Height, "error", err.Error())
return nil, nil
}
txDecoder := b.clientCtx.TxConfig.TxDecoder()

var txsMessages []*evmtypes.MsgEthereumTx
for i, tx := range txs {
if !rpctypes.TxSuccessOrExceedsBlockGasLimit(blockRes.TxsResults[i]) {
b.logger.Debug("invalid tx result code", "cosmos-hash", hexutil.Encode(tx.Hash()))
continue
}
decodedTx, err := txDecoder(tx)
if err != nil {
b.logger.Error("failed to decode transaction", "hash", txs[i].Hash(), "error", err.Error())
Expand Down
2 changes: 2 additions & 0 deletions rpc/backend/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ func (suite *BackendTestSuite) TestTraceBlock() {
func() {
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterTraceBlock(queryClient, []*evmtypes.MsgEthereumTx{msgEthTx})
client := suite.backend.clientCtx.Client.(*mocks.Client)
RegisterBlockResults(client, 1)
},
[]*evmtypes.TxTraceResult{},
&resBlockFilled,
Expand Down
2 changes: 1 addition & 1 deletion rpc/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func TxExceedBlockGasLimit(res *abci.ResponseDeliverTx) bool {
return strings.Contains(res.Log, ExceedBlockGasLimitError)
}

// TxSuccessOrExceedsBlockGasLimit returnsrue if the transaction was successful
// TxSuccessOrExceedsBlockGasLimit returns true if the transaction was successful
// or if it failed with an ExceedBlockGasLimit error
func TxSuccessOrExceedsBlockGasLimit(res *abci.ResponseDeliverTx) bool {
return res.Code == 0 || TxExceedBlockGasLimit(res)
Expand Down
16 changes: 3 additions & 13 deletions tests/integration_tests/test_account.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import os

import pytest
from eth_account import Account
from web3 import Web3

from .network import setup_ethermint
from .utils import ADDRS, w3_wait_for_new_blocks
from .utils import ADDRS, derive_new_account, w3_wait_for_new_blocks


@pytest.fixture(scope="module")
Expand All @@ -32,19 +29,12 @@ def cluster(request, custom_ethermint, geth):
raise NotImplementedError


def derive_new_address(n=1):
# derive a new address
account_path = f"m/44'/60'/0'/0/{n}"
mnemonic = os.getenv("COMMUNITY_MNEMONIC")
return (Account.from_mnemonic(mnemonic, account_path=account_path)).address


def test_get_transaction_count(cluster):
w3: Web3 = cluster.w3
blk = hex(w3.eth.block_number)
sender = ADDRS["validator"]

receiver = derive_new_address()
receiver = derive_new_account().address
n0 = w3.eth.get_transaction_count(receiver, blk)
# ensure transaction send in new block
w3_wait_for_new_blocks(w3, 1, sleep=0.1)
Expand All @@ -64,7 +54,7 @@ def test_get_transaction_count(cluster):

def test_query_future_blk(cluster):
w3: Web3 = cluster.w3
acc = derive_new_address(2)
acc = derive_new_account(2).address
current = w3.eth.block_number
future = current + 1000
with pytest.raises(ValueError) as exc:
Expand Down
51 changes: 51 additions & 0 deletions tests/integration_tests/test_debug_trace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import requests
from pystarport import ports

from .utils import (
derive_new_account,
send_transaction,
sign_transaction,
wait_for_new_blocks,
)


def test_trace_blk(ethermint):
w3 = ethermint.w3
cli = ethermint.cosmos_cli()
acc = derive_new_account(3)
sender = acc.address
# fund new sender
fund = 3000000000000000000
tx = {"to": sender, "value": fund, "gasPrice": w3.eth.gas_price}
send_transaction(w3, tx)
assert w3.eth.get_balance(sender, "latest") == fund
nonce = w3.eth.get_transaction_count(sender)
blk = wait_for_new_blocks(cli, 1, sleep=0.1)
txhashes = []
total = 3
for n in range(total):
tx = {
"to": "0x2956c404227Cc544Ea6c3f4a36702D0FD73d20A2",
"value": fund // total,
"gas": 21000,
"maxFeePerGas": 6556868066901,
"maxPriorityFeePerGas": 1500000000,
"nonce": nonce + n,
}
signed = sign_transaction(w3, tx, acc.key)
txhash = w3.eth.send_raw_transaction(signed.rawTransaction)
txhashes.append(txhash)
for txhash in txhashes[0 : total - 1]:
res = w3.eth.wait_for_transaction_receipt(txhash)
assert res.status == 1

url = f"http://127.0.0.1:{ports.evmrpc_port(ethermint.base_port(0))}"
params = {
"method": "debug_traceBlockByNumber",
"params": [hex(blk + 1)],
"id": 1,
"jsonrpc": "2.0",
}
rsp = requests.post(url, json=params)
assert rsp.status_code == 200
assert len(rsp.json()["result"]) == 2
7 changes: 7 additions & 0 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,10 @@ def parse_events(logs):
ev["type"]: {attr["key"]: attr["value"] for attr in ev["attributes"]}
for ev in logs[0]["events"]
}


def derive_new_account(n=1):
# derive a new address
account_path = f"m/44'/60'/0'/0/{n}"
mnemonic = os.getenv("COMMUNITY_MNEMONIC")
return Account.from_mnemonic(mnemonic, account_path=account_path)