File tree Expand file tree Collapse file tree 2 files changed +27
-23
lines changed Expand file tree Collapse file tree 2 files changed +27
-23
lines changed Original file line number Diff line number Diff line change 99import signal
1010import sys
1111import tempfile
12+ import threading
13+ from time import sleep
1214from typing import Dict
1315
1416from kubernetes import client , config
@@ -100,6 +102,30 @@ def b64_to_hex(b64, reverse=False):
100102 else :
101103 return base64 .b64decode (b64 ).hex ()
102104
105+ def wait_for_tanks_connected (self ):
106+ def tank_connected (self , tank ):
107+ while True :
108+ peers = tank .getpeerinfo ()
109+ count = sum (
110+ 1
111+ for peer in peers
112+ if peer .get ("connection_type" ) == "manual" or peer .get ("addnode" ) is True
113+ )
114+ self .log .info (f"Tank { tank .tank } connected to { count } /{ tank .init_peers } peers" )
115+ if count >= tank .init_peers :
116+ break
117+ else :
118+ sleep (1 )
119+
120+ conn_threads = [
121+ threading .Thread (target = tank_connected , args = (self , tank )) for tank in self .nodes
122+ ]
123+ for thread in conn_threads :
124+ thread .start ()
125+
126+ all (thread .join () is None for thread in conn_threads )
127+ self .log .info ("Network connected" )
128+
103129 def handle_sigterm (self , signum , frame ):
104130 print ("SIGTERM received, stopping..." )
105131 self .shutdown ()
Original file line number Diff line number Diff line change @@ -20,29 +20,7 @@ def run_test(self):
2020 # L1 P2P
2121 ##
2222 self .log .info ("Waiting for L1 p2p network connections..." )
23-
24- def tank_connected (self , tank ):
25- while True :
26- peers = tank .getpeerinfo ()
27- count = sum (
28- 1
29- for peer in peers
30- if peer .get ("connection_type" ) == "manual" or peer .get ("addnode" ) is True
31- )
32- self .log .info (f"Tank { tank .tank } connected to { count } /{ tank .init_peers } peers" )
33- if count >= tank .init_peers :
34- break
35- else :
36- sleep (1 )
37-
38- conn_threads = [
39- threading .Thread (target = tank_connected , args = (self , tank )) for tank in self .nodes
40- ]
41- for thread in conn_threads :
42- thread .start ()
43-
44- all (thread .join () is None for thread in conn_threads )
45- self .log .info ("Network connected" )
23+ self .wait_for_tanks_connected ()
4624
4725 ##
4826 # MINER
You can’t perform that action at this time.
0 commit comments