Skip to content

Commit 3f2ad53

Browse files
committed
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 3e27e38 commit 3f2ad53

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

contrib/msggen/msggen/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16068,7 +16068,7 @@
1606816068
"amount_msat": {
1606916069
"type": "msat",
1607016070
"description": [
16071-
"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`."
16071+
"The amount in millisatoshis this node would receive from a peer before forwarding the payment to the next. Note: this is shown in listsendpays as `amount_sent_msat`."
1607216072
]
1607316073
},
1607416074
"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. Note: this is shown in listsendpays as `amount_sent_msat`."
3838
]
3939
},
4040
"cltv_expiry": {

lightningd/pay.c

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

19781978
/* Mark it pending now, though htlc_set_add might
19791979
* not resolve immediately */
19801980
fixme_ignore(command_still_pending(cmd));
1981-
htlc_set_add(cmd->ld, cmd->ld->log, *msat, *payload->total_msat,
1981+
htlc_set_add(cmd->ld, cmd->ld->log, payload->amt_to_forward, *payload->total_msat,
19821982
NULL, payment_hash, payload->payment_secret,
19831983
selfpay_mpp_fail, selfpay_mpp_succeeded,
19841984
selfpay);
@@ -2014,22 +2014,22 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
20142014
"Unknown peer %s",
20152015
fmt_node_id(tmpctx, &nid));
20162016

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

2024-
if (amount_msat_greater(*msat, next->htlc_maximum_msat)
2025-
|| amount_msat_less(*msat, next->htlc_minimum_msat)) {
2024+
if (amount_msat_greater(payload->amt_to_forward, next->htlc_maximum_msat)
2025+
|| amount_msat_less(payload->amt_to_forward, next->htlc_minimum_msat)) {
20262026
/* Are we in old-range grace-period? */
20272027
if (!timemono_before(time_mono(), next->old_feerate_timeout)
2028-
|| amount_msat_less(*msat, next->old_htlc_minimum_msat)
2029-
|| amount_msat_greater(*msat, next->old_htlc_maximum_msat)) {
2028+
|| amount_msat_less(payload->amt_to_forward, next->old_htlc_minimum_msat)
2029+
|| amount_msat_greater(payload->amt_to_forward, next->old_htlc_maximum_msat)) {
20302030
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
20312031
"Amount %s not in htlc min/max range %s-%s",
2032-
fmt_amount_msat(tmpctx, *msat),
2032+
fmt_amount_msat(tmpctx, payload->amt_to_forward),
20332033
fmt_amount_msat(tmpctx, next->htlc_minimum_msat),
20342034
fmt_amount_msat(tmpctx, next->htlc_maximum_msat));
20352035
}
@@ -2082,11 +2082,11 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
20822082
if (command_check_only(cmd))
20832083
return command_check_done(cmd);
20842084

2085-
failmsg = send_htlc_out(tmpctx, next, *msat,
2085+
failmsg = send_htlc_out(tmpctx, next, payload->amt_to_forward,
20862086
*cltv,
20872087
/* If unknown, we set this equal (so accounting logs 0 fees) */
20882088
amount_msat_eq(*destination_msat, AMOUNT_MSAT(0))
2089-
? *msat : *destination_msat,
2089+
? payload->amt_to_forward : *destination_msat,
20902090
payment_hash,
20912091
next_path_key, NULL, *partid, *groupid,
20922092
serialize_onionpacket(tmpctx, rs->next),
@@ -2101,7 +2101,7 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
21012101
register_payment_and_waiter(cmd,
21022102
payment_hash,
21032103
*partid, *groupid,
2104-
*destination_msat, *msat, AMOUNT_MSAT(0),
2104+
*destination_msat, payload->amt_to_forward, AMOUNT_MSAT(0),
21052105
label, invstring, local_invreq_id,
21062106
&shared_secret,
21072107
destination);

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-
@unittest.skip
10781077
def test_bolt12_fees(node_factory):
10791078
AMT_MSAT = 10000
10801079
FEES_MSAT = 5000

0 commit comments

Comments
 (0)