Skip to content

Commit b6b9de0

Browse files
committed
server: move network_connected to Warnet class for scenario access
1 parent 229bd38 commit b6b9de0

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

src/cli/network.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ def status(network: str):
129129

130130
@network.command()
131131
@click.option("--network", default="warnet", show_default=True)
132-
@click.argument("threshold", type=int)
133132
def connected(network: str):
134133
"""
135134
Indicate whether the all of the edges in the gaph file are connected in <network>

src/scenarios/miner_std.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def add_options(self, parser):
3131
)
3232

3333
def run_test(self):
34+
while not self.warnet.network_connected():
35+
sleep(1)
36+
3437
current_miner = 0
3538

3639
while True:

src/warnet/server.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import traceback
1515
from datetime import datetime
1616
from io import BytesIO
17-
from json import loads
1817
from logging import StreamHandler
1918
from logging.handlers import RotatingFileHandler
2019
from pathlib import Path
@@ -570,24 +569,13 @@ def network_status(self, network: str = "warnet") -> list[dict]:
570569
self.logger.error(msg)
571570
raise ServerError(message=msg) from e
572571

573-
574572
def network_connected(self, network: str = "warnet") -> bool:
575573
"""
576-
Indicate whether the <threshold> of graph edges is connected in <network>
574+
Indicate whether all of the graph edges are connected in <network>
577575
"""
578576
try:
579577
wn = Warnet.from_network(network, self.backend)
580-
for tank in wn.tanks:
581-
peerinfo = loads(wn.container_interface.get_bitcoin_cli(tank, "getpeerinfo"))
582-
manuals = 0
583-
for peer in peerinfo:
584-
if peer["connection_type"] == "manual":
585-
manuals += 1
586-
# Even if more edges are specifed, bitcoind only allows
587-
# 8 manual outbound connections
588-
if min(8, len(tank.init_peers)) > manuals:
589-
return False
590-
return True
578+
return wn.network_connected()
591579
except Exception as e:
592580
self.logger.error(f"{e}")
593581
return False

src/warnet/warnet.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,16 @@ def export(self, subdir):
221221

222222
def wait_for_health(self):
223223
self.container_interface.wait_for_healthy_tanks(self)
224+
225+
def network_connected(self):
226+
for tank in self.tanks:
227+
peerinfo = json.loads(self.container_interface.get_bitcoin_cli(tank, "getpeerinfo"))
228+
manuals = 0
229+
for peer in peerinfo:
230+
if peer["connection_type"] == "manual":
231+
manuals += 1
232+
# Even if more edges are specifed, bitcoind only allows
233+
# 8 manual outbound connections
234+
if min(8, len(tank.init_peers)) > manuals:
235+
return False
236+
return True

test/scenarios_test.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@
1111
base.start_server()
1212
print(base.warcli(f"network start {graph_file_path}"))
1313
base.wait_for_all_tanks_status(target="running")
14-
base.wait_for_all_edges()
1514

1615
# Use rpc instead of warcli so we get raw JSON object
1716
scenarios = base.rpc("scenarios_available")
1817
assert len(scenarios) == 4
1918

20-
# Exponential backoff will repeat this command until it succeeds.
21-
# That's when we are ready for scenarios
22-
base.warcli("rpc 0 getblockcount")
23-
2419
# Start scenario
2520
base.warcli("scenarios run miner_std --allnodes --interval=1")
2621

0 commit comments

Comments
 (0)