Skip to content

Commit 65ef1c1

Browse files
committed
ln_init: various bug fixes for large networks
1 parent 6d466ef commit 65ef1c1

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

resources/scenarios/ln_framework/ln.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ def to_dict(self):
8989
def to_lnd_chanpolicy(self, capacity):
9090
# LND requires a 1% reserve
9191
reserve = ((capacity * 99) // 100) * 1000
92+
# "min htlc amount of 0 mSAT is below min htlc parameter of 1 mSAT"
93+
min_htlc = 1
9294
return {
9395
"time_lock_delta": self.cltv_expiry_delta,
94-
"min_htlc_msat": self.htlc_minimum_msat,
96+
"min_htlc_msat": max(self.htlc_minimum_msat, min_htlc),
9597
"base_fee_msat": self.fee_base_msat,
9698
"fee_rate_ppm": self.fee_proportional_millionths,
9799
"max_htlc_msat": min(self.htlc_maximum_msat, reserve),
@@ -357,8 +359,12 @@ def uri(self):
357359

358360
def connect(self, target_uri):
359361
pk, host = target_uri.split("@")
360-
res = self.post("/v1/peers", data={"addr": {"pubkey": pk, "host": host}})
361-
return json.loads(res)
362+
response = self.post("/v1/peers", data={"addr": {"pubkey": pk, "host": host}})
363+
res = json.loads(response)
364+
if "status" in res and "initiated" in res["status"]:
365+
return {}
366+
else:
367+
return res
362368

363369
def channel(self, pk, capacity, push_amt, fee_rate):
364370
b64_pk = self.hex_to_b64(pk)
@@ -372,6 +378,8 @@ def channel(self, pk, capacity, push_amt, fee_rate):
372378
},
373379
)
374380
res = json.loads(response)
381+
if "result" not in res:
382+
raise Exception(res)
375383
res["txid"] = self.b64_to_hex(
376384
res["result"]["chan_pending"]["txid"], reverse=True
377385
)

resources/scenarios/ln_init.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,9 @@ def open_channel(self, ch, fee_rate):
256256
src = self.lns[ch["source"]]
257257
tgt_uri = ln_uris[ch["target"]]
258258
tgt_pk, _ = tgt_uri.split("@")
259-
self.log.info(
260-
f"Sending channel open from {ch['source']} -> {ch['target']} with fee_rate={fee_rate}"
261-
)
259+
log = f" {ch['source']} -> {ch['target']}\n {ch['id']} fee: {fee_rate}"
262260
while True:
261+
self.log.info(f"Sending channel open:\n{log}")
263262
try:
264263
res = src.channel(
265264
pk=tgt_pk,
@@ -268,20 +267,11 @@ def open_channel(self, ch, fee_rate):
268267
fee_rate=fee_rate,
269268
)
270269
ch["txid"] = res["txid"]
271-
self.log.info(
272-
f"Channel open {ch['source']} -> {ch['target']}\n "
273-
+ f"outpoint={res['outpoint']}\n "
274-
+ f"expected channel id: {ch['id']}"
275-
)
270+
ch["outpoint"] = res["outpoint"]
271+
self.log.info(f"Channel open success:\n{log}\n outpoint: {res['outpoint']}")
276272
break
277273
except Exception as e:
278-
ch["txid"] = "N/A"
279-
self.log.info(
280-
"Couldn't open channel:\n "
281-
+ f"From {ch['source']} -> {ch['target']} fee_rate={fee_rate}\n "
282-
+ f"{e}\n"
283-
+ "Retrying in 5 seconds..."
284-
)
274+
self.log.info(f"Couldn't open channel:\n{log}\n {e}\n Retrying in 5 seconds...")
285275
sleep(5)
286276

287277
channels = sorted(ch_by_block[target_block], key=lambda ch: ch["id"]["index"])
@@ -301,6 +291,11 @@ def open_channel(self, ch, fee_rate):
301291
ch_threads.append(t)
302292

303293
all(thread.join() is None for thread in ch_threads)
294+
for ch in channels:
295+
if ch["outpoint"][-2:] != ":0":
296+
self.log.error(f"Channel open outpoint not tx output index 0\n {ch}")
297+
raise Exception("Channel determinism ruined, abort!")
298+
304299
self.log.info(f"Waiting for {len(channels)} channel opens in mempool...")
305300
self.wait_until(
306301
lambda channels=channels: self.nodes[0].getmempoolinfo()["size"] >= len(channels),
@@ -369,6 +364,7 @@ def update_policy(self, ln, txid_hex, policy, capacity):
369364
f" Failed updates: {res['failed_updates']}\n txid: {txid_hex}\n policy:{policy}\n retrying in 5 seconds..."
370365
)
371366
sleep(5)
367+
continue
372368
break
373369
except Exception as e:
374370
self.log.info(f"Couldn't update channel policy for {ln.name} because {e}, retrying in 5 seconds...")

0 commit comments

Comments
 (0)