Skip to content

Commit 7ee162b

Browse files
Lagrang3rustyrussell
authored andcommitted
injectpayment_onion: fix fees for blinded paths
Changelog-Fixed: injectpayment_onion: fix fees for blinded paths, treat amount_msat as the incoming amount and not the forward amount. Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
1 parent c1274f6 commit 7ee162b

5 files changed

Lines changed: 14 additions & 15 deletions

File tree

contrib/msggen/msggen/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16124,7 +16124,7 @@
1612416124
"amount_msat": {
1612516125
"type": "msat",
1612616126
"description": [
16127-
"The amount for the first HTLC in millisatoshis. This is also the amount which will be forwarded to the first peer (if any) as we do not charge fees on our own payments. Note: this is shown in listsendpays as `amount_sent_msat`."
16127+
"The amount in millisatoshis this node would receive from a peer before forwarding the payment to the next."
1612816128
]
1612916129
},
1613016130
"cltv_expiry": {

doc/schemas/injectpaymentonion.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"amount_msat": {
3535
"type": "msat",
3636
"description": [
37-
"The amount for the first HTLC in millisatoshis. This is also the amount which will be forwarded to the first peer (if any) as we do not charge fees on our own payments. Note: this is shown in listsendpays as `amount_sent_msat`."
37+
"The amount in millisatoshis this node would receive from a peer before forwarding the payment to the next."
3838
]
3939
},
4040
"cltv_expiry": {

lightningd/pay.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,15 +1973,15 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
19731973
register_payment_and_waiter(cmd,
19741974
payment_hash,
19751975
*partid, *groupid,
1976-
*destination_msat, *msat, AMOUNT_MSAT(0),
1976+
*destination_msat, payload->amt_to_forward, AMOUNT_MSAT(0),
19771977
label, invstring, local_invreq_id,
19781978
&shared_secret,
19791979
destination);
19801980

19811981
/* Mark it pending now, though htlc_set_add might
19821982
* not resolve immediately */
19831983
fixme_ignore(command_still_pending(cmd));
1984-
htlc_set_add(cmd->ld, cmd->ld->log, *msat, *payload->total_msat,
1984+
htlc_set_add(cmd->ld, cmd->ld->log, payload->amt_to_forward, *payload->total_msat,
19851985
NULL, payment_hash, payload->payment_secret,
19861986
selfpay_mpp_fail, selfpay_mpp_succeeded,
19871987
selfpay);
@@ -2017,22 +2017,22 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
20172017
"Unknown peer %s",
20182018
fmt_node_id(tmpctx, &nid));
20192019

2020-
next = best_channel(cmd->ld, next_peer, *msat, NULL);
2020+
next = best_channel(cmd->ld, next_peer, payload->amt_to_forward, NULL);
20212021
if (!next)
20222022
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
20232023
"No available channel with peer %s",
20242024
fmt_node_id(tmpctx, &nid));
20252025
}
20262026

2027-
if (amount_msat_greater(*msat, next->htlc_maximum_msat)
2028-
|| amount_msat_less(*msat, next->htlc_minimum_msat)) {
2027+
if (amount_msat_greater(payload->amt_to_forward, next->htlc_maximum_msat)
2028+
|| amount_msat_less(payload->amt_to_forward, next->htlc_minimum_msat)) {
20292029
/* Are we in old-range grace-period? */
20302030
if (!timemono_before(time_mono(), next->old_feerate_timeout)
2031-
|| amount_msat_less(*msat, next->old_htlc_minimum_msat)
2032-
|| amount_msat_greater(*msat, next->old_htlc_maximum_msat)) {
2031+
|| amount_msat_less(payload->amt_to_forward, next->old_htlc_minimum_msat)
2032+
|| amount_msat_greater(payload->amt_to_forward, next->old_htlc_maximum_msat)) {
20332033
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
20342034
"Amount %s not in htlc min/max range %s-%s",
2035-
fmt_amount_msat(tmpctx, *msat),
2035+
fmt_amount_msat(tmpctx, payload->amt_to_forward),
20362036
fmt_amount_msat(tmpctx, next->htlc_minimum_msat),
20372037
fmt_amount_msat(tmpctx, next->htlc_maximum_msat));
20382038
}
@@ -2085,11 +2085,11 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
20852085
if (command_check_only(cmd))
20862086
return command_check_done(cmd);
20872087

2088-
failmsg = send_htlc_out(tmpctx, next, *msat,
2088+
failmsg = send_htlc_out(tmpctx, next, payload->amt_to_forward,
20892089
*cltv,
20902090
/* If unknown, we set this equal (so accounting logs 0 fees) */
20912091
amount_msat_eq(*destination_msat, AMOUNT_MSAT(0))
2092-
? *msat : *destination_msat,
2092+
? payload->amt_to_forward : *destination_msat,
20932093
payment_hash,
20942094
next_path_key, NULL, *partid, *groupid,
20952095
serialize_onionpacket(tmpctx, rs->next),
@@ -2104,7 +2104,7 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
21042104
register_payment_and_waiter(cmd,
21052105
payment_hash,
21062106
*partid, *groupid,
2107-
*destination_msat, *msat, AMOUNT_MSAT(0),
2107+
*destination_msat, payload->amt_to_forward, AMOUNT_MSAT(0),
21082108
label, invstring, local_invreq_id,
21092109
&shared_secret,
21102110
destination);

tests/test_pay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6360,7 +6360,7 @@ def test_injectpaymentonion_selfpay(node_factory, executor):
63606360
'payload': serialize_payload_final_tlv(333, 18, 1000, blockheight, inv5['payment_secret']).hex()}]
63616361
onion1 = l1.rpc.createonion(hops=hops1, assocdata=inv5['payment_hash'])
63626362
hops2 = [{'pubkey': l1.info['id'],
6363-
'payload': serialize_payload_final_tlv(666, 18, 1000, blockheight, inv5['payment_secret']).hex()}]
6363+
'payload': serialize_payload_final_tlv(667, 18, 1000, blockheight, inv5['payment_secret']).hex()}]
63646364
onion2 = l1.rpc.createonion(hops=hops2, assocdata=inv5['payment_hash'])
63656365

63666366
fut1 = executor.submit(l1.rpc.injectpaymentonion,

tests/test_xpay.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,6 @@ def mock_getblockhash(req):
10741074
fut.result(TIMEOUT)
10751075

10761076

1077-
@pytest.mark.xfail(strict=True)
10781077
def test_blinded_path_fees(node_factory):
10791078
"""Test that we don't send the amount+fees to our direct peer (we should
10801079
only send the required amount) when the sending node is the entry point in

0 commit comments

Comments
 (0)