Skip to content

Commit a6fc662

Browse files
committed
Fix wait for gossip loop
Remove all unnecessary thread sleeps
1 parent 9fdd5f8 commit a6fc662

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

resources/scenarios/commander.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def tank_connected(self, tank):
144144
if count >= tank.init_peers:
145145
break
146146
else:
147-
sleep(1)
147+
sleep(5)
148148

149149
conn_threads = [
150150
threading.Thread(target=tank_connected, args=(self, tank)) for tank in self.nodes

resources/scenarios/ln_init.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ def connect_ln(self, pair):
184184
threading.Thread(target=connect_ln, args=(self, pair)) for pair in connections
185185
]
186186
for thread in p2p_threads:
187-
sleep(1)
188187
thread.start()
189188

190189
all(thread.join(timeout=THREAD_JOIN_TIMEOUT) is None for thread in p2p_threads)
@@ -258,7 +257,6 @@ def open_channel(self, ch, fee_rate):
258257
assert index == ch["id"]["index"], "Channel ID indexes are not consecutive"
259258
assert fee_rate >= 1, "Too many TXs in block, out of fee range"
260259
t = threading.Thread(target=open_channel, args=(self, ch, fee_rate))
261-
sleep(2)
262260
t.start()
263261
ch_threads.append(t)
264262

@@ -288,20 +286,25 @@ def open_channel(self, ch, fee_rate):
288286
def ln_all_chs(self, ln):
289287
expected = len(self.channels)
290288
attempts=0
291-
max_tries=5
292-
while len(ln.graph()["edges"]) != expected and attempts < max_tries:
289+
actual = 0
290+
while actual != expected:
291+
actual = len(ln.graph()["edges"])
292+
if attempts > 10:
293+
break
293294
attempts+=1
294-
sleep(1)
295-
self.log.info(f"LN {ln.name} has graph with all {expected} channels")
295+
sleep(5)
296+
if actual == expected:
297+
self.log.info(f"LN {ln.name} has graph with all {expected} channels")
298+
else:
299+
self.log.error(f"LN {ln.name} graph is INCOMPLETE - {actual} of {expected} channels")
296300

297301
ch_ann_threads = [
298302
threading.Thread(target=ln_all_chs, args=(self, ln)) for ln in ln_nodes
299303
]
300304
for thread in ch_ann_threads:
301-
sleep(1)
302305
thread.start()
303306

304-
all(thread.join(timeout=THREAD_JOIN_TIMEOUT) is None for thread in ch_ann_threads)
307+
all(thread.join(timeout=THREAD_JOIN_TIMEOUT*2) is None for thread in ch_ann_threads)
305308
self.log.info("All LN nodes have complete graph")
306309

307310
##
@@ -359,14 +362,15 @@ def matching_graph(self, expected, ln):
359362
while not done:
360363
actual = ln.graph()["edges"]
361364
self.log.debug(f"LN {ln.name} channel graph edges: {actual}")
362-
assert (len(expected) == len(actual),f"Expected edges {expected}, actual edges {actual}")
363-
if len(actual) > 0: done = True
365+
if len(actual) > 0:
366+
done = True
367+
assert len(expected) == len(actual), f"Expected edges {len(expected)}, actual edges {len(actual)}\n{actual}"
364368
for i, actual_ch in enumerate(actual):
365369
expected_ch = expected[i]
366370
capacity = expected_ch["capacity"]
367371
# We assert this because it isn't updated as part of policy.
368372
# If this fails we have a bigger issue
369-
assert int(actual_ch["capacity"]) == capacity, f"LN {ln.name} graph capacity mismatch:\n actual: {actual_ch}\n expected: {expected_ch}"
373+
assert int(actual_ch["capacity"]) == capacity, f"LN {ln.name} graph capacity mismatch:\n actual: {actual_ch["capacity"]}\n expected: {capacity}"
370374

371375
# Policies were not defined in network.yaml
372376
if "source_policy" not in expected_ch or "target_policy" not in expected_ch:

0 commit comments

Comments
 (0)