Skip to content

Commit f87843e

Browse files
committed
Add support for the new P2P topology format
See * <IntersectMBO/cardano-node#4559> * <IntersectMBO/cardano-node#4563>
1 parent a370bc4 commit f87843e

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

cardano_node_tests/utils/cluster_scripts.py

+28-3
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,19 @@ def _gen_p2p_topology(self, ports: List[int], fixed_ports: List[int]) -> dict:
213213
# select fixed ports and several randomly selected ports
214214
selected_ports = set(fixed_ports + random.sample(ports, 3))
215215
access_points = [{"address": "127.0.0.1", "port": port} for port in selected_ports]
216+
topology = {
217+
"localRoots": [
218+
{"accessPoints": access_points, "advertise": False, "valency": len(access_points)},
219+
],
220+
"publicRoots": [],
221+
}
222+
return topology
223+
224+
def _gen_p2p_topology_old(self, ports: List[int], fixed_ports: List[int]) -> dict:
225+
"""Generate p2p topology for given ports in the old topology format."""
226+
# select fixed ports and several randomly selected ports
227+
selected_ports = set(fixed_ports + random.sample(ports, 3))
228+
access_points = [{"address": "127.0.0.1", "port": port} for port in selected_ports]
216229
topology = {
217230
"LocalRoots": {
218231
"groups": [
@@ -277,14 +290,26 @@ def _gen_topology_files(self, destdir: Path, nodes: Sequence[NodePorts]) -> None
277290
all_except = list(all_nodes - {node_rec.node})
278291
node_name = "bft1" if node_rec.num == 0 else f"pool{node_rec.num}"
279292

280-
# legacy topology
293+
# Legacy topology
294+
281295
topology = self._gen_legacy_topology(ports=all_except)
282296
dest_legacy = destdir / f"topology-{node_name}.json"
283297
dest_legacy.write_text(f"{json.dumps(topology, indent=4)}\n")
284298

285-
# p2p topology
299+
# P2P topology
300+
286301
fixed_ports = list(first_four - {node_rec.node})
287-
p2p_topology = self._gen_p2p_topology(ports=all_except, fixed_ports=fixed_ports)
302+
303+
# Use both old and new format for P2P topology.
304+
# When testing mix of legacy and P2P topologies, odd numbered pools use legacy
305+
# topology. Here, for that reason, the decision cannot be based on oddity, otherwise
306+
# we would use just single P2P topology format for all pools. At the same time we
307+
# want the selection process to be deterministic, so we don't want to use random.
308+
if node_rec.num % 3 == 0:
309+
p2p_topology = self._gen_p2p_topology_old(ports=all_except, fixed_ports=fixed_ports)
310+
else:
311+
p2p_topology = self._gen_p2p_topology(ports=all_except, fixed_ports=fixed_ports)
312+
288313
dest_p2p = destdir / f"p2p-topology-{node_name}.json"
289314
dest_p2p.write_text(f"{json.dumps(p2p_topology, indent=4)}\n")
290315

0 commit comments

Comments
 (0)