From 036c598424751e3bf305a0b1267696cf6f240ae9 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Tue, 14 Jun 2022 17:43:08 +0800 Subject: [PATCH] Problem: json-rpc failed on pruned nodes (backport #550) Solution: - Make basic json-rpc apis works on pruned nodes - Test with integration tests --- go.mod | 2 +- go.sum | 4 +- gomod2nix.toml | 6 +- integration_tests/configs/pruned-node.yaml | 65 +++++++++++++ integration_tests/test_pruned_node.py | 108 +++++++++++++++++++++ 5 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 integration_tests/configs/pruned-node.yaml create mode 100644 integration_tests/test_pruned_node.py diff --git a/go.mod b/go.mod index 4bc21f6b6e..f1520e5b55 100644 --- a/go.mod +++ b/go.mod @@ -160,7 +160,7 @@ replace ( github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/tharsis/ethermint => github.com/crypto-org-chain/ethermint v0.10.0-alpha1-cronos-10 + github.com/tharsis/ethermint => github.com/yihuang/ethermint v0.10.0-cronos.0.20220630073727-4a4fd6003e12 google.golang.org/grpc => google.golang.org/grpc v1.33.2 ) diff --git a/go.sum b/go.sum index 88a7c1539f..de9adfd5e2 100644 --- a/go.sum +++ b/go.sum @@ -271,8 +271,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/crypto-org-chain/ethermint v0.10.0-alpha1-cronos-10 h1:QLICrljqG8eJ4X+JCqvWf1Lbg/TXS+lxoFbcezBpyjc= -github.com/crypto-org-chain/ethermint v0.10.0-alpha1-cronos-10/go.mod h1:T4f1p3L5kccbjBZMtJLKfOLiUXTO1OuS1I7FzQuJD+w= github.com/crypto-org-chain/ibc-go/v2 v2.2.0-hooks2 h1:elj+Tb/3O9GA3pv62zkc1B0P8hl1WHmF6vF8PInEJm4= github.com/crypto-org-chain/ibc-go/v2 v2.2.0-hooks2/go.mod h1:rAHRlBcRiHPP/JszN+08SJx3pegww9bcVncIb9QLx7I= github.com/crypto-org-chain/keyring v1.1.6-fixes h1:AUFSu56NY6XobY6XfRoDx6v3loiOrHK5MNUm32GEjwA= @@ -1166,6 +1164,8 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/ybbus/jsonrpc v2.1.2+incompatible/go.mod h1:XJrh1eMSzdIYFbM08flv0wp5G35eRniyeGut1z+LSiE= +github.com/yihuang/ethermint v0.10.0-cronos.0.20220630073727-4a4fd6003e12 h1:3FFxlzlEuOkyDMDFst8rBZOVgxpaqblnWuY9NG+nIT8= +github.com/yihuang/ethermint v0.10.0-cronos.0.20220630073727-4a4fd6003e12/go.mod h1:T4f1p3L5kccbjBZMtJLKfOLiUXTO1OuS1I7FzQuJD+w= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/gomod2nix.toml b/gomod2nix.toml index c4a455559a..1a9199295e 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -1434,9 +1434,9 @@ schema = 1 version = "v0.6.7" hash = "sha256-hl/3RrBrpkk2zA6dmrNlIYKs1/GfqegSscDSkA5Pjlo=" [mod."github.com/tharsis/ethermint"] - version = "v0.10.0-alpha1-cronos-10" - hash = "sha256-EfYOvGreGToosDcqg1MBCHwSRSFdBIVvMlXIlYFFH0A=" - replaced = "github.com/crypto-org-chain/ethermint" + version = "v0.10.0-cronos.0.20220630073727-4a4fd6003e12" + hash = "sha256-23OXZLkqPiwgpa3BcRan/MC7I6hsVm91VWuawOynpu0=" + replaced = "github.com/yihuang/ethermint" [mod."github.com/tidwall/gjson"] version = "v1.6.7" hash = "sha256-GL6MI9oNq+Pjxai9RtDPBeSpIuMTPQZPsB2vcntCBr8=" diff --git a/integration_tests/configs/pruned-node.yaml b/integration_tests/configs/pruned-node.yaml new file mode 100644 index 0000000000..d0ce85d1b5 --- /dev/null +++ b/integration_tests/configs/pruned-node.yaml @@ -0,0 +1,65 @@ +dotenv: ../../scripts/.env +cronos_777-1: + cmd: cronosd + start-flags: "--trace" + app-config: + minimum-gas-prices: 0basetcro + index-events: + - ethereum_tx.ethereumTxHash + pruning: "everything" + state-sync: + snapshot-interval: 0 + json-rpc: + address: "0.0.0.0:{EVMRPC_PORT}" + ws-address: "0.0.0.0:{EVMRPC_PORT_WS}" + api: "eth,net,web3,debug,cronos" + validators: + - coins: 1000000000000000000stake,10000000000000000000000basetcro + staked: 1000000000000000000stake + mnemonic: ${VALIDATOR1_MNEMONIC} + - coins: 1000000000000000000stake,10000000000000000000000basetcro + staked: 1000000000000000000stake + mnemonic: ${VALIDATOR2_MNEMONIC} + accounts: + - name: community + coins: 10000000000000000000000basetcro + mnemonic: ${COMMUNITY_MNEMONIC} + - name: signer1 + coins: 20000000000000000000000basetcro + mnemonic: ${SIGNER1_MNEMONIC} + - name: signer2 + coins: 30000000000000000000000basetcro + mnemonic: ${SIGNER2_MNEMONIC} + + + genesis: + consensus_params: + block: + max_bytes: "1048576" + max_gas: "81500000" + app_state: + evm: + params: + evm_denom: basetcro + cronos: + params: + cronos_admin: ${CRONOS_ADMIN} + enable_auto_deployment: true + ibc_cro_denom: ${IBC_CRO_DENOM} + gov: + voting_params: + voting_period: "10s" + deposit_params: + max_deposit_period: "10s" + min_deposit: + - denom: "basetcro" + amount: "1" + transfer: + params: + receive_enabled: true + send_enabled: true + feemarket: + params: + no_base_fee: false + base_fee: "100000000000" + min_gas_multiplier: "0" diff --git a/integration_tests/test_pruned_node.py b/integration_tests/test_pruned_node.py new file mode 100644 index 0000000000..b488cbba7a --- /dev/null +++ b/integration_tests/test_pruned_node.py @@ -0,0 +1,108 @@ +from pathlib import Path + +import pytest +from eth_bloom import BloomFilter +from eth_utils import abi, big_endian_to_int +from hexbytes import HexBytes +from web3.datastructures import AttributeDict + +from .network import setup_custom_cronos +from .utils import ( + ADDRS, + CONTRACTS, + KEYS, + deploy_contract, + sign_transaction, + wait_for_new_blocks, +) + + +@pytest.fixture(scope="module") +def cronos(request, tmp_path_factory): + """start-cronos + params: enable_auto_deployment + """ + yield from setup_custom_cronos( + tmp_path_factory.mktemp("pruned"), + 26900, + Path(__file__).parent / "configs/pruned-node.yaml", + ) + + +def test_pruned_node(cronos): + """ + test basic json-rpc apis works in pruned node + """ + w3 = cronos.w3 + erc20 = deploy_contract( + w3, + CONTRACTS["TestERC20A"], + key=KEYS["validator"], + ) + tx = erc20.functions.transfer(ADDRS["community"], 10).buildTransaction( + {"from": ADDRS["validator"]} + ) + signed = sign_transaction(w3, tx, KEYS["validator"]) + txhash = w3.eth.send_raw_transaction(signed.rawTransaction) + + print("wait for prunning happens") + wait_for_new_blocks(cronos.cosmos_cli(0), 10) + + txreceipt = w3.eth.wait_for_transaction_receipt(txhash) + assert len(txreceipt.logs) == 1 + expect_log = { + "address": erc20.address, + "topics": [ + HexBytes( + abi.event_signature_to_log_topic("Transfer(address,address,uint256)") + ), + HexBytes(b"\x00" * 12 + HexBytes(ADDRS["validator"])), + HexBytes(b"\x00" * 12 + HexBytes(ADDRS["community"])), + ], + "data": "0x000000000000000000000000000000000000000000000000000000000000000a", + "transactionIndex": 0, + "logIndex": 0, + "removed": False, + } + assert expect_log.items() <= txreceipt.logs[0].items() + + # check block bloom + block = w3.eth.get_block(txreceipt.blockNumber) + assert "baseFeePerGas" in block + assert block.miner == "0x0000000000000000000000000000000000000000" + bloom = BloomFilter(big_endian_to_int(block.logsBloom)) + assert HexBytes(erc20.address) in bloom + for topic in expect_log["topics"]: + assert topic in bloom + + tx1 = w3.eth.get_transaction(txhash) + tx2 = w3.eth.get_transaction_by_block( + txreceipt.blockNumber, txreceipt.transactionIndex + ) + exp_tx = AttributeDict( + { + "from": "0x57f96e6B86CdeFdB3d412547816a82E3E0EbF9D2", + "gas": 51503, + "input": ( + "0xa9059cbb000000000000000000000000378c50d9264c63f3f92b806d4ee56e" + "9d86ffb3ec000000000000000000000000000000000000000000000000000000" + "000000000a" + ), + "nonce": 2, + "to": erc20.address, + "transactionIndex": 0, + "value": 0, + "type": "0x2", + "accessList": [], + "chainId": "0x309", + } + ) + assert tx1 == tx2 + for name in exp_tx.keys(): + assert tx1[name] == tx2[name] == exp_tx[name] + + print( + w3.eth.get_logs( + {"fromBlock": txreceipt.blockNumber, "toBlock": txreceipt.blockNumber} + ) + )