Trampoline: if possible, do not add second trampoline for e2e payments.
This should fix #7967
This commit is contained in:
@@ -97,9 +97,8 @@ def encode_routing_info(r_tags):
|
|||||||
return result.tobytes()
|
return result.tobytes()
|
||||||
|
|
||||||
|
|
||||||
def is_legacy_relay(invoice_features, r_tags) -> Tuple[bool, Optional[bytes]]:
|
def is_legacy_relay(invoice_features, r_tags) -> Tuple[bool, List[bytes]]:
|
||||||
"""Returns if we deal with a legacy payment and gives back the possible last
|
"""Returns if we deal with a legacy payment and the list of trampoline pubkeys in the invoice.
|
||||||
trampoline pubkey.
|
|
||||||
"""
|
"""
|
||||||
invoice_features = LnFeatures(invoice_features)
|
invoice_features = LnFeatures(invoice_features)
|
||||||
# trampoline-supporting wallets:
|
# trampoline-supporting wallets:
|
||||||
@@ -113,7 +112,7 @@ def is_legacy_relay(invoice_features, r_tags) -> Tuple[bool, Optional[bytes]]:
|
|||||||
# Any trampoline node should be able to figure out a path to the receiver and
|
# Any trampoline node should be able to figure out a path to the receiver and
|
||||||
# we can use an e2e payment.
|
# we can use an e2e payment.
|
||||||
if not r_tags:
|
if not r_tags:
|
||||||
return False, None
|
return False, []
|
||||||
else:
|
else:
|
||||||
# - We choose one routing hint at random, and
|
# - We choose one routing hint at random, and
|
||||||
# use end-to-end trampoline if that node is a trampoline-forwarder (TF).
|
# use end-to-end trampoline if that node is a trampoline-forwarder (TF).
|
||||||
@@ -123,12 +122,11 @@ def is_legacy_relay(invoice_features, r_tags) -> Tuple[bool, Optional[bytes]]:
|
|||||||
# endpoints connected to T1 and T2, and sender only has send-capacity with T1, while
|
# endpoints connected to T1 and T2, and sender only has send-capacity with T1, while
|
||||||
# recipient only has recv-capacity with T2.
|
# recipient only has recv-capacity with T2.
|
||||||
singlehop_r_tags = [x for x in r_tags if len(x) == 1]
|
singlehop_r_tags = [x for x in r_tags if len(x) == 1]
|
||||||
forwarder_pubkey = random.choice(singlehop_r_tags)[0][0]
|
invoice_trampolines = [x[0][0] for x in singlehop_r_tags if is_hardcoded_trampoline(x[0][0])]
|
||||||
if is_hardcoded_trampoline(forwarder_pubkey):
|
return False, invoice_trampolines
|
||||||
return False, forwarder_pubkey
|
|
||||||
# if trampoline receiving is not supported or the forwarder is not known as a trampoline,
|
# if trampoline receiving is not supported or the forwarder is not known as a trampoline,
|
||||||
# we send a legacy payment
|
# we send a legacy payment
|
||||||
return True, None
|
return True, []
|
||||||
|
|
||||||
|
|
||||||
def trampoline_policy(
|
def trampoline_policy(
|
||||||
@@ -179,7 +177,7 @@ def create_trampoline_route(
|
|||||||
use_two_trampolines: bool
|
use_two_trampolines: bool
|
||||||
) -> LNPaymentRoute:
|
) -> LNPaymentRoute:
|
||||||
# we decide whether to convert to a legacy payment
|
# we decide whether to convert to a legacy payment
|
||||||
is_legacy, second_trampoline_pubkey = is_legacy_relay(invoice_features, r_tags)
|
is_legacy, invoice_trampolines = is_legacy_relay(invoice_features, r_tags)
|
||||||
|
|
||||||
# we build a route of trampoline hops and extend the route list in place
|
# we build a route of trampoline hops and extend the route list in place
|
||||||
route = []
|
route = []
|
||||||
@@ -202,7 +200,8 @@ def create_trampoline_route(
|
|||||||
route[-1].invoice_features = invoice_features
|
route[-1].invoice_features = invoice_features
|
||||||
route[-1].outgoing_node_id = invoice_pubkey
|
route[-1].outgoing_node_id = invoice_pubkey
|
||||||
else:
|
else:
|
||||||
if second_trampoline_pubkey and trampoline_node_id != second_trampoline_pubkey:
|
if invoice_trampolines and trampoline_node_id not in invoice_trampolines:
|
||||||
|
second_trampoline_pubkey = random.choice(invoice_trampolines)
|
||||||
extend_trampoline_route(route, trampoline_node_id, second_trampoline_pubkey, trampoline_fee_level)
|
extend_trampoline_route(route, trampoline_node_id, second_trampoline_pubkey, trampoline_fee_level)
|
||||||
|
|
||||||
# final edge (not part of the route if payment is legacy, but eclair requires an encrypted blob)
|
# final edge (not part of the route if payment is legacy, but eclair requires an encrypted blob)
|
||||||
|
|||||||
Reference in New Issue
Block a user