Skip to content

Commit 681078b

Browse files
committed
sendpay: add payment_metadata argument.
And document the missing arguments. Signed-off-by: Rusty Russell <[email protected]>
1 parent d356625 commit 681078b

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

common/onion.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ u8 *onion_final_hop(const tal_t *ctx,
7171
struct amount_msat total_msat,
7272
const struct pubkey *blinding,
7373
const u8 *enctlv,
74-
const struct secret *payment_secret)
74+
const struct secret *payment_secret,
75+
const u8 *payment_metadata)
7576
{
7677
struct tlv_tlv_payload *tlv = tlv_tlv_payload_new(tmpctx);
7778
struct tlv_tlv_payload_payment_data tlv_pdata;
@@ -102,6 +103,7 @@ u8 *onion_final_hop(const tal_t *ctx,
102103
tlv_pdata.total_msat = total_msat.millisatoshis; /* Raw: TLV convert */
103104
tlv->payment_data = &tlv_pdata;
104105
}
106+
tlv->payment_metadata = cast_const(u8 *, payment_metadata);
105107
#if EXPERIMENTAL_FEATURES
106108
tlv->blinding_point = cast_const(struct pubkey *, blinding);
107109
tlv->encrypted_recipient_data = cast_const(u8 *, enctlv);

common/onion.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ u8 *onion_nonfinal_hop(const tal_t *ctx,
2929
const struct pubkey *blinding,
3030
const u8 *enctlv);
3131

32-
/* Note that this can fail if we supply payment_secret and !use_tlv! */
32+
/* Note that this can fail if we supply payment_secret or payment_metadata and !use_tlv! */
3333
u8 *onion_final_hop(const tal_t *ctx,
3434
struct amount_msat forward,
3535
u32 outgoing_cltv,
3636
struct amount_msat total_msat,
3737
const struct pubkey *blinding,
3838
const u8 *enctlv,
39-
const struct secret *payment_secret);
39+
const struct secret *payment_secret,
40+
const u8 *payment_metadata);
4041

4142
/**
4243
* onion_payload_length: measure payload length in decrypted onion.

contrib/pyln-client/pyln/client/lightning.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ def plugin_rescan(self):
11261126
}
11271127
return self.call("plugin", payload)
11281128

1129-
def sendpay(self, route, payment_hash, label=None, msatoshi=None, bolt11=None, payment_secret=None, partid=None, groupid=None):
1129+
def sendpay(self, route, payment_hash, label=None, msatoshi=None, bolt11=None, payment_secret=None, partid=None, groupid=None, payment_metadata=None):
11301130
"""
11311131
Send along {route} in return for preimage of {payment_hash}.
11321132
"""
@@ -1139,6 +1139,7 @@ def sendpay(self, route, payment_hash, label=None, msatoshi=None, bolt11=None, p
11391139
"payment_secret": payment_secret,
11401140
"partid": partid,
11411141
"groupid": groupid,
1142+
"payment_metadata": payment_metadata,
11421143
}
11431144
return self.call("sendpay", payload)
11441145

devtools/onion.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static void do_generate(int argc, char **argv,
8080
take(onion_final_hop(NULL,
8181
amt, i, amt,
8282
NULL, NULL,
83-
NULL)));
83+
NULL, NULL)));
8484
else
8585
sphinx_add_hop(sp, &path[i],
8686
take(onion_nonfinal_hop(NULL,

doc/lightning-sendpay.7.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ SYNOPSIS
55
--------
66

77
**sendpay** *route* *payment\_hash* [*label*] [*msatoshi*]
8-
[*bolt11*] [*payment_secret*] [*partid*]
8+
[*bolt11*] [*payment_secret*] [*partid*] [*localofferid*] [*groupid*] [*payment_metadata*]
99

1010
DESCRIPTION
1111
-----------
@@ -44,6 +44,16 @@ partial payments with the same *payment_hash*. The *msatoshi* amount
4444
*payment_hash* must be equal, and **sendpay** will fail if there are
4545
already *msatoshi* worth of payments pending.
4646

47+
The *localofferid* value indicates that this payment is being made for a local
48+
send_invoice offer: this ensures that we only send a payment for a single-use
49+
offer once.
50+
51+
*groupid* allows you to attach a number which appears in **listsendpays** so
52+
payments can be identified as part of a logical group. The *pay* plugin uses
53+
this to identify one attempt at a MPP payment, for example.
54+
55+
*payment_metadata* is placed in the final onion hop TLV.
56+
4757
Once a payment has succeeded, calls to **sendpay** with the same
4858
*payment\_hash* but a different *msatoshi* or destination will fail;
4959
this prevents accidental multiple payments. Calls to **sendpay** with
@@ -94,6 +104,7 @@ The following error codes may occur:
94104
will be routing failure object.
95105
- 204: Failure along route; retry a different route. The *data* field
96106
of the error will be routing failure object.
107+
- 212: *localofferid* refers to an invalid, or used, local offer.
97108

98109
A routing failure object has the fields below:
99110
- *erring\_index*. The index of the node along the route that reported

lightningd/pay.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,8 @@ send_payment(struct lightningd *ld,
11221122
const char *label TAKES,
11231123
const char *invstring TAKES,
11241124
const struct sha256 *local_offer_id,
1125-
const struct secret *payment_secret)
1125+
const struct secret *payment_secret,
1126+
const u8 *payment_metadata)
11261127
{
11271128
unsigned int base_expiry;
11281129
struct onionpacket *packet;
@@ -1174,7 +1175,7 @@ send_payment(struct lightningd *ld,
11741175
route[i].amount,
11751176
base_expiry + route[i].delay,
11761177
total_msat, route[i].blinding, route[i].enctlv,
1177-
payment_secret);
1178+
payment_secret, payment_metadata);
11781179
if (!onion) {
11791180
return command_fail(cmd, PAY_DESTINATION_PERM_FAIL,
11801181
"Destination does not support"
@@ -1422,7 +1423,8 @@ static struct command_result *json_sendpay(struct command *cmd,
14221423
const char *invstring, *label;
14231424
u64 *partid, *group;
14241425
struct secret *payment_secret;
1425-
struct sha256 *local_offer_id = NULL;
1426+
struct sha256 *local_offer_id;
1427+
u8 *payment_metadata;
14261428

14271429
/* For generating help, give new-style. */
14281430
if (!param(cmd, buffer, params,
@@ -1436,6 +1438,7 @@ static struct command_result *json_sendpay(struct command *cmd,
14361438
p_opt_def("partid", param_u64, &partid, 0),
14371439
p_opt("localofferid", param_sha256, &local_offer_id),
14381440
p_opt("groupid", param_u64, &group),
1441+
p_opt("payment_metadata", param_bin_from_hex, &payment_metadata),
14391442
NULL))
14401443
return command_param_failed();
14411444

@@ -1485,7 +1488,8 @@ static struct command_result *json_sendpay(struct command *cmd,
14851488
route,
14861489
final_amount,
14871490
msat ? *msat : final_amount,
1488-
label, invstring, local_offer_id, payment_secret);
1491+
label, invstring, local_offer_id,
1492+
payment_secret, payment_metadata);
14891493
}
14901494

14911495
static const struct json_command sendpay_command = {

0 commit comments

Comments
 (0)