Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the new P2P topology format #1685

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions cardano_node_tests/utils/cluster_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,19 @@ def _gen_p2p_topology(self, ports: List[int], fixed_ports: List[int]) -> dict:
# select fixed ports and several randomly selected ports
selected_ports = set(fixed_ports + random.sample(ports, 3))
access_points = [{"address": "127.0.0.1", "port": port} for port in selected_ports]
topology = {
"localRoots": [
{"accessPoints": access_points, "advertise": False, "valency": len(access_points)},
],
"publicRoots": [],
}
return topology

def _gen_p2p_topology_old(self, ports: List[int], fixed_ports: List[int]) -> dict:
"""Generate p2p topology for given ports in the old topology format."""
# select fixed ports and several randomly selected ports
selected_ports = set(fixed_ports + random.sample(ports, 3))
access_points = [{"address": "127.0.0.1", "port": port} for port in selected_ports]
topology = {
"LocalRoots": {
"groups": [
Expand Down Expand Up @@ -277,14 +290,26 @@ def _gen_topology_files(self, destdir: Path, nodes: Sequence[NodePorts]) -> None
all_except = list(all_nodes - {node_rec.node})
node_name = "bft1" if node_rec.num == 0 else f"pool{node_rec.num}"

# legacy topology
# Legacy topology

topology = self._gen_legacy_topology(ports=all_except)
dest_legacy = destdir / f"topology-{node_name}.json"
dest_legacy.write_text(f"{json.dumps(topology, indent=4)}\n")

# p2p topology
# P2P topology

fixed_ports = list(first_four - {node_rec.node})
p2p_topology = self._gen_p2p_topology(ports=all_except, fixed_ports=fixed_ports)

# Use both old and new format for P2P topology.
# When testing mix of legacy and P2P topologies, odd numbered pools use legacy
# topology. Here, for that reason, the decision cannot be based on oddity, otherwise
# we would use just single P2P topology format for all pools. At the same time we
# want the selection process to be deterministic, so we don't want to use random.
if node_rec.num % 3 == 0:
p2p_topology = self._gen_p2p_topology_old(ports=all_except, fixed_ports=fixed_ports)
else:
p2p_topology = self._gen_p2p_topology(ports=all_except, fixed_ports=fixed_ports)

dest_p2p = destdir / f"p2p-topology-{node_name}.json"
dest_p2p.write_text(f"{json.dumps(p2p_topology, indent=4)}\n")

Expand Down