diff --git a/testground/benchmark/benchmark/peer.py b/testground/benchmark/benchmark/peer.py index f8b043b758..91adc5a88d 100644 --- a/testground/benchmark/benchmark/peer.py +++ b/testground/benchmark/benchmark/peer.py @@ -4,6 +4,7 @@ from pathlib import Path from typing import List +import jsonmerge from pydantic.json import pydantic_encoder from .cli import ChainCommand @@ -133,41 +134,54 @@ def gen_genesis( print("genesis validated") return patch_json( leader_home / "config" / "genesis.json", - { - "consensus.params.block.max_gas": "163000000", - "app_state.evm.params.evm_denom": "basecro", - "app_state.feemarket.params.no_base_fee": True, - **genesis_patch, - }, + jsonmerge.merge( + { + "consensus": {"params": {"block": {"max_gas": "163000000"}}}, + "app_state": { + "evm": {"params": {"evm_denom": "basecro"}}, + "feemarket": {"params": {"no_base_fee": True}}, + }, + }, + genesis_patch, + ), ) def patch_configs(home: Path, peers: str, config_patch: dict, app_patch: dict): default_config_patch = { "db_backend": "rocksdb", - "p2p.addr_book_strict": False, - "mempool.recheck": False, - "mempool.size": MEMPOOL_SIZE, - "consensus.timeout_commit": "1s", - "tx_index.indexer": "null", + "p2p": {"addr_book_strict": False}, + "mempool": { + "recheck": False, + "size": MEMPOOL_SIZE, + }, + "consensus": {"timeout_commit": "1s"}, + "tx_index": {"indexer": "null"}, } default_app_patch = { "minimum-gas-prices": "0basecro", "index-events": ["ethereum_tx.ethereumTxHash"], - "memiavl.enable": True, - "mempool.max-txs": MEMPOOL_SIZE, - "evm.block-executor": "block-stm", # or "sequential" - "evm.block-stm-workers": 0, - "evm.block-stm-pre-estimate": True, - "json-rpc.enable-indexer": True, + "memiavl": { + "enable": True, + "cache-size": 0, + }, + "mempool": {"max-txs": MEMPOOL_SIZE}, + "evm": { + "block-executor": "block-stm", # or "sequential" + "block-stm-workers": 0, + "block-stm-pre-estimate": True, + }, + "json-rpc": {"enable-indexer": True}, } # update persistent_peers and other configs in config.toml - config_patch = { - **default_config_patch, - **config_patch, - "p2p.persistent_peers": peers, - } - app_patch = {**default_app_patch, **app_patch} + config_patch = jsonmerge.merge( + default_config_patch, + jsonmerge.merge( + config_patch, + {"p2p": {"persistent_peers": peers}}, + ), + ) + app_patch = jsonmerge.merge(default_app_patch, app_patch) patch_toml(home / "config" / "config.toml", config_patch) patch_toml(home / "config" / "app.toml", app_patch) diff --git a/testground/benchmark/benchmark/stateless.py b/testground/benchmark/benchmark/stateless.py index 063a59e4ef..b836144475 100644 --- a/testground/benchmark/benchmark/stateless.py +++ b/testground/benchmark/benchmark/stateless.py @@ -91,14 +91,6 @@ def _gen( (outdir / VALIDATOR_GROUP).mkdir(parents=True, exist_ok=True) (outdir / FULLNODE_GROUP).mkdir(parents=True, exist_ok=True) - config_patch = ( - json.loads(config_patch) if isinstance(config_patch, str) else config_patch - ) - app_patch = json.loads(app_patch) if isinstance(app_patch, str) else app_patch - genesis_patch = ( - json.loads(genesis_patch) if isinstance(genesis_patch, str) else genesis_patch - ) - peers = [] for i in range(validators): print("init validator", i) diff --git a/testground/benchmark/benchmark/utils.py b/testground/benchmark/benchmark/utils.py index 172a956887..6cbab687a6 100644 --- a/testground/benchmark/benchmark/utils.py +++ b/testground/benchmark/benchmark/utils.py @@ -4,6 +4,7 @@ from pathlib import Path import bech32 +import jsonmerge import requests import tomlkit import web3 @@ -15,26 +16,24 @@ LOCAL_RPC = "http://localhost:26657" -def patch_dict(doc, kwargs): - for k, v in kwargs.items(): - keys = k.split(".") - assert len(keys) > 0 - cur = doc - for section in keys[:-1]: - cur = cur[section] - cur[keys[-1]] = v +def patch_toml_doc(doc, patch): + for k, v in patch.items(): + if isinstance(v, dict): + patch_toml_doc(doc.setdefault(k, {}), v) + else: + doc[k] = v -def patch_toml(path: Path, kwargs): +def patch_toml(path: Path, patch): doc = tomlkit.parse(path.read_text()) - patch_dict(doc, kwargs) + patch_toml_doc(doc, patch) path.write_text(tomlkit.dumps(doc)) return doc -def patch_json(path: Path, kwargs): +def patch_json(path: Path, patch): doc = json.loads(path.read_text()) - patch_dict(doc, kwargs) + doc = jsonmerge.merge(doc, patch) path.write_text(json.dumps(doc)) return doc diff --git a/testground/benchmark/poetry.lock b/testground/benchmark/poetry.lock index d0e4207cb0..97de198f91 100644 --- a/testground/benchmark/poetry.lock +++ b/testground/benchmark/poetry.lock @@ -965,6 +965,20 @@ files = [ {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, ] +[[package]] +name = "jsonmerge" +version = "1.9.2" +description = "Merge a series of JSON documents." +optional = false +python-versions = "*" +files = [ + {file = "jsonmerge-1.9.2-py3-none-any.whl", hash = "sha256:cab93ee7763fb51a4a09bbdab2eacf499ffb208ab94247ae86acea3e0e823b05"}, + {file = "jsonmerge-1.9.2.tar.gz", hash = "sha256:c43757e0180b0e19b7ae4c130ad42a07cc580c31912f61f4823e8eaf2fa394a3"}, +] + +[package.dependencies] +jsonschema = ">2.4.0" + [[package]] name = "jsonschema" version = "4.22.0" @@ -2188,4 +2202,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "f95059b65ce788a6cef6d06ec8d9dd9e65a819502003b2c3fa269647c0bc299d" +content-hash = "0fb7ea7cb80f99d281286bd73bc04631c191c6b75b7375fa98cc9e590ff65074" diff --git a/testground/benchmark/pyproject.toml b/testground/benchmark/pyproject.toml index e626b7f291..0459065cf8 100644 --- a/testground/benchmark/pyproject.toml +++ b/testground/benchmark/pyproject.toml @@ -17,6 +17,7 @@ bech32 = "^1" requests = "^2.32" click = "^8.1.7" ujson = "^5.10.0" +jsonmerge = "^1.9.2" [tool.poetry.dev-dependencies] pytest = "^8.2"