trampoline: fix off-by-one confusion of fees
The convention is that edges (start_node -> edge_node) store the policy/fees for the *start_node*. This is what the non-trampoline edges were already using (for a long time), but the trampoline ones were off-by-one (policy was for end_node), which was then worked around in multiple places, to correct for... i.e. I think because of all the workarounds, there was no actual bug, but it was just very confusing. Also note that the prior usage of trampoline edges would not work if we (sender) were not directly connected to a TF (trampoline-forwarder) but had extra edges in the route to even get to the first TF. Having the policy corresponding to the start_node of the edge would work even in that case.
This commit is contained in:
@@ -241,10 +241,6 @@ def calc_hops_data_for_payment(
|
||||
# payloads, backwards from last hop (but excluding the first edge):
|
||||
for edge_index in range(len(route) - 1, 0, -1):
|
||||
route_edge = route[edge_index]
|
||||
is_trampoline = route_edge.is_trampoline()
|
||||
if is_trampoline:
|
||||
amt += route_edge.fee_for_edge(amt)
|
||||
cltv_abs += route_edge.cltv_delta
|
||||
hop_payload = {
|
||||
"amt_to_forward": {"amt_to_forward": amt},
|
||||
"outgoing_cltv_value": {"outgoing_cltv_value": cltv_abs},
|
||||
@@ -252,9 +248,8 @@ def calc_hops_data_for_payment(
|
||||
}
|
||||
hops_data.append(
|
||||
OnionHopsDataSingle(payload=hop_payload))
|
||||
if not is_trampoline:
|
||||
amt += route_edge.fee_for_edge(amt)
|
||||
cltv_abs += route_edge.cltv_delta
|
||||
amt += route_edge.fee_for_edge(amt)
|
||||
cltv_abs += route_edge.cltv_delta
|
||||
hops_data.reverse()
|
||||
return hops_data, amt, cltv_abs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user