From 6ac74f8f709c141fa59f66c3abc46855322a5b11 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 28 Feb 2023 10:48:50 +0800 Subject: [PATCH 1/4] align filter rule for debug_traceBlockByNumber --- rpc/backend/tracing.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rpc/backend/tracing.go b/rpc/backend/tracing.go index e616c6f092..60998d517c 100644 --- a/rpc/backend/tracing.go +++ b/rpc/backend/tracing.go @@ -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" @@ -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()) From 9b2d9b9301d4567c638cea5b8735fd336c492947 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 28 Feb 2023 11:07:28 +0800 Subject: [PATCH 2/4] test debug_traceBlockByNumber --- tests/integration_tests/test_debug_trace.py | 53 +++++++++++++++++++++ tests/integration_tests/utils.py | 7 +++ 2 files changed, 60 insertions(+) create mode 100644 tests/integration_tests/test_debug_trace.py diff --git a/tests/integration_tests/test_debug_trace.py b/tests/integration_tests/test_debug_trace.py new file mode 100644 index 0000000000..89cd278a23 --- /dev/null +++ b/tests/integration_tests/test_debug_trace.py @@ -0,0 +1,53 @@ +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) + print(f"block number start: {blk}") + 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) + print("txhash", txhash.hex()) + 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 diff --git a/tests/integration_tests/utils.py b/tests/integration_tests/utils.py index eda82706e4..6fcaf16cf8 100644 --- a/tests/integration_tests/utils.py +++ b/tests/integration_tests/utils.py @@ -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) From f20eb7089cf4a89b4012b90ba4358bb6512aecc2 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 28 Feb 2023 13:11:24 +0800 Subject: [PATCH 3/4] fix lint --- tests/integration_tests/test_debug_trace.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/integration_tests/test_debug_trace.py b/tests/integration_tests/test_debug_trace.py index 89cd278a23..d96b055510 100644 --- a/tests/integration_tests/test_debug_trace.py +++ b/tests/integration_tests/test_debug_trace.py @@ -21,7 +21,6 @@ def test_trace_blk(ethermint): 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) - print(f"block number start: {blk}") txhashes = [] total = 3 for n in range(total): @@ -35,9 +34,8 @@ def test_trace_blk(ethermint): } signed = sign_transaction(w3, tx, acc.key) txhash = w3.eth.send_raw_transaction(signed.rawTransaction) - print("txhash", txhash.hex()) txhashes.append(txhash) - for txhash in txhashes[0:total - 1]: + for txhash in txhashes[0 : total - 1]: res = w3.eth.wait_for_transaction_receipt(txhash) assert res.status == 1 From ed815357a27f9ae5e62c810513c11164d7031903 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 28 Feb 2023 12:33:47 +0800 Subject: [PATCH 4/4] update doc --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ae0045552..900e1e632c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`.