1
0

trampoline: do not add node in trampoline hints if it already is

the last trampoline of the route
This commit is contained in:
ThomasV
2021-03-06 00:26:55 +01:00
parent 5663e59863
commit 83993768e5
2 changed files with 13 additions and 6 deletions

View File

@@ -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):

View File

@@ -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