trampoline MPP: fix total_msat in trampoline onion, and bucketing
This commit is contained in:
@@ -1145,7 +1145,10 @@ class LNWallet(LNWorker):
|
|||||||
|
|
||||||
key = (payment_hash, short_channel_id, htlc.htlc_id)
|
key = (payment_hash, short_channel_id, htlc.htlc_id)
|
||||||
self.sent_htlcs_routes[key] = route, payment_secret, amount_msat, total_msat
|
self.sent_htlcs_routes[key] = route, payment_secret, amount_msat, total_msat
|
||||||
self.sent_buckets[payment_secret] = total_msat
|
# if we sent MPP to a trampoline, add item to sent_buckets
|
||||||
|
if not self.channel_db and amount_msat != total_msat:
|
||||||
|
if payment_secret not in self.sent_buckets:
|
||||||
|
self.sent_buckets[payment_secret] = total_msat
|
||||||
util.trigger_callback('htlc_added', chan, htlc, SENT)
|
util.trigger_callback('htlc_added', chan, htlc, SENT)
|
||||||
|
|
||||||
def handle_error_code_from_failed_htlc(self, htlc_log):
|
def handle_error_code_from_failed_htlc(self, htlc_log):
|
||||||
@@ -1299,7 +1302,6 @@ class LNWallet(LNWorker):
|
|||||||
payment_hash,
|
payment_hash,
|
||||||
payment_secret,
|
payment_secret,
|
||||||
full_path: LNPaymentPath = None) -> Sequence[Tuple[LNPaymentRoute, int]]:
|
full_path: LNPaymentPath = None) -> Sequence[Tuple[LNPaymentRoute, int]]:
|
||||||
# FIXME trampoline case broken if amount_msat != final_total_msat
|
|
||||||
|
|
||||||
"""Creates multiple routes for splitting a payment over the available
|
"""Creates multiple routes for splitting a payment over the available
|
||||||
private channels.
|
private channels.
|
||||||
@@ -1323,7 +1325,7 @@ class LNWallet(LNWorker):
|
|||||||
continue
|
continue
|
||||||
trampoline_onion, trampoline_fee, amount_with_fees, cltv_delta = create_trampoline_route_and_onion(
|
trampoline_onion, trampoline_fee, amount_with_fees, cltv_delta = create_trampoline_route_and_onion(
|
||||||
amount_msat=amount_msat,
|
amount_msat=amount_msat,
|
||||||
bucket_amount_msat=amount_msat,
|
total_msat=final_total_msat,
|
||||||
min_cltv_expiry=min_cltv_expiry,
|
min_cltv_expiry=min_cltv_expiry,
|
||||||
my_pubkey=self.node_keypair.pubkey,
|
my_pubkey=self.node_keypair.pubkey,
|
||||||
invoice_pubkey=invoice_pubkey,
|
invoice_pubkey=invoice_pubkey,
|
||||||
@@ -1387,8 +1389,8 @@ class LNWallet(LNWorker):
|
|||||||
for node_id, bucket in buckets.items():
|
for node_id, bucket in buckets.items():
|
||||||
bucket_amount_msat = sum([x[1] for x in bucket])
|
bucket_amount_msat = sum([x[1] for x in bucket])
|
||||||
trampoline_onion, trampoline_fee, bucket_amount_with_fees, bucket_cltv_delta = create_trampoline_route_and_onion(
|
trampoline_onion, trampoline_fee, bucket_amount_with_fees, bucket_cltv_delta = create_trampoline_route_and_onion(
|
||||||
amount_msat=amount_msat,
|
amount_msat=bucket_amount_msat,
|
||||||
bucket_amount_msat=bucket_amount_msat,
|
total_msat=final_total_msat,
|
||||||
min_cltv_expiry=min_cltv_expiry,
|
min_cltv_expiry=min_cltv_expiry,
|
||||||
my_pubkey=self.node_keypair.pubkey,
|
my_pubkey=self.node_keypair.pubkey,
|
||||||
invoice_pubkey=invoice_pubkey,
|
invoice_pubkey=invoice_pubkey,
|
||||||
@@ -1707,13 +1709,14 @@ class LNWallet(LNWorker):
|
|||||||
sender_idx = None
|
sender_idx = None
|
||||||
self.logger.info(f"htlc_failed {failure_message}")
|
self.logger.info(f"htlc_failed {failure_message}")
|
||||||
|
|
||||||
# FIXME: maybe only check this bucketing stuff if not using trampoline?
|
# check sent_buckets if we use trampoline
|
||||||
# if payment_secret in self.sent_buckets:
|
if self.channel_db is None and payment_secret in self.sent_buckets:
|
||||||
# self.sent_buckets[payment_secret] -= amount_msat
|
self.sent_buckets[payment_secret] -= amount_msat
|
||||||
# if self.sent_buckets[payment_secret] > 0:
|
if self.sent_buckets[payment_secret] > 0:
|
||||||
# return
|
return
|
||||||
# else:
|
else:
|
||||||
# amount_msat = bucket_msat
|
amount_msat = bucket_msat
|
||||||
|
|
||||||
htlc_log = HtlcLog(
|
htlc_log = HtlcLog(
|
||||||
success=False,
|
success=False,
|
||||||
route=route,
|
route=route,
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ def encode_routing_info(r_tags):
|
|||||||
def create_trampoline_route(
|
def create_trampoline_route(
|
||||||
*,
|
*,
|
||||||
amount_msat:int,
|
amount_msat:int,
|
||||||
bucket_amount_msat:int,
|
|
||||||
min_cltv_expiry:int,
|
min_cltv_expiry:int,
|
||||||
invoice_pubkey:bytes,
|
invoice_pubkey:bytes,
|
||||||
invoice_features:int,
|
invoice_features:int,
|
||||||
@@ -161,7 +160,7 @@ def create_trampoline_route(
|
|||||||
return route
|
return route
|
||||||
|
|
||||||
|
|
||||||
def create_trampoline_onion(route, amount_msat, final_cltv, total_msat, payment_hash, payment_secret):
|
def create_trampoline_onion(*, route, amount_msat, final_cltv, total_msat, payment_hash, payment_secret):
|
||||||
# all edges are trampoline
|
# all edges are trampoline
|
||||||
hops_data, amount_msat, cltv = calc_hops_data_for_payment(
|
hops_data, amount_msat, cltv = calc_hops_data_for_payment(
|
||||||
route,
|
route,
|
||||||
@@ -196,7 +195,7 @@ def create_trampoline_onion(route, amount_msat, final_cltv, total_msat, payment_
|
|||||||
def create_trampoline_route_and_onion(
|
def create_trampoline_route_and_onion(
|
||||||
*,
|
*,
|
||||||
amount_msat,
|
amount_msat,
|
||||||
bucket_amount_msat,
|
total_msat,
|
||||||
min_cltv_expiry,
|
min_cltv_expiry,
|
||||||
invoice_pubkey,
|
invoice_pubkey,
|
||||||
invoice_features,
|
invoice_features,
|
||||||
@@ -211,7 +210,6 @@ def create_trampoline_route_and_onion(
|
|||||||
# create route for the trampoline_onion
|
# create route for the trampoline_onion
|
||||||
trampoline_route = create_trampoline_route(
|
trampoline_route = create_trampoline_route(
|
||||||
amount_msat=amount_msat,
|
amount_msat=amount_msat,
|
||||||
bucket_amount_msat=bucket_amount_msat,
|
|
||||||
min_cltv_expiry=min_cltv_expiry,
|
min_cltv_expiry=min_cltv_expiry,
|
||||||
my_pubkey=my_pubkey,
|
my_pubkey=my_pubkey,
|
||||||
invoice_pubkey=invoice_pubkey,
|
invoice_pubkey=invoice_pubkey,
|
||||||
@@ -223,15 +221,15 @@ def create_trampoline_route_and_onion(
|
|||||||
trampoline2_list=trampoline2_list)
|
trampoline2_list=trampoline2_list)
|
||||||
# compute onion and fees
|
# compute onion and fees
|
||||||
final_cltv = local_height + min_cltv_expiry
|
final_cltv = local_height + min_cltv_expiry
|
||||||
trampoline_onion, bucket_amount_with_fees, bucket_cltv = create_trampoline_onion(
|
trampoline_onion, amount_with_fees, bucket_cltv = create_trampoline_onion(
|
||||||
trampoline_route,
|
route=trampoline_route,
|
||||||
bucket_amount_msat,
|
amount_msat=amount_msat,
|
||||||
final_cltv,
|
final_cltv=final_cltv,
|
||||||
amount_msat,
|
total_msat=total_msat,
|
||||||
payment_hash,
|
payment_hash=payment_hash,
|
||||||
payment_secret)
|
payment_secret=payment_secret)
|
||||||
bucket_cltv_delta = bucket_cltv - local_height
|
bucket_cltv_delta = bucket_cltv - local_height
|
||||||
bucket_cltv_delta += trampoline_route[0].cltv_expiry_delta
|
bucket_cltv_delta += trampoline_route[0].cltv_expiry_delta
|
||||||
# trampoline fee for this very trampoline
|
# trampoline fee for this very trampoline
|
||||||
trampoline_fee = trampoline_route[0].fee_for_edge(bucket_amount_with_fees)
|
trampoline_fee = trampoline_route[0].fee_for_edge(amount_with_fees)
|
||||||
return trampoline_onion, trampoline_fee, bucket_amount_with_fees, bucket_cltv_delta
|
return trampoline_onion, trampoline_fee, amount_with_fees, bucket_cltv_delta
|
||||||
|
|||||||
Reference in New Issue
Block a user