From 5c8b70663c01ebc259e861f448754f3b0cfe1304 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Thu, 17 Feb 2022 15:06:37 +0800 Subject: [PATCH] Problem: don't work on tendermint 0.35 Closes: #45 Solution: - support new field names - remove self from peer list - enable legacy p2p mode --- pystarport/cluster.py | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/pystarport/cluster.py b/pystarport/cluster.py index f2fe7f2..9856d5b 100644 --- a/pystarport/cluster.py +++ b/pystarport/cluster.py @@ -846,10 +846,16 @@ def create_account(cli, account, use_ledger=False): ] ) for i, val in enumerate(config["validators"]): + self_peer = "tcp://%s@%s:%d" % ( + cli.node_id(i), + val["hostname"], + ports.p2p_port(val["base_port"]), + ) + clean_peers = remove_peer(peers, self_peer) edit_tm_cfg( data_dir / f"node{i}/config/config.toml", val["base_port"], - peers, + clean_peers, val.get("config", {}), ) edit_app_cfg( @@ -1033,18 +1039,27 @@ def docker_compose_yml(cmd, validators, data_dir, image): def edit_tm_cfg(path, base_port, peers, config, *, custom_edit=None): + "field name changed after tendermint 0.35, support both flavours." doc = tomlkit.parse(open(path).read()) + doc["mode"] = "validator" # tendermint is start in process, not needed # doc['proxy_app'] = 'tcp://127.0.0.1:%d' % abci_port(base_port) - doc["rpc"]["laddr"] = "tcp://0.0.0.0:%d" % ports.rpc_port(base_port) - doc["rpc"]["pprof_laddr"] = "localhost:%d" % ports.pprof_port(base_port) - doc["rpc"]["grpc_laddr"] = "tcp://0.0.0.0:%d" % ports.grpc_port_tx_only(base_port) - doc["p2p"]["laddr"] = "tcp://0.0.0.0:%d" % ports.p2p_port(base_port) - doc["p2p"]["persistent_peers"] = peers - doc["p2p"]["addr_book_strict"] = False - doc["p2p"]["allow_duplicate_ip"] = True - doc["consensus"]["timeout_commit"] = "1s" - doc["rpc"]["timeout_broadcast_tx_commit"] = "30s" + rpc = doc["rpc"] + rpc["laddr"] = "tcp://0.0.0.0:%d" % ports.rpc_port(base_port) + rpc["pprof_laddr"] = rpc["pprof-laddr"] = "localhost:%d" % ( + ports.pprof_port(base_port), + ) + rpc["timeout_broadcast_tx_commit"] = rpc["timeout-broadcast-tx-commit"] = "30s" + rpc["grpc_laddr"] = rpc["grpc-laddr"] = "tcp://0.0.0.0:%d" % ( + ports.grpc_port_tx_only(base_port), + ) + p2p = doc["p2p"] + # p2p["use-legacy"] = True + p2p["laddr"] = "tcp://0.0.0.0:%d" % ports.p2p_port(base_port) + p2p["persistent_peers"] = p2p["persistent-peers"] = peers + p2p["addr_book_strict"] = p2p["addr-book-strict"] = False + p2p["allow_duplicate_ip"] = p2p["allow-duplicate-ip"] = True + doc["consensus"]["timeout_commit"] = doc["consensus"]["timeout-commit"] = "1s" patch_toml_doc(doc, config) if custom_edit is not None: custom_edit(doc) @@ -1102,6 +1117,13 @@ def format_value(v, ctx): return v +def remove_peer(peers, peer): + "remove peer from peers" + l = peers.split(",") + l.remove(peer) + return ",".join(l) + + if __name__ == "__main__": interact("rm -r data; mkdir data", ignore_error=True) data_dir = Path("data")