Skip to content

Commit

Permalink
Problem: don't work on tendermint 0.35
Browse files Browse the repository at this point in the history
Closes: #45
Solution:
- support new field names
- remove self from peer list
- enable legacy p2p mode
  • Loading branch information
yihuang committed Feb 17, 2022
1 parent 5a2732f commit 95584f9
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions pystarport/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1102,6 +1117,13 @@ def format_value(v, ctx):
return v


def remove_peer(peers, peer):
"remove peer from peers"
items = peers.split(",")
items.remove(peer)
return ",".join(items)


if __name__ == "__main__":
interact("rm -r data; mkdir data", ignore_error=True)
data_dir = Path("data")
Expand Down

0 comments on commit 95584f9

Please sign in to comment.