Skip to content

Commit cf0bd39

Browse files
committed
injectpaymentionion: allow specification of actual amount which reaches destination.
This appears in listsendpays / listpays, and is useful information (if we know!). This doesn't fix old payments, but means that xpay can use this for new payments. Signed-off-by: Rusty Russell <[email protected]>
1 parent 6311a54 commit cf0bd39

File tree

9 files changed

+79
-52
lines changed

9 files changed

+79
-52
lines changed

.msggen.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,7 @@
18091809
"InjectpaymentonionRequest": {
18101810
"InjectPaymentOnion.amount_msat": 3,
18111811
"InjectPaymentOnion.cltv_expiry": 4,
1812+
"InjectPaymentOnion.destination_msat": 10,
18121813
"InjectPaymentOnion.groupid": 6,
18131814
"InjectPaymentOnion.invstring": 8,
18141815
"InjectPaymentOnion.label": 7,
@@ -7548,6 +7549,10 @@
75487549
"added": "v24.11",
75497550
"deprecated": null
75507551
},
7552+
"InjectPaymentOnion.destination_msat": {
7553+
"added": "v24.11.1",
7554+
"deprecated": null
7555+
},
75517556
"InjectPaymentOnion.groupid": {
75527557
"added": "v24.11",
75537558
"deprecated": null

cln-grpc/proto/node.proto

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-grpc/src/convert.rs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-rpc/src/model.rs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/msggen/msggen/schema.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16175,7 +16175,7 @@
1617516175
"amount_msat": {
1617616176
"type": "msat",
1617716177
"description": [
16178-
"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."
16178+
"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`."
1617916179
]
1618016180
},
1618116181
"cltv_expiry": {
@@ -16213,6 +16213,13 @@
1621316213
"description": [
1621416214
"`localinvreqid` is used by offers to link a payment attempt to a local `invoice_request` offer created by lightningd-invoicerequest(7)."
1621516215
]
16216+
},
16217+
"destination_msat": {
16218+
"type": "msat",
16219+
"added": "v24.11.1",
16220+
"description": [
16221+
"Amount that is actually delivered to the destination (i.e. `amount_msat` minus fees), for showing in listsendpays (confusingly, as `amount_msat`)."
16222+
]
1621616223
}
1621716224
}
1621816225
},

contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Lines changed: 36 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/schemas/lightning-injectpaymentonion.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"amount_msat": {
3434
"type": "msat",
3535
"description": [
36-
"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."
36+
"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`."
3737
]
3838
},
3939
"cltv_expiry": {
@@ -71,6 +71,13 @@
7171
"description": [
7272
"`localinvreqid` is used by offers to link a payment attempt to a local `invoice_request` offer created by lightningd-invoicerequest(7)."
7373
]
74+
},
75+
"destination_msat": {
76+
"type": "msat",
77+
"added": "v24.11.1",
78+
"description": [
79+
"Amount that is actually delivered to the destination (i.e. `amount_msat` minus fees), for showing in listsendpays (confusingly, as `amount_msat`)."
80+
]
7481
}
7582
}
7683
},

