3
3
import os
4
4
import docker
5
5
import time
6
- from concurrent .futures import ThreadPoolExecutor
6
+ from concurrent .futures import ThreadPoolExecutor , wait
7
7
from docker .models .containers import Container
8
8
from datetime import datetime
9
9
import re
@@ -276,7 +276,10 @@ def ensure_layer2_ready(self) -> None:
276
276
nodes = self .config .nodes
277
277
if self .node_manager .newly_installed :
278
278
if self .network == "simnet" :
279
- self .lnd_cfheaders ["bitcoin" ] = CFHeaderState ()
279
+ if self .config .nodes ["lndbtc" ]["mode" ] == "native" :
280
+ self .lnd_cfheaders ["bitcoin" ] = CFHeaderState ()
281
+ if self .config .nodes ["lndltc" ]["mode" ] == "native" :
282
+ self .lnd_cfheaders ["litecoin" ] = CFHeaderState ()
280
283
self .lnd_cfheaders ["litecoin" ] = CFHeaderState ()
281
284
if "bitcoind" in nodes and nodes ["bitcoind" ]["mode" ] in ["neutrino" , "light" ]:
282
285
self .lnd_cfheaders ["bitcoin" ] = CFHeaderState ()
@@ -287,27 +290,18 @@ def ensure_layer2_ready(self) -> None:
287
290
print ("Syncing light clients:" )
288
291
self ._print_lnd_cfheaders (erase_last_line = False )
289
292
290
- with ThreadPoolExecutor (max_workers = 2 , thread_name_prefix = "LndReady" ) as executor :
291
- native_lndbtc = self .config .nodes ["lndbtc" ]["mode" ] == "native"
292
- native_lndltc = self .config .nodes ["lndltc" ]["mode" ] == "native"
293
-
294
- if native_lndbtc :
295
- f1 = executor .submit (self .ensure_lnd_ready , "bitcoin" )
293
+ with ThreadPoolExecutor (max_workers = len (self .lnd_cfheaders ), thread_name_prefix = "LndReady" ) as executor :
294
+ futs = {}
295
+ for chain in self .lnd_cfheaders :
296
+ futs [executor .submit (self .ensure_lnd_ready , chain )] = chain
296
297
297
- if native_lndltc :
298
- f2 = executor .submit (self .ensure_lnd_ready , "litecoin" )
298
+ done , not_done = wait (futs )
299
299
300
- if native_lndbtc :
301
- try :
302
- f1 .result ()
303
- except Exception as e :
304
- raise FatalError ("Failed to wait for lndbtc to be ready" ) from e
305
-
306
- if native_lndltc :
307
- try :
308
- f2 .result ()
309
- except Exception as e :
310
- raise FatalError ("Failed to wait for lndltc to be ready" ) from e
300
+ if len (not_done ) > 0 :
301
+ for f in not_done :
302
+ f .cancel ()
303
+ lnds = ", " .join ([futs [f ] for f in not_done ])
304
+ raise FatalError ("Failed to wait for {} to be ready" .format (lnds ))
311
305
312
306
if self .node_manager .newly_installed :
313
307
print ()
0 commit comments