Skip to content

Commit 0203931

Browse files
committed
try/catch getpeerinfo in connected()
1 parent afda17c commit 0203931

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/warnet/network.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,22 @@ def _connected(end="\n"):
6262
tanks = get_mission("tank")
6363
for tank in tanks:
6464
# Get actual
65-
peerinfo = json.loads(_rpc(tank.metadata.name, "getpeerinfo", ""))
66-
actual = 0
67-
for peer in peerinfo:
68-
if is_connection_manual(peer):
69-
actual += 1
70-
expected = int(tank.metadata.annotations["init_peers"])
71-
print(f"Tank {tank.metadata.name} peers expected: {expected}, actual: {actual}", end=end)
72-
# Even if more edges are specified, bitcoind only allows
73-
# 8 manual outbound connections
74-
if min(8, expected) > actual:
75-
print("\nNetwork not connected")
65+
try:
66+
peerinfo = json.loads(_rpc(tank.metadata.name, "getpeerinfo", ""))
67+
actual = 0
68+
for peer in peerinfo:
69+
if is_connection_manual(peer):
70+
actual += 1
71+
expected = int(tank.metadata.annotations["init_peers"])
72+
print(
73+
f"Tank {tank.metadata.name} peers expected: {expected}, actual: {actual}", end=end
74+
)
75+
# Even if more edges are specified, bitcoind only allows
76+
# 8 manual outbound connections
77+
if min(8, expected) > actual:
78+
print("\nNetwork not connected")
79+
return False
80+
except Exception:
7681
return False
7782
print("Network connected ")
7883
return True

0 commit comments

Comments
 (0)