diff --git a/go.mod b/go.mod index 90fd401660..b3ed002fba 100644 --- a/go.mod +++ b/go.mod @@ -252,10 +252,10 @@ require ( // release/v0.50.x replace ( - cosmossdk.io/client/v2 => github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240911084450-6870ba130be2 - cosmossdk.io/store => github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240911084450-6870ba130be2 - cosmossdk.io/x/tx => github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240911084450-6870ba130be2 - github.com/cosmos/cosmos-sdk => github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240911084450-6870ba130be2 + cosmossdk.io/client/v2 => github.com/mmsqe/cosmos-sdk/client/v2 v2.0.0-20240912123054-e5f1bce93ddd + cosmossdk.io/store => github.com/mmsqe/cosmos-sdk/store v0.0.0-20240912123054-e5f1bce93ddd + cosmossdk.io/x/tx => github.com/mmsqe/cosmos-sdk/x/tx v0.0.0-20240912123054-e5f1bce93ddd + github.com/cosmos/cosmos-sdk => github.com/mmsqe/cosmos-sdk v0.46.0-beta2.0.20240912123054-e5f1bce93ddd ) replace ( @@ -275,7 +275,7 @@ replace ( github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2 github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240425065928-ebb09502e7a7 // develop - github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20240912060135-56f8a5be75ec + github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20240913100216-dbc7eb41488c // Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0 diff --git a/go.sum b/go.sum index 11e4629b0f..dbb7e5e1f1 100644 --- a/go.sum +++ b/go.sum @@ -419,16 +419,8 @@ github.com/crypto-org-chain/btree v0.0.0-20240406140148-2687063b042c h1:MOgfS4+F github.com/crypto-org-chain/btree v0.0.0-20240406140148-2687063b042c/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= github.com/crypto-org-chain/cometbft-db v0.0.0-20231011055109-57922ac52a63 h1:R1QJ9a3XdYMSKo+1RdFifxb/g3lNypC52L/rpYrWoKo= github.com/crypto-org-chain/cometbft-db v0.0.0-20231011055109-57922ac52a63/go.mod h1:rocwIfnS+kA060x64gkSIRvWB9StSppIkJuo5MWzL24= -github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240911084450-6870ba130be2 h1:4SoAvnxDaiIWcgm6XOmPDIdCf4/WNhNYLXGbij1eaA0= -github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240911084450-6870ba130be2/go.mod h1:Rb43DdB0i/rKcCN69Tg2X3+zA4WhJ7MC8K3a6Ezh38E= -github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240911084450-6870ba130be2 h1:5oGZtOUcauk9dtv+8BCfj2PEQyXEEEV+K3sP4OSvBmg= -github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240911084450-6870ba130be2/go.mod h1:W5sR4asmVDUhJpEmuXTUBkk/yEefKlXTjVWcNciVSR0= -github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240911084450-6870ba130be2 h1:CGh5I0L6IYhe0AJevb4vf5TE3ru+qAgMs437BlWCwo8= -github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240911084450-6870ba130be2/go.mod h1:gjE3DZe4t/+VeIk6CmrouyqiuDbZ7QOVDDq3nLqBTpg= -github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240911084450-6870ba130be2 h1:mxlOSCru7YgmX055rrlkCSUu0D8lAqJ8Dnhp0yXCBuM= -github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240911084450-6870ba130be2/go.mod h1:RTiTs4hkXG6IvYGknvB8p79YgjYJdcbzLUOGJChsPnY= -github.com/crypto-org-chain/ethermint v0.6.1-0.20240912060135-56f8a5be75ec h1:9J1fV54SQDeFzzWQnIvr1uwVJIAIkPv3+sm0RapfDM0= -github.com/crypto-org-chain/ethermint v0.6.1-0.20240912060135-56f8a5be75ec/go.mod h1:D2lnc8ARuVmgc2/2IWla2Ky1o8/pjmyrnIt+d46Clco= +github.com/crypto-org-chain/ethermint v0.6.1-0.20240913100216-dbc7eb41488c h1:pJJNL+ZganmfcxzEijVNqwNDhzXsTyMk/Of1/lUvxlM= +github.com/crypto-org-chain/ethermint v0.6.1-0.20240913100216-dbc7eb41488c/go.mod h1:D2lnc8ARuVmgc2/2IWla2Ky1o8/pjmyrnIt+d46Clco= github.com/crypto-org-chain/go-block-stm v0.0.0-20240912024944-1cd89976aa5e h1:FFpE6+Y4o5GxkeGwUcETM6amgohh7msWvWf1MDqueVc= github.com/crypto-org-chain/go-block-stm v0.0.0-20240912024944-1cd89976aa5e/go.mod h1:iwQTX9xMX8NV9k3o2BiWXA0SswpsZrDk5q3gA7nWYiE= github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240425065928-ebb09502e7a7 h1:V43F3JFcqG4MUThf9W/DytnPblpR6CcaLBw2Wx6zTgE= @@ -898,6 +890,14 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= +github.com/mmsqe/cosmos-sdk v0.46.0-beta2.0.20240912123054-e5f1bce93ddd h1:kY7l1i7Gt0makuMuOBmGWrxzbY1I1/Qy6eslEzQDcJA= +github.com/mmsqe/cosmos-sdk v0.46.0-beta2.0.20240912123054-e5f1bce93ddd/go.mod h1:Rb43DdB0i/rKcCN69Tg2X3+zA4WhJ7MC8K3a6Ezh38E= +github.com/mmsqe/cosmos-sdk/client/v2 v2.0.0-20240912123054-e5f1bce93ddd h1:GcrVJhj4QeD94Ln9bI/9zlQVy7XNRNsw22zLbqPNiK8= +github.com/mmsqe/cosmos-sdk/client/v2 v2.0.0-20240912123054-e5f1bce93ddd/go.mod h1:W5sR4asmVDUhJpEmuXTUBkk/yEefKlXTjVWcNciVSR0= +github.com/mmsqe/cosmos-sdk/store v0.0.0-20240912123054-e5f1bce93ddd h1:ckbMXs43RBcGaTxlkJn2j9Vg3o/IU92jJ+N7Q6EYnUA= +github.com/mmsqe/cosmos-sdk/store v0.0.0-20240912123054-e5f1bce93ddd/go.mod h1:gjE3DZe4t/+VeIk6CmrouyqiuDbZ7QOVDDq3nLqBTpg= +github.com/mmsqe/cosmos-sdk/x/tx v0.0.0-20240912123054-e5f1bce93ddd h1:fyLJ0iBHsWf955qiJkRnDxTSoIh82pmqUe+YuNaGVd8= +github.com/mmsqe/cosmos-sdk/x/tx v0.0.0-20240912123054-e5f1bce93ddd/go.mod h1:RTiTs4hkXG6IvYGknvB8p79YgjYJdcbzLUOGJChsPnY= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= diff --git a/gomod2nix.toml b/gomod2nix.toml index 1172af8aa7..474d4975a3 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -17,9 +17,9 @@ schema = 3 version = "v0.7.5" hash = "sha256-Nuw697sJr56kU3EU7DV1eYNkyI76psznIVqYAV6RfbQ=" [mod."cosmossdk.io/client/v2"] - version = "v2.0.0-20240911084450-6870ba130be2" + version = "v2.0.0-20240912123054-e5f1bce93ddd" hash = "sha256-60hmufv3Ml4Pv3zNwgn8eeqlEINOR6n9MKr2QHddoxo=" - replaced = "github.com/crypto-org-chain/cosmos-sdk/client/v2" + replaced = "github.com/mmsqe/cosmos-sdk/client/v2" [mod."cosmossdk.io/collections"] version = "v0.4.0" hash = "sha256-minFyzgO/D+Oda4E3B1qvOAN5qd65SjS6nmjca4cp/8=" @@ -42,9 +42,9 @@ schema = 3 version = "v0.0.0-20230608160436-666c345ad23d" hash = "sha256-6BMBA98BpK3jG6++ZE4LdPQwwpS+lZ0GLMRF1fO4UfM=" [mod."cosmossdk.io/store"] - version = "v0.0.0-20240911084450-6870ba130be2" + version = "v0.0.0-20240912123054-e5f1bce93ddd" hash = "sha256-Dm3sSZNJBcnBF33PULoTpK4rkNQbsZl0DfTqH1GPCQM=" - replaced = "github.com/crypto-org-chain/cosmos-sdk/store" + replaced = "github.com/mmsqe/cosmos-sdk/store" [mod."cosmossdk.io/tools/confix"] version = "v0.1.1" hash = "sha256-/Et2FFhb4XfakbLFvGQK3QxN5Y7alzO+DGfi2/EWbxo=" @@ -55,9 +55,9 @@ schema = 3 version = "v0.1.0" hash = "sha256-/gWvrqvy6bW90+NU66T+9QysYgvG1VbwfYJZ8tkqpeA=" [mod."cosmossdk.io/x/tx"] - version = "v0.0.0-20240911084450-6870ba130be2" + version = "v0.0.0-20240912123054-e5f1bce93ddd" hash = "sha256-xT5IdapEx1h46ofBpxcBQfzGF2EntmC8xZl7aym/6xE=" - replaced = "github.com/crypto-org-chain/cosmos-sdk/x/tx" + replaced = "github.com/mmsqe/cosmos-sdk/x/tx" [mod."cosmossdk.io/x/upgrade"] version = "v0.1.1" hash = "sha256-bM9ybpaibMH7k4M6/QAXCZ3fJcADfJHxvMgp4AVUihs=" @@ -167,9 +167,9 @@ schema = 3 version = "v1.0.0-beta.5" hash = "sha256-Fy/PbsOsd6iq0Njy3DVWK6HqWsogI+MkE8QslHGWyVg=" [mod."github.com/cosmos/cosmos-sdk"] - version = "v0.50.6-0.20240911084450-6870ba130be2" - hash = "sha256-kl2sLe8vITIguRGtdeviDeP3R5JIbRg+eDsheGd4PqM=" - replaced = "github.com/crypto-org-chain/cosmos-sdk" + version = "v0.46.0-beta2.0.20240912123054-e5f1bce93ddd" + hash = "sha256-ehNXD1RsXdC+Et+RrwuycvJBQ2yQnPNQIAb1JCUM77U=" + replaced = "github.com/mmsqe/cosmos-sdk" [mod."github.com/cosmos/go-bip39"] version = "v1.0.0" hash = "sha256-Qm2aC2vaS8tjtMUbHmlBSagOSqbduEEDwc51qvQaBmA=" @@ -259,8 +259,8 @@ schema = 3 hash = "sha256-lE4G5FaRb3MVi9FFVn+WlwsSTOB4SbjmVboKyQ5yB0A=" replaced = "github.com/crypto-org-chain/go-ethereum" [mod."github.com/evmos/ethermint"] - version = "v0.6.1-0.20240912060135-56f8a5be75ec" - hash = "sha256-LkGl7SLTfEJ5wf/dKf7Dq8P7LQLNspjm6zz+iPSY7Ic=" + version = "v0.6.1-0.20240913100216-dbc7eb41488c" + hash = "sha256-C5idKvZvEjbBzQdVPhbNOVHztzolIR/JL9oenAn5lOk=" replaced = "github.com/crypto-org-chain/ethermint" [mod."github.com/fatih/color"] version = "v1.16.0" diff --git a/testground/benchmark/benchmark/main.py b/testground/benchmark/benchmark/main.py index 16c1a652dd..1ea69f97ce 100644 --- a/testground/benchmark/benchmark/main.py +++ b/testground/benchmark/benchmark/main.py @@ -36,7 +36,7 @@ def entrypoint(ctx: Context): test_finish_entry = f"finish-test-{ctx.params.test_group_id}" if not ctx.is_validator: - generate_load(cli, ctx.params.num_accounts, ctx.params.num_txs) + generate_load(cli, ctx.params.num_accounts) print("finish test", ctx.group_seq) ctx.sync.signal_and_wait( test_finish_entry, ctx.params.test_group_instance_count diff --git a/testground/benchmark/benchmark/peer.py b/testground/benchmark/benchmark/peer.py index eb49fd5a7c..664596cae3 100644 --- a/testground/benchmark/benchmark/peer.py +++ b/testground/benchmark/benchmark/peer.py @@ -1,14 +1,17 @@ import json import tempfile +from concurrent.futures import ThreadPoolExecutor, as_completed from pathlib import Path from typing import List +from eth_account import Account + from .cli import ChainCommand from .context import Context from .network import get_data_ip from .topology import connect_all from .types import GenesisAccount, PeerPacket -from .utils import patch_json, patch_toml +from .utils import eth_to_bech32, parse_coins, patch_json, patch_toml VAL_ACCOUNT = "validator" VAL_INITIAL_AMOUNT = "100000000000000000000basecro" @@ -30,6 +33,8 @@ def bootstrap(ctx: Context, cli) -> PeerPacket: ctx.params.chain_id, ctx.params.test_group_id, ctx.group_seq, + ctx.params.num_accounts, + ctx.params.num_txs, ) data = ctx.sync.publish_subscribe_simple( @@ -58,6 +63,8 @@ def init_node( chain_id: str, group: str, group_seq: int, + num_accounts: int, + num_txs: int, ) -> PeerPacket: default_kwargs = { "home": home, @@ -72,6 +79,48 @@ def init_node( ) cli("keys", "add", VAL_ACCOUNT, **default_kwargs) cli("keys", "add", "account", **default_kwargs) + users = [] + tx = { + "to": "0x0000000000000000000000000000000000000000", + "value": 1, + "gas": 21000, + "gasPrice": 1000000000, + "chainId": 777, + } + futs = [] + with ThreadPoolExecutor(max_workers=num_accounts * num_txs) as executor: + for _ in range(num_accounts): + user = Account.create() + users.append( + { + "address": eth_to_bech32(user.address), + "coins": parse_coins(ACC_INITIAL_AMOUNT), + } + ) + for i in range(num_txs): + tx["nonce"] = i + raw = Account.from_key(user.key).sign_transaction(tx).rawTransaction + futs.append( + executor.submit( + cli, + "tx", + "evm", + "raw", + raw.hex(), + "-y", + "--generate-only", + "--evm-denom", + DEFAULT_DENOM, + **default_kwargs, + ) + ) + try: + tmp_txs = [fut.result() for fut in as_completed(futs)] + except Exception as e: + print("generate account failed", e) + + file = home / "tmp_txs.json" + file.write_text(json.dumps(tmp_txs)) validator_addr = cli("keys", "show", VAL_ACCOUNT, "--address", **default_kwargs) account_addr = cli("keys", "show", "account", "--address", **default_kwargs) accounts = [ @@ -82,10 +131,12 @@ def init_node( node_id = cli("comet", "show-node-id", **default_kwargs) peer_id = f"{node_id}@{ip}:26656" peer = PeerPacket( + home=home, ip=str(ip), node_id=node_id, peer_id=peer_id, accounts=accounts, + users=users, ) if group == VALIDATOR_GROUP: @@ -97,6 +148,11 @@ def init_node( def gen_genesis( cli: ChainCommand, leader_home: Path, peers: List[PeerPacket], genesis_patch: dict ): + default_kwargs = { + "home": leader_home, + "chain_id": "cronos_777-1", + "keyring_backend": "test", + } for peer in peers: for account in peer.accounts: cli( @@ -106,13 +162,22 @@ def gen_genesis( account.balance, home=leader_home, ) + file = peer.home / "users.json" + file.write_text(json.dumps(peer.users)) + cli( + "genesis", + "bulk-add-genesis-account", + file, + **default_kwargs, + ) + collect_gen_tx(cli, peers, home=leader_home) cli("genesis", "validate", home=leader_home) return patch_json( leader_home / "config" / "genesis.json", { "consensus.params.block.max_gas": "163000000", - "app_state.evm.params.evm_denom": "basecro", + "app_state.evm.params.evm_denom": DEFAULT_DENOM, "app_state.feemarket.params.no_base_fee": True, **genesis_patch, }, diff --git a/testground/benchmark/benchmark/sendtx.py b/testground/benchmark/benchmark/sendtx.py index 34bb9f2cd0..a18c7e0142 100644 --- a/testground/benchmark/benchmark/sendtx.py +++ b/testground/benchmark/benchmark/sendtx.py @@ -1,10 +1,12 @@ +import json +import tempfile import time from concurrent.futures import ThreadPoolExecutor, as_completed import web3 from eth_account import Account -from .utils import export_eth_account, send_transaction, send_transactions +from .utils import send_transaction, send_transactions TEST_AMOUNT = 1000000000000000000 GAS_PRICE = 1000000000 @@ -77,13 +79,58 @@ def sendtx(w3: web3.Web3, acct: Account, tx_amount: int): ) -def generate_load(cli, num_accounts, num_txs, **kwargs): - w3 = web3.Web3(web3.providers.HTTPProvider("http://localhost:8545")) - assert w3.eth.chain_id == 777 - genesis_account = export_eth_account(cli, "account", **kwargs) - accounts = fund_test_accounts(w3, genesis_account, num_accounts) +def sendrawtx(cli, tx, **kwargs): + tx = json.loads(tx) + msgs = [tx["body"]["messages"][0]] + fee = tx["auth_info"]["fee"] + total_fee = sum(int(amt["amount"]) for amt in fee["amount"]) + gas_limit = int(fee["gas_limit"]) + cosmos_tx = { + "body": { + "messages": msgs, + "memo": "", + "timeout_height": "0", + "extension_options": [ + {"@type": "/ethermint.evm.v1.ExtensionOptionsEthereumTx"} + ], + "non_critical_extension_options": [], + }, + "auth_info": { + "signer_infos": [], + "fee": { + "amount": [{"denom": "basecro", "amount": str(total_fee)}], + "gas_limit": str(gas_limit), + "payer": "", + "granter": "", + }, + }, + "signatures": [], + } + with tempfile.NamedTemporaryFile("w") as fp: + json.dump(cosmos_tx, fp) + fp.flush() + rsp = json.loads(cli("tx", "broadcast", fp.name, **kwargs)) + cli("tx", "broadcast", fp.name, **kwargs) + if rsp["code"] == 0: + print("txhash", rsp["txhash"]) + + +def sendrawtx_retry(cli, tx, **kwargs): + for i in range(0, 3): + try: + sendrawtx(cli, tx, **kwargs) + break + except Exception as e: + print("sendrawtx failed", i, e) + + +def generate_load(cli, num_accounts, **kwargs): + home = kwargs.get("home") + tmp_txs = [] + with open(home / "tmp_txs.json", "r") as file: + tmp_txs = json.load(file) with ThreadPoolExecutor(max_workers=num_accounts) as executor: - futs = (executor.submit(sendtx, w3, acct, num_txs) for acct in accounts) + futs = (executor.submit(sendrawtx_retry, cli, tx, **kwargs) for tx in tmp_txs) for fut in as_completed(futs): try: fut.result() diff --git a/testground/benchmark/benchmark/stateless.py b/testground/benchmark/benchmark/stateless.py index 20693224f3..8e05d2c5ca 100644 --- a/testground/benchmark/benchmark/stateless.py +++ b/testground/benchmark/benchmark/stateless.py @@ -6,6 +6,7 @@ import tarfile import tempfile import time +from concurrent.futures import ThreadPoolExecutor, as_completed from datetime import datetime from pathlib import Path from typing import List @@ -32,7 +33,6 @@ # use cronosd on host machine LOCAL_CRONOSD_PATH = "cronosd" DEFAULT_CHAIN_ID = "cronos_777-1" -DEFAULT_DENOM = "basecro" # the container must be deployed with the prefixed name HOSTNAME_TEMPLATE = "testplan-{index}" LOCAL_RPC = "http://localhost:26657" @@ -65,11 +65,19 @@ def gen( for i in range(validators): print("init validator", i) ip = hostname_template.format(index=i) - peers.append(init_node_local(cli, outdir, VALIDATOR_GROUP, i, ip)) + peers.append( + init_node_local( + cli, outdir, VALIDATOR_GROUP, i, ip, num_accounts, num_txs + ) + ) for i in range(fullnodes): print("init fullnode", i) ip = hostname_template.format(index=i + validators) - peers.append(init_node_local(cli, outdir, FULLNODE_GROUP, i, ip)) + peers.append( + init_node_local( + cli, outdir, FULLNODE_GROUP, i, ip, num_accounts, num_txs + ) + ) print("prepare genesis") # use a full node directory to prepare the genesis file @@ -161,12 +169,12 @@ def run( if group == FULLNODE_GROUP or cfg.get("validator-generate-load", True): wait_for_w3() - generate_load( - cli, cfg["num_accounts"], cfg["num_txs"], home=home, output="json" - ) + generate_load(cli, cfg["num_accounts"], home=home, output="json") # node quit when the chain is idle or halted for a while - detect_idle_halted(20, 20) + detect_idle_halted(3, 3) + + print_balances(cli, home) with (home / "block_stats.log").open("w") as logfile: dump_block_stats(logfile) @@ -186,6 +194,39 @@ def run( shutil.copy(output, filename) +def print_balances(cli, home): + with open(home / "users.json", "r") as file: + futs = [] + users = json.load(file) + with ThreadPoolExecutor(max_workers=len(users)) as executor: + for user in users: + futs.append( + executor.submit( + cli, + "query", + "bank", + "balances", + user["address"], + height=0, + home=home, + output="json", + ) + ) + + for idx, fut in enumerate(as_completed(futs)): + user = users[idx] + try: + result = json.loads(fut.result()) + print( + "test end, address:", + user["address"], + "balance:", + result["balances"][0]["amount"], + ) + except Exception as e: + print("get balance failed", user["address"], e) + + def output_filter(group, group_seq: int): """ filter out some big and useless paths to reduce size of output artifacts @@ -264,7 +305,13 @@ def block_txs(height): def init_node_local( - cli: ChainCommand, outdir: Path, group: str, group_seq: int, ip: str + cli: ChainCommand, + outdir: Path, + group: str, + group_seq: int, + ip: str, + num_accounts: int, + num_txs: int, ) -> PeerPacket: return init_node( cli, @@ -273,6 +320,8 @@ def init_node_local( DEFAULT_CHAIN_ID, group, group_seq, + num_accounts, + num_txs, ) diff --git a/testground/benchmark/benchmark/types.py b/testground/benchmark/benchmark/types.py index 4025df380d..d7c7facd1f 100644 --- a/testground/benchmark/benchmark/types.py +++ b/testground/benchmark/benchmark/types.py @@ -1,3 +1,4 @@ +from pathlib import Path from typing import List, Optional from pydantic import BaseModel @@ -18,5 +19,7 @@ class PeerPacket(BaseModel): ip: str node_id: str peer_id: str + home: Path accounts: List[GenesisAccount] + users: List[dict] gentx: Optional[dict] = None diff --git a/testground/benchmark/benchmark/utils.py b/testground/benchmark/benchmark/utils.py index 0b0580e20b..5a02e73f1f 100644 --- a/testground/benchmark/benchmark/utils.py +++ b/testground/benchmark/benchmark/utils.py @@ -1,6 +1,7 @@ import json import socket import time +from itertools import dropwhile, takewhile from pathlib import Path import bech32 @@ -124,3 +125,21 @@ def send_transactions(w3, txs, acct, wait=True): def export_eth_account(cli, name: str, **kwargs) -> Account: kwargs.setdefault("keyring_backend", "test") return Account.from_key(cli("keys", "unsafe-export-eth-key", name, **kwargs)) + + +def eth_to_bech32(addr, prefix="crc"): + bz = bech32.convertbits(HexBytes(addr), 8, 5) + return bech32.bech32_encode(prefix, bz) + + +def parse_coins(value): + coins = [] + for coin in value.split(","): + amount = "".join(takewhile(is_float, coin)) + denom = "".join(dropwhile(is_float, coin)) + coins.append({"amount": amount, "denom": denom.strip()}) + return coins + + +def is_float(s): + return str.isdigit(s) or s == "."