URI: 
       tUse 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. - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 196b4c00a35b288f28885c0ceb8afdd5ffbd9a0f
   DIR parent 0491da2c662fdf74c1470acdb2bb856640780245
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Mon,  8 Mar 2021 18:49:52 +0100
       
       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.
       
       Diffstat:
         M electrum/lnpeer.py                  |       1 -
         M electrum/lnutil.py                  |      17 +++++++++--------
         M electrum/lnworker.py                |      15 ++++-----------
         M electrum/trampoline.py              |      26 +++++++++-----------------
       
       4 files changed, 22 insertions(+), 37 deletions(-)
       ---
   DIR diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py
       t@@ -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,
   DIR diff --git a/electrum/lnutil.py b/electrum/lnutil.py
       t@@ -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
       -
       -    # 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)
       +    OPTION_TRAMPOLINE_ROUTING_REQ = 1 << 24
       +    OPTION_TRAMPOLINE_ROUTING_OPT = 1 << 25
       +
       +    _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:
   DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py
       t@@ -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,
       t@@ -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:
       t@@ -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)
       t@@ -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,
       t@@ -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,
       t@@ -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,
       t@@ -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,
       t@@ -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)]
       t@@ -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,
       t@@ -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))
       t@@ -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]:
   DIR diff --git a/electrum/trampoline.py b/electrum/trampoline.py
       t@@ -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
       t@@ -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(
       t@@ -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,
       t@@ -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