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

fix: align filter rule for debug trace block #220

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/

* (rpc) [#1682](https://github.com/evmos/ethermint/pull/1682) Add config for maximum number of bytes returned from eth_call.

### Bug Fixes

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

### Improvements

* (cli) [#1615](https://github.com/evmos/ethermint/pull/1615) Support customize db opener in `StartCmd`.
Expand Down
11 changes: 10 additions & 1 deletion rpc/backend/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
rpctypes "github.com/evmos/ethermint/rpc/types"
ethermint "github.com/evmos/ethermint/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
Expand Down Expand Up @@ -137,11 +138,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
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 @@ -190,3 +190,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)