Skip to content

Commit

Permalink
keysend: allow extratlvs parameter, even in non-experimental mode.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
Changelog-Added: JSON-RPC: `keysend` now has `extratlvs` option in non-EXPERIMENTAL builds.
  • Loading branch information
rustyrussell committed Sep 21, 2022
1 parent bc0acf4 commit fc016df
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
4 changes: 3 additions & 1 deletion doc/lightning-keysend.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lightning-keysend -- Send funds to a node without an invoice
SYNOPSIS
--------

**keysend** *destination* *msatoshi* [*label*] [*maxfeepercent*] [*retry\_for*] [*maxdelay*] [*exemptfee*]
**keysend** *destination* *msatoshi* [*label*] [*maxfeepercent*] [*retry\_for*] [*maxdelay*] [*exemptfee*] [*extratlvs*]

DESCRIPTION
-----------
Expand Down Expand Up @@ -36,6 +36,8 @@ Unlike lightning-pay(7), issuing the same `keysend` commands multiple times will
Until *retry_for* seconds passes (default: 60), the command will keep finding routes and retrying the payment.
However, a payment may be delayed for up to `maxdelay` blocks by another node; clients should be prepared for this worst case.

*extratlvs* is an optional dictionary of additional fields to insert into the final tlv. The format is 'fieldnumber': 'hexstring'.

When using *lightning-cli*, you may skip optional parameters by using
*null*. Alternatively, use **-k** option to provide parameters by name.

Expand Down
20 changes: 2 additions & 18 deletions plugins/keysend.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ static struct keysend_data *keysend_init(struct payment *p)
randombytes_buf(&d->preimage, sizeof(d->preimage));
ccan_sha256(&payment_hash, &d->preimage, sizeof(d->preimage));
p->payment_hash = tal_dup(p, struct sha256, &payment_hash);
#if EXPERIMENTAL_FEATURES
d->extra_tlvs = NULL;
#endif
return d;
} else {
/* If we are a child payment (retry or split) we copy the
Expand Down Expand Up @@ -92,15 +90,13 @@ static void keysend_cb(struct keysend_data *d, struct payment *p) {
tlvstream_set_raw(&last_payload->tlv_payload->fields, PREIMAGE_TLV_TYPE,
&d->preimage, sizeof(struct preimage));

#if EXPERIMENTAL_FEATURES
if (d->extra_tlvs != NULL) {
for (size_t i = 0; i < tal_count(d->extra_tlvs); i++) {
struct tlv_field *f = &d->extra_tlvs[i];
tlvstream_set_raw(&last_payload->tlv_payload->fields,
f->numtype, f->value, f->length);
}
}
#endif

return payment_continue(p);
}
Expand Down Expand Up @@ -148,9 +144,7 @@ static struct command_result *json_keysend(struct command *cmd, const char *buf,
u32 *maxdelay;
unsigned int *retryfor;
struct route_info **hints;
#if EXPERIMENTAL_FEATURES
struct tlv_field *extra_fields;
#endif

#if DEVELOPER
bool *use_shadow;
Expand All @@ -165,12 +159,10 @@ static struct command_result *json_keysend(struct command *cmd, const char *buf,
p_opt_def("maxdelay", param_number, &maxdelay,
maxdelay_default),
p_opt_def("exemptfee", param_msat, &exemptfee, AMOUNT_MSAT(5000)),
p_opt("extratlvs", param_extra_tlvs, &extra_fields),
p_opt("routehints", param_routehint_array, &hints),
#if DEVELOPER
p_opt_def("use_shadow", param_bool, &use_shadow, true),
#endif
p_opt("routehints", param_routehint_array, &hints),
#if EXPERIMENTAL_FEATURES
p_opt("extratlvs", param_extra_tlvs, &extra_fields),
#endif
NULL))
return command_param_failed();
Expand Down Expand Up @@ -210,10 +202,8 @@ static struct command_result *json_keysend(struct command *cmd, const char *buf,

p->constraints.cltv_budget = *maxdelay;

#if EXPERIMENTAL_FEATURES
payment_mod_keysend_get_data(p)->extra_tlvs =
tal_steal(p, extra_fields);
#endif

payment_mod_exemptfee_get_data(p)->amount = *exemptfee;
#if DEVELOPER
Expand Down Expand Up @@ -365,14 +355,8 @@ static struct command_result *htlc_accepted_call(struct command *cmd,
return htlc_accepted_continue(cmd, NULL);
}

#if EXPERIMENTAL_FEATURES
/* Note: This is a magic pointer value, not an actual array */
allowed = cast_const(u64 *, FROMWIRE_TLV_ANY_TYPE);
#else
/* We explicitly allow our type. */
allowed = tal_arr(cmd, u64, 1);
allowed[0] = PREIMAGE_TLV_TYPE;
#endif

payload = tlv_tlv_payload_new(cmd);
if (!fromwire_tlv(&rawpayload, &max, tlvs_tlv_tlv_payload, TLVS_ARRAY_SIZE_tlv_tlv_payload,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3568,7 +3568,7 @@ def test_keysend(node_factory):
l3.rpc.keysend(l4.info['id'], amt)


@unittest.skipIf(not EXPERIMENTAL_FEATURES, "Requires extratlvs option")
@unittest.skipIf(not EXPERIMENTAL_FEATURES, "Requires experimental-accept-extra-tlv-types option")
def test_keysend_extra_tlvs(node_factory):
"""Use the extratlvs option to deliver a message with sphinx' TLV type.
"""
Expand Down

0 comments on commit fc016df

Please sign in to comment.