From a7934b33841ab125f395a517c00ee6b6feab9b1b Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 15 Aug 2023 17:01:09 +0800 Subject: [PATCH 1/5] local --- docs/api/json-rpc/events.md | 4 ++-- integration_tests/configs/cronos-experimental-devnet.jsonnet | 4 ++-- integration_tests/configs/default.jsonnet | 4 ++-- integration_tests/test_basic.py | 4 ++-- scripts/cronos-devnet.yaml | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/api/json-rpc/events.md b/docs/api/json-rpc/events.md index 9a92e8ba7a..0e7c3a1435 100644 --- a/docs/api/json-rpc/events.md +++ b/docs/api/json-rpc/events.md @@ -112,10 +112,10 @@ PubSubAPI](https://geth.ethereum.org/docs/rpc/pubsub), Cronos needs to cast the responses retrieved into the Ethereum types. You can start a connection with the Ethereum websocket using the `--json-rpc.ws-address` flag when starting -the node (default `"0.0.0.0:8546"`): +the node (default `"127.0.0.1:8546"`): ```bash -cronosd start --json-rpc.address"0.0.0.0:8545" --json-rpc.ws-address="0.0.0.0:8546" --evm.rpc.api="eth,web3,net,txpool,debug" --json-rpc.enable +cronosd start --json-rpc.address"127.0.0.1:8545" --json-rpc.ws-address="127.0.0.1:8546" --evm.rpc.api="eth,web3,net,txpool,debug" --json-rpc.enable ``` Then, start a websocket subscription with [`ws`](https://github.com/hashrocket/ws) diff --git a/integration_tests/configs/cronos-experimental-devnet.jsonnet b/integration_tests/configs/cronos-experimental-devnet.jsonnet index 6e6a2e7faf..76af1d8a3e 100644 --- a/integration_tests/configs/cronos-experimental-devnet.jsonnet +++ b/integration_tests/configs/cronos-experimental-devnet.jsonnet @@ -9,8 +9,8 @@ config { 'app-db-backend':: super['app-db-backend'], 'minimum-gas-prices': '100000000000basetcro', 'json-rpc': { - address: '0.0.0.0:{EVMRPC_PORT}', - 'ws-address': '0.0.0.0:{EVMRPC_PORT_WS}', + address: '127.0.0.1:{EVMRPC_PORT}', + 'ws-address': '127.0.0.1:{EVMRPC_PORT_WS}', }, }, genesis+: { diff --git a/integration_tests/configs/default.jsonnet b/integration_tests/configs/default.jsonnet index 04c9a14d78..e2ab47b4ff 100644 --- a/integration_tests/configs/default.jsonnet +++ b/integration_tests/configs/default.jsonnet @@ -14,8 +14,8 @@ 'index-events': ['ethereum_tx.ethereumTxHash'], 'iavl-lazy-loading': true, 'json-rpc': { - address: '0.0.0.0:{EVMRPC_PORT}', - 'ws-address': '0.0.0.0:{EVMRPC_PORT_WS}', + address: '127.0.0.1:{EVMRPC_PORT}', + 'ws-address': '127.0.0.1:{EVMRPC_PORT_WS}', api: 'eth,net,web3,debug,cronos', 'feehistory-cap': 100, 'block-range-cap': 10000, diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index 5abdfe1496..53708a1018 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -191,8 +191,8 @@ def test_statesync(cronos): clustercli.base_port(i), { "json-rpc": { - "address": "0.0.0.0:{EVMRPC_PORT}", - "ws-address": "0.0.0.0:{EVMRPC_PORT_WS}", + "address": "127.0.0.1:{EVMRPC_PORT}", + "ws-address": "127.0.0.1:{EVMRPC_PORT_WS}", } }, ) diff --git a/scripts/cronos-devnet.yaml b/scripts/cronos-devnet.yaml index 0b9b865e1a..1c7ea5a5de 100644 --- a/scripts/cronos-devnet.yaml +++ b/scripts/cronos-devnet.yaml @@ -7,8 +7,8 @@ cronos_777-1: index-events: - ethereum_tx.ethereumTxHash json-rpc: - address: "0.0.0.0:{EVMRPC_PORT}" - ws-address: "0.0.0.0:{EVMRPC_PORT_WS}" + address: "127.0.0.1:{EVMRPC_PORT}" + ws-address: "127.0.0.1:{EVMRPC_PORT_WS}" api: "eth,net,web3,debug,cronos" validators: - coins: 1000000000000000000stake,10000000000000000000000basetcro From d6300dcb84288f7708f3ef7408aa4d19fc9b28be Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 15 Aug 2023 17:56:01 +0800 Subject: [PATCH 2/5] pytest -v -s test_basic.py::test_tx_inclusion --- integration_tests/configs/default.jsonnet | 5 ++- integration_tests/test_basic.py | 40 +++++++++++------------ integration_tests/utils.py | 17 ++++++++++ 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/integration_tests/configs/default.jsonnet b/integration_tests/configs/default.jsonnet index e2ab47b4ff..d40eb62b7b 100644 --- a/integration_tests/configs/default.jsonnet +++ b/integration_tests/configs/default.jsonnet @@ -9,6 +9,9 @@ }, }, 'app-config': { + 'evm': { + 'max-tx-gas-wanted': 400000, + }, 'app-db-backend': 'pebbledb', 'minimum-gas-prices': '0basetcro', 'index-events': ['ethereum_tx.ethereumTxHash'], @@ -61,7 +64,7 @@ consensus_params: { block: { max_bytes: '1048576', - max_gas: '81500000', + max_gas: '40000000', }, }, app_state: { diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index 53708a1018..abb2dc53fc 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -24,6 +24,7 @@ modify_command_in_supervisor_config, send_transaction, send_txs, + send_txs2, wait_for_block, wait_for_port, ) @@ -668,40 +669,37 @@ def test_contract(cronos): origin_cmd = None -@pytest.mark.parametrize("max_gas_wanted", [80000000, 40000000, 25000000, 500000]) -def test_tx_inclusion(cronos, max_gas_wanted): +def test_tx_inclusion(cronos): """ - send multiple heavy transactions at the same time. - check they are included in consecutively blocks without failure. test against different max-gas-wanted configuration. """ - - def fn(cmd): - global origin_cmd - if origin_cmd is None: - origin_cmd = cmd - return f"{origin_cmd} --evm.max-tx-gas-wanted {max_gas_wanted}" - - modify_command_in_supervisor_config( - cronos.base_dir / "tasks.ini", - lambda cmd: fn(cmd), - ) - cronos.supervisorctl("update") - wait_for_port(ports.evmrpc_port(cronos.base_port(0))) - + max_gas_wanted = 40000000 w3 = cronos.w3 cli = cronos.cosmos_cli() - block_gas_limit = 81500000 - tx_gas_limit = 80000000 + block_gas_limit = 40000000 + tx_gas_limit = 289275000 max_tx_in_block = block_gas_limit // min(max_gas_wanted, tx_gas_limit) print("max_tx_in_block", max_tx_in_block) - to = ADDRS["validator"] - params = {"gas": tx_gas_limit} - _, sended_hash_set = send_txs(w3, cli, to, list(KEYS.values())[0:4], params) + + contract = deploy_contract( + w3, + CONTRACTS["TestMessageCall"], + key=KEYS["community"], + ) + iterations = 13000 + tx = contract.functions.test(iterations).build_transaction() + print("estimate_gas", w3.eth.estimate_gas(tx)) + tx["gas"] = tx_gas_limit + # receipt = send_transaction(w3, tx, KEYS["community"]) + _, sended_hash_set = send_txs2(w3, cli, list(KEYS.values())[0:4], tx) block_nums = [ w3.eth.wait_for_transaction_receipt(h).blockNumber for h in sended_hash_set ] + for h in sended_hash_set: + print("res:", w3.eth.wait_for_transaction_receipt(h)) block_nums.sort() print(f"all block numbers: {block_nums}") # the transactions should be included according to max_gas_wanted diff --git a/integration_tests/utils.py b/integration_tests/utils.py index 6df869c722..5d97adfab3 100644 --- a/integration_tests/utils.py +++ b/integration_tests/utils.py @@ -510,3 +510,20 @@ def send_txs(w3, cli, to, keys, params): sended_hash_set = send_raw_transactions(w3, raw_transactions) return block_num_0, sended_hash_set + + +def send_txs2(w3, cli, keys, tx): + # use different sender accounts to be able be send concurrently + raw_transactions = [] + for key_from in keys: + signed = sign_transaction(w3, tx, key_from) + raw_transactions.append(signed.rawTransaction) + + # wait block update + block_num_0 = wait_for_new_blocks(cli, 1, sleep=0.1) + print(f"block number start: {block_num_0}") + + # send transactions + sended_hash_set = send_raw_transactions(w3, raw_transactions) + + return block_num_0, sended_hash_set From 1482e6fc9b937f60662fd64f1b2eef070144f89a Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 15 Aug 2023 22:34:28 +0800 Subject: [PATCH 3/5] debug --- integration_tests/test_basic.py | 24 +++--------------------- integration_tests/utils.py | 6 +++--- scripts/run-integration-tests | 2 +- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index abb2dc53fc..2500bc226d 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -676,14 +676,9 @@ def test_tx_inclusion(cronos): test against different max-gas-wanted configuration. """ - max_gas_wanted = 40000000 w3 = cronos.w3 cli = cronos.cosmos_cli() - block_gas_limit = 40000000 tx_gas_limit = 289275000 - max_tx_in_block = block_gas_limit // min(max_gas_wanted, tx_gas_limit) - print("max_tx_in_block", max_tx_in_block) - contract = deploy_contract( w3, CONTRACTS["TestMessageCall"], @@ -693,24 +688,11 @@ def test_tx_inclusion(cronos): tx = contract.functions.test(iterations).build_transaction() print("estimate_gas", w3.eth.estimate_gas(tx)) tx["gas"] = tx_gas_limit - # receipt = send_transaction(w3, tx, KEYS["community"]) _, sended_hash_set = send_txs2(w3, cli, list(KEYS.values())[0:4], tx) - block_nums = [ - w3.eth.wait_for_transaction_receipt(h).blockNumber for h in sended_hash_set - ] for h in sended_hash_set: - print("res:", w3.eth.wait_for_transaction_receipt(h)) - block_nums.sort() - print(f"all block numbers: {block_nums}") - # the transactions should be included according to max_gas_wanted - if max_tx_in_block == 1: - for block_num, next_block_num in zip(block_nums, block_nums[1:]): - assert next_block_num == block_num + 1 - else: - for num in block_nums[1:max_tx_in_block]: - assert num == block_nums[0] - for num in block_nums[max_tx_in_block:]: - assert num == block_nums[0] + 1 + res = w3.eth.wait_for_transaction_receipt(h) + print("res:", h.hex(), res["cumulativeGasUsed"], res["gasUsed"], res["status"]) + time.sleep(30) def test_replay_protection(cronos): diff --git a/integration_tests/utils.py b/integration_tests/utils.py index 5d97adfab3..d57dc8a92b 100644 --- a/integration_tests/utils.py +++ b/integration_tests/utils.py @@ -28,10 +28,10 @@ Account.enable_unaudited_hdwallet_features() ACCOUNTS = { "validator": Account.from_mnemonic(os.getenv("VALIDATOR1_MNEMONIC")), - "validator2": Account.from_mnemonic(os.getenv("VALIDATOR2_MNEMONIC")), + # "validator2": Account.from_mnemonic(os.getenv("VALIDATOR2_MNEMONIC")), "community": Account.from_mnemonic(os.getenv("COMMUNITY_MNEMONIC")), - "signer1": Account.from_mnemonic(os.getenv("SIGNER1_MNEMONIC")), - "signer2": Account.from_mnemonic(os.getenv("SIGNER2_MNEMONIC")), + # "signer1": Account.from_mnemonic(os.getenv("SIGNER1_MNEMONIC")), + # "signer2": Account.from_mnemonic(os.getenv("SIGNER2_MNEMONIC")), } KEYS = {name: account.key for name, account in ACCOUNTS.items()} ADDRS = {name: account.address for name, account in ACCOUNTS.items()} diff --git a/scripts/run-integration-tests b/scripts/run-integration-tests index 1609dd454b..75bed83a76 100755 --- a/scripts/run-integration-tests +++ b/scripts/run-integration-tests @@ -10,4 +10,4 @@ cd ../integration_tests/contracts HUSKY_SKIP_INSTALL=1 npm install npm run typechain cd .. -nix-shell --run "pytest -vv -s" +nix-shell --run "pytest -v -s test_basic.py::test_tx_inclusion" From 7b13c87a58f3068e151dbcb2f891bdb4575fd430 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 16 Aug 2023 14:29:53 +0800 Subject: [PATCH 4/5] blk --- integration_tests/test_basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index 2500bc226d..6c0b20e494 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -691,7 +691,7 @@ def test_tx_inclusion(cronos): _, sended_hash_set = send_txs2(w3, cli, list(KEYS.values())[0:4], tx) for h in sended_hash_set: res = w3.eth.wait_for_transaction_receipt(h) - print("res:", h.hex(), res["cumulativeGasUsed"], res["gasUsed"], res["status"]) + print("res:", h.hex(), res["blockNumber"], res["cumulativeGasUsed"], res["gasUsed"], res["status"]) time.sleep(30) From d836f4c687abf086b4d6e4a203c3d611afa0b80e Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 16 Aug 2023 14:30:46 +0800 Subject: [PATCH 5/5] change back rocksdb --- integration_tests/configs/default.jsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/configs/default.jsonnet b/integration_tests/configs/default.jsonnet index d40eb62b7b..a62dd1f563 100644 --- a/integration_tests/configs/default.jsonnet +++ b/integration_tests/configs/default.jsonnet @@ -12,7 +12,7 @@ 'evm': { 'max-tx-gas-wanted': 400000, }, - 'app-db-backend': 'pebbledb', + 'app-db-backend': 'rocksdb', 'minimum-gas-prices': '0basetcro', 'index-events': ['ethereum_tx.ethereumTxHash'], 'iavl-lazy-loading': true,