Skip to content

Commit

Permalink
Merge pull request #1685 from input-output-hk/support_new_p2p_format
Browse files Browse the repository at this point in the history
Add support for the new P2P topology format
  • Loading branch information
mkoura authored Feb 28, 2023
2 parents a370bc4 + f87843e commit 0c3de01
Showing 1 changed file with 28 additions and 3 deletions.
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

0 comments on commit 0c3de01

Please sign in to comment.