Use new value of option_trampoline_routing flag, add it to our invoices.
Keep supporting old value for Eclair/Phoenix. Do not add trampoline_routing_hints in invoices.
This commit is contained in:
@@ -1453,7 +1453,6 @@ class Peer(Logger):
|
||||
amount_to_pay=amt_to_forward,
|
||||
min_cltv_expiry=cltv_from_onion,
|
||||
r_tags=[],
|
||||
t_tags=[],
|
||||
invoice_features=invoice_features,
|
||||
fwd_trampoline_onion=next_trampoline_onion,
|
||||
fwd_trampoline_fee=trampoline_fee,
|
||||
|
||||
@@ -947,14 +947,15 @@ class LnFeatures(IntFlag):
|
||||
_ln_feature_contexts[OPTION_SUPPORT_LARGE_CHANNEL_OPT] = (LNFC.INIT | LNFC.NODE_ANN)
|
||||
_ln_feature_contexts[OPTION_SUPPORT_LARGE_CHANNEL_REQ] = (LNFC.INIT | LNFC.NODE_ANN)
|
||||
|
||||
OPTION_TRAMPOLINE_ROUTING_REQ = 1 << 50
|
||||
OPTION_TRAMPOLINE_ROUTING_OPT = 1 << 51
|
||||
OPTION_TRAMPOLINE_ROUTING_REQ = 1 << 24
|
||||
OPTION_TRAMPOLINE_ROUTING_OPT = 1 << 25
|
||||
|
||||
# We do not set trampoline_routing_opt in invoices, because the spec is not ready.
|
||||
# This ensures that current version of Phoenix can pay us
|
||||
# It also prevents Electrum from using t_tags from future implementations
|
||||
_ln_feature_contexts[OPTION_TRAMPOLINE_ROUTING_REQ] = (LNFC.INIT | LNFC.NODE_ANN) # | LNFC.INVOICE)
|
||||
_ln_feature_contexts[OPTION_TRAMPOLINE_ROUTING_OPT] = (LNFC.INIT | LNFC.NODE_ANN) # | LNFC.INVOICE)
|
||||
_ln_feature_contexts[OPTION_TRAMPOLINE_ROUTING_REQ] = (LNFC.INIT | LNFC.NODE_ANN | LNFC.INVOICE)
|
||||
_ln_feature_contexts[OPTION_TRAMPOLINE_ROUTING_OPT] = (LNFC.INIT | LNFC.NODE_ANN | LNFC.INVOICE)
|
||||
|
||||
# temporary
|
||||
OPTION_TRAMPOLINE_ROUTING_REQ_ECLAIR = 1 << 50
|
||||
OPTION_TRAMPOLINE_ROUTING_OPT_ECLAIR = 1 << 51
|
||||
|
||||
def validate_transitive_dependencies(self) -> bool:
|
||||
# for all even bit set, set corresponding odd bit:
|
||||
|
||||
@@ -961,7 +961,6 @@ class LNWallet(LNWorker):
|
||||
invoice_pubkey=decoded_invoice.pubkey.serialize(),
|
||||
min_cltv_expiry=decoded_invoice.get_min_final_cltv_expiry(),
|
||||
r_tags=decoded_invoice.get_routing_info('r'),
|
||||
t_tags=decoded_invoice.get_routing_info('t'),
|
||||
invoice_features=decoded_invoice.get_tag('9') or 0,
|
||||
trampoline_fee_level=0,
|
||||
use_two_trampolines=False,
|
||||
@@ -984,7 +983,6 @@ class LNWallet(LNWorker):
|
||||
invoice_pubkey = lnaddr.pubkey.serialize()
|
||||
invoice_features = LnFeatures(lnaddr.get_tag('9') or 0)
|
||||
r_tags = lnaddr.get_routing_info('r')
|
||||
t_tags = lnaddr.get_routing_info('t')
|
||||
amount_to_pay = lnaddr.get_amount_msat()
|
||||
status = self.get_payment_status(payment_hash)
|
||||
if status == PR_PAID:
|
||||
@@ -1006,7 +1004,6 @@ class LNWallet(LNWorker):
|
||||
amount_to_pay=amount_to_pay,
|
||||
min_cltv_expiry=min_cltv_expiry,
|
||||
r_tags=r_tags,
|
||||
t_tags=t_tags,
|
||||
invoice_features=invoice_features,
|
||||
attempts=attempts,
|
||||
full_path=full_path)
|
||||
@@ -1032,7 +1029,6 @@ class LNWallet(LNWorker):
|
||||
amount_to_pay: int, # in msat
|
||||
min_cltv_expiry: int,
|
||||
r_tags,
|
||||
t_tags,
|
||||
invoice_features: int,
|
||||
attempts: int = 1,
|
||||
full_path: LNPaymentPath = None,
|
||||
@@ -1065,7 +1061,6 @@ class LNWallet(LNWorker):
|
||||
invoice_pubkey=node_pubkey,
|
||||
min_cltv_expiry=min_cltv_expiry,
|
||||
r_tags=r_tags,
|
||||
t_tags=t_tags,
|
||||
invoice_features=invoice_features,
|
||||
full_path=full_path,
|
||||
payment_hash=payment_hash,
|
||||
@@ -1288,7 +1283,7 @@ class LNWallet(LNWorker):
|
||||
final_total_msat: int, # total payment amount final receiver will get
|
||||
invoice_pubkey,
|
||||
min_cltv_expiry,
|
||||
r_tags, t_tags,
|
||||
r_tags,
|
||||
invoice_features: int,
|
||||
payment_hash,
|
||||
payment_secret,
|
||||
@@ -1326,7 +1321,6 @@ class LNWallet(LNWorker):
|
||||
invoice_features=invoice_features,
|
||||
node_id=chan.node_id,
|
||||
r_tags=r_tags,
|
||||
t_tags=t_tags,
|
||||
payment_hash=payment_hash,
|
||||
payment_secret=payment_secret,
|
||||
local_height=local_height,
|
||||
@@ -1354,7 +1348,7 @@ class LNWallet(LNWorker):
|
||||
amount_msat=amount_msat,
|
||||
invoice_pubkey=invoice_pubkey,
|
||||
min_cltv_expiry=min_cltv_expiry,
|
||||
r_tags=r_tags, t_tags=t_tags,
|
||||
r_tags=r_tags,
|
||||
invoice_features=invoice_features,
|
||||
outgoing_channel=None, full_path=full_path)
|
||||
routes = [(route, amount_msat, final_total_msat, amount_msat, min_cltv_expiry, payment_secret, fwd_trampoline_onion)]
|
||||
@@ -1390,7 +1384,6 @@ class LNWallet(LNWorker):
|
||||
invoice_features=invoice_features,
|
||||
node_id=node_id,
|
||||
r_tags=r_tags,
|
||||
t_tags=t_tags,
|
||||
payment_hash=payment_hash,
|
||||
payment_secret=payment_secret,
|
||||
local_height=local_height,
|
||||
@@ -1429,7 +1422,7 @@ class LNWallet(LNWorker):
|
||||
amount_msat=part_amount_msat,
|
||||
invoice_pubkey=invoice_pubkey,
|
||||
min_cltv_expiry=min_cltv_expiry,
|
||||
r_tags=r_tags, t_tags=t_tags,
|
||||
r_tags=r_tags,
|
||||
invoice_features=invoice_features,
|
||||
outgoing_channel=channel, full_path=None)
|
||||
routes.append((route, part_amount_msat, final_total_msat, part_amount_msat, min_cltv_expiry, payment_secret, fwd_trampoline_onion))
|
||||
@@ -1446,7 +1439,7 @@ class LNWallet(LNWorker):
|
||||
amount_msat: int,
|
||||
invoice_pubkey: bytes,
|
||||
min_cltv_expiry: int,
|
||||
r_tags, t_tags,
|
||||
r_tags,
|
||||
invoice_features: int,
|
||||
outgoing_channel: Channel = None,
|
||||
full_path: Optional[LNPaymentPath]) -> Tuple[LNPaymentRoute, int]:
|
||||
|
||||
@@ -91,21 +91,13 @@ def create_trampoline_route(
|
||||
invoice_features:int,
|
||||
my_pubkey: bytes,
|
||||
trampoline_node_id,
|
||||
r_tags, t_tags,
|
||||
r_tags,
|
||||
trampoline_fee_level: int,
|
||||
use_two_trampolines: bool) -> LNPaymentRoute:
|
||||
|
||||
invoice_features = LnFeatures(invoice_features)
|
||||
# We do not set trampoline_routing_opt in our invoices, because the spec is not ready
|
||||
# Do not use t_tags if the flag is set, because we the format is not decided yet
|
||||
if invoice_features.supports(LnFeatures.OPTION_TRAMPOLINE_ROUTING_OPT):
|
||||
is_legacy = False
|
||||
if len(r_tags) > 0 and len(r_tags[0]) == 1:
|
||||
pubkey, scid, feebase, feerate, cltv = r_tags[0][0]
|
||||
t_tags = [pubkey, feebase, feerate, cltv]
|
||||
else:
|
||||
t_tags = None
|
||||
elif len(t_tags) > 0:
|
||||
if invoice_features.supports(LnFeatures.OPTION_TRAMPOLINE_ROUTING_OPT)\
|
||||
or invoice_features.supports(LnFeatures.OPTION_TRAMPOLINE_ROUTING_OPT_ECLAIR):
|
||||
is_legacy = False
|
||||
else:
|
||||
is_legacy = True
|
||||
@@ -154,13 +146,14 @@ def create_trampoline_route(
|
||||
route[-1].outgoing_node_id = invoice_pubkey
|
||||
else:
|
||||
last_trampoline = route[-1].end_node
|
||||
for t_tag in t_tags:
|
||||
pubkey, feebase, feerate, cltv = t_tag
|
||||
r_tags = [x for x in r_tags if len(x) == 1]
|
||||
random.shuffle(r_tags)
|
||||
for r_tag in r_tags:
|
||||
pubkey, scid, feebase, feerate, cltv = r_tag[0]
|
||||
if pubkey == trampoline_node_id:
|
||||
break
|
||||
else:
|
||||
random.shuffle(t_tags)
|
||||
pubkey, feebase, feerate, cltv = t_tags[0]
|
||||
pubkey, scid, feebase, feerate, cltv = r_tag[0]
|
||||
if route[-1].node_id != pubkey:
|
||||
route.append(
|
||||
TrampolineEdge(
|
||||
@@ -241,7 +234,7 @@ def create_trampoline_route_and_onion(
|
||||
invoice_features,
|
||||
my_pubkey: bytes,
|
||||
node_id,
|
||||
r_tags, t_tags,
|
||||
r_tags,
|
||||
payment_hash,
|
||||
payment_secret,
|
||||
local_height:int,
|
||||
@@ -256,7 +249,6 @@ def create_trampoline_route_and_onion(
|
||||
invoice_features=invoice_features,
|
||||
trampoline_node_id=node_id,
|
||||
r_tags=r_tags,
|
||||
t_tags=t_tags,
|
||||
trampoline_fee_level=trampoline_fee_level,
|
||||
use_two_trampolines=use_two_trampolines)
|
||||
# compute onion and fees
|
||||
|
||||
Reference in New Issue
Block a user