lightningd/pay.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,7 @@ static struct command_result *param_u64_nonzero(struct command *cmd,
17821782
static void register_payment_and_waiter(struct command *cmd,
17831783
const struct sha256 *payment_hash,
17841784
u64 partid, u64 groupid,
1785-
struct amount_msat msat,
1785+
struct amount_msat destination_msat,
17861786
struct amount_msat msat_sent,
17871787
struct amount_msat total_msat,
17881788
const char *label,
@@ -1799,7 +1799,7 @@ static void register_payment_and_waiter(struct command *cmd,
17991799
groupid,
18001800
PAYMENT_PENDING,
18011801
NULL,
1802-
msat,
1802+
destination_msat,
18031803
msat_sent,
18041804
total_msat,
18051805
NULL,
@@ -1829,7 +1829,7 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
18291829
struct lightningd *ld = cmd->ld;
18301830
const char *label, *invstring;
18311831
struct pubkey *blinding, *next_path_key;
1832-
struct amount_msat *msat;
1832+
struct amount_msat *destination_msat, *msat;
18331833
u32 *cltv;
18341834
u64 *partid, *groupid;
18351835
struct sha256 *local_invreq_id;
@@ -1857,12 +1857,13 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
18571857
p_opt("label", param_escaped_string, &label),
18581858
p_opt("invstring", param_invstring, &invstring),
18591859
p_opt("localinvreqid", param_sha256, &local_invreq_id),
1860+
p_opt_def("destination_msat", param_msat, &destination_msat, AMOUNT_MSAT(0)),
18601861
NULL))
18611862
return command_param_failed();
18621863

18631864
/* Safety check: reconcile this with previous attempts, check
1864-
* partid/groupid uniqueness: we don't know amount or total. */
1865-
ret = check_progress(cmd->ld, cmd, payment_hash, AMOUNT_MSAT(0),
1865+
* partid/groupid uniqueness: we don't know total. */
1866+
ret = check_progress(cmd->ld, cmd, payment_hash, *destination_msat,
18661867
AMOUNT_MSAT(0),
18671868
*partid, *groupid, NULL, &prev_payment);
18681869
if (ret)
@@ -1938,13 +1939,10 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
19381939
selfpay->groupid = *groupid;
19391940
selfpay->payment_hash = *payment_hash;
19401941

1941-
/* We actually *do* know msat delivered and total msat, but
1942-
* then check_progress will complain on the next part, because
1943-
* we don't know it then, so leave them 0 */
19441942
register_payment_and_waiter(cmd,
19451943
payment_hash,
19461944
*partid, *groupid,
1947-
AMOUNT_MSAT(0), *msat, AMOUNT_MSAT(0),
1945+
*destination_msat, *msat, AMOUNT_MSAT(0),
19481946
label, invstring, local_invreq_id,
19491947
&shared_secret);
19501948

@@ -2058,14 +2056,15 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
20582056
register_payment_and_waiter(cmd,
20592057
payment_hash,
20602058
*partid, *groupid,
2061-
AMOUNT_MSAT(0), *msat, AMOUNT_MSAT(0),
2059+
*destination_msat, *msat, AMOUNT_MSAT(0),
20622060
label, invstring, local_invreq_id,
20632061
&shared_secret);
20642062

2063+
/* If unknown, we set this equal (so accounting logs 0 fees) */
2064+
if (amount_msat_eq(*destination_msat, AMOUNT_MSAT(0)))
2065+
*destination_msat = *msat;
20652066
failmsg = send_htlc_out(tmpctx, next, *msat,
2066-
/* We set final_msat to the same, so fees == 0
2067-
* (in fact, we don't know!) */
2068-
*cltv, *msat,
2067+
*cltv, *destination_msat,
20692068
payment_hash,
20702069
next_path_key, *partid, *groupid,
20712070
serialize_onionpacket(tmpctx, rs->next),

tests/test_pay.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6114,6 +6114,7 @@ def test_injectpaymentonion_simple(node_factory, executor):
61146114
assert lsp['partid'] == 1
61156115
assert lsp['payment_hash'] == inv1['payment_hash']
61166116
assert lsp['status'] == 'complete'
6117+
assert 'amount_msat' not in lsp
61176118

61186119
# We FAIL on reattempt
61196120
with pytest.raises(RpcError, match="Already paid this invoice") as err:
@@ -6175,6 +6176,7 @@ def test_injectpaymentonion_mpp(node_factory, executor):
61756176
assert lsp['partid'] == 1 or lsp['partid'] == 2
61766177
assert lsp['payment_hash'] == inv2['payment_hash']
61776178
assert lsp['status'] == 'complete'
6179+
assert 'amount_msat' not in lsp
61786180
assert len(lsps) == 2
61796181

61806182

@@ -6198,14 +6200,16 @@ def test_injectpaymentonion_3hop(node_factory, executor):
61986200
amount_msat=1001,
61996201
cltv_expiry=blockheight + 18 + 6 + 6,
62006202
partid=1,
6201-
groupid=0)
6203+
groupid=0,
6204+
destination_msat=1000)
62026205
assert sha256(bytes.fromhex(ret['payment_preimage'])).hexdigest() == inv3['payment_hash']
62036206
assert only_one(l3.rpc.listinvoices("test_injectpaymentonion3")['invoices'])['status'] == 'paid'
62046207
lsp = only_one(l1.rpc.listsendpays(inv3['bolt11'])['payments'])
62056208
assert lsp['groupid'] == 0
62066209
assert lsp['partid'] == 1
62076210
assert lsp['payment_hash'] == inv3['payment_hash']
62086211
assert lsp['status'] == 'complete'
6212+
assert lsp['amount_msat'] == 1000
62096213

62106214

62116215
def test_injectpaymentonion_selfpay(node_factory, executor):

0 commit comments

Comments
 (0)