electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 83993768e5309c504ae6c419d40986d5e374b9d2
parent 5663e598637d5cf8aba6b2be8c2b3ccc609fd692
Author: ThomasV <thomasv@electrum.org>
Date:   Sat,  6 Mar 2021 00:26:55 +0100

trampoline: do not add node in trampoline hints if it already is
the last trampoline of the route

Diffstat:
Melectrum/tests/test_lnpeer.py | 2+-
Melectrum/trampoline.py | 17++++++++++++-----
2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/electrum/tests/test_lnpeer.py b/electrum/tests/test_lnpeer.py @@ -763,7 +763,7 @@ class TestPeer(ElectrumTestCase): graph.w_a.network.channel_db.stop() graph.w_a.network.channel_db = None # Note: first attempt will fail with insufficient trampoline fee - self._test_multipart_payment(graph, attempts=2) + self._test_multipart_payment(graph, attempts=3) @needs_test_with_all_chacha20_implementations def test_close(self): diff --git a/electrum/trampoline.py b/electrum/trampoline.py @@ -102,12 +102,11 @@ def create_trampoline_route( is_legacy = False if len(r_tags) > 0 and len(r_tags[0]) == 1: pubkey, scid, feebase, feerate, cltv = r_tags[0][0] - t_tag = pubkey, feebase, feerate, cltv + t_tags = [pubkey, feebase, feerate, cltv] else: - t_tag = None + t_tags = None elif len(t_tags) > 0: is_legacy = False - t_tag = t_tags[0] else: is_legacy = True @@ -154,8 +153,14 @@ def create_trampoline_route( route[-1].invoice_features = invoice_features route[-1].outgoing_node_id = invoice_pubkey else: - if t_tag: + last_trampoline = route[-1].end_node + for t_tag in t_tags: pubkey, feebase, feerate, cltv = t_tag + if pubkey == trampoline_node_id: + break + else: + random.shuffle(t_tags) + pubkey, feebase, feerate, cltv = t_tags[0] if route[-1].node_id != pubkey: route.append( TrampolineEdge( @@ -165,6 +170,7 @@ def create_trampoline_route( fee_proportional_millionths=feerate, cltv_expiry_delta=cltv, node_features=trampoline_features)) + # Final edge (not part of the route if payment is legacy, but eclair requires an encrypted blob) route.append( TrampolineEdge( @@ -266,4 +272,5 @@ def create_trampoline_route_and_onion( bucket_cltv_delta += trampoline_route[0].cltv_expiry_delta # trampoline fee for this very trampoline trampoline_fee = trampoline_route[0].fee_for_edge(amount_with_fees) - return trampoline_onion, trampoline_fee, amount_with_fees, bucket_cltv_delta + amount_with_fees += trampoline_fee + return trampoline_onion, amount_with_fees, bucket_cltv_delta