Skip to content

Commit 9de05c3

Browse files
committed
keysend: Add maxfee to keysend for consistency with pay
1 parent 78b9ccf commit 9de05c3

File tree

12 files changed

+774
-687
lines changed

12 files changed

+774
-687
lines changed

.msggen.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,7 @@
15211521
"KeySend.extratlvs": 9,
15221522
"KeySend.label": 3,
15231523
"KeySend.maxdelay": 6,
1524+
"KeySend.maxfee": 11,
15241525
"KeySend.maxfeepercent": 4,
15251526
"KeySend.msatoshi": 2,
15261527
"KeySend.retry_for": 5,
@@ -6362,6 +6363,10 @@
63626363
"added": "pre-v0.10.1",
63636364
"deprecated": null
63646365
},
6366+
"KeySend.maxfee": {
6367+
"added": "v24.11",
6368+
"deprecated": null
6369+
},
63656370
"KeySend.maxfeepercent": {
63666371
"added": "pre-v0.10.1",
63676372
"deprecated": null

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

6+
## [Unreleased]
7+
8+
### Added
9+
10+
- keysend: Add `maxfee` to keysend for consistency with pay. ([#7227])
611

712
## [24.08] - 2024-08-28: "Steel Backed-up Channels"
813

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-grpc/src/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ fn test_keysend() {
293293
}],
294294
}),
295295
extratlvs: None,
296+
maxfee: None
296297
};
297298

298299
let u: cln_rpc::model::requests::KeysendRequest = g.into();

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15048,6 +15048,13 @@
1504815048
"description": [
1504915049
"Dictionary of additional fields to insert into the final tlv. The format is 'fieldnumber': 'hexstring'."
1505015050
]
15051+
},
15052+
"maxfee": {
15053+
"added": "v24.11",
15054+
"type": "msat",
15055+
"description": [
15056+
"*maxfee* overrides both *maxfeepercent* and *exemptfee* defaults (and if you specify *maxfee* you cannot specify either of those), and creates an absolute limit on what fee we will pay. This allows you to implement your own heuristics rather than the primitive ones used here."
15057+
]
1505115058
}
1505215059
}
1505315060
},

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

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

doc/schemas/lightning-keysend.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@
103103
"description": [
104104
"Dictionary of additional fields to insert into the final tlv. The format is 'fieldnumber': 'hexstring'."
105105
]
106+
},
107+
"maxfee": {
108+
"added": "v24.11",
109+
"type": "msat",
110+
"description": [
111+
"*maxfee* overrides both *maxfeepercent* and *exemptfee* defaults (and if you specify *maxfee* you cannot specify either of those), and creates an absolute limit on what fee we will pay. This allows you to implement your own heuristics rather than the primitive ones used here."
112+
]
106113
}
107114
}
108115
},

plugins/keysend.c

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static u64 *accepted_extra_tlvs;
2323
* ================
2424
*
2525
* The keysend modifier adds the payment preimage to the TLV payload. This
26-
* enables the recipient to accept the payment despite it not correspondin to
26+
* enables the recipient to accept the payment despite it not corresponding to
2727
* an invoice that the recipient created. Keysend does not provide any proof
2828
* or payment, but does not require an out-of-band communication round to get
2929
* an invoice first.
@@ -215,7 +215,7 @@ static struct command_result *json_keysend(struct command *cmd, const char *buf,
215215
{
216216
struct payment *p;
217217
const char *label;
218-
struct amount_msat *exemptfee, *msat;
218+
struct amount_msat *exemptfee, *msat, *maxfee;
219219
struct node_id *destination;
220220
u64 *maxfee_pct_millionths;
221221
u32 *maxdelay;
@@ -229,14 +229,15 @@ static struct command_result *json_keysend(struct command *cmd, const char *buf,
229229
p_req("destination", param_node_id, &destination),
230230
p_req("amount_msat", param_msat, &msat),
231231
p_opt("label", param_string, &label),
232-
p_opt_def("maxfeepercent", param_millionths,
233-
&maxfee_pct_millionths, 500000),
232+
p_opt("maxfeepercent", param_millionths,
233+
&maxfee_pct_millionths),
234234
p_opt_def("retry_for", param_number, &retryfor, 60),
235235
p_opt_def("maxdelay", param_number, &maxdelay,
236236
maxdelay_default),
237-
p_opt_def("exemptfee", param_msat, &exemptfee, AMOUNT_MSAT(5000)),
237+
p_opt("exemptfee", param_msat, &exemptfee),
238238
p_opt("extratlvs", param_extra_tlvs, &extra_fields),
239239
p_opt("routehints", param_routehint_array, &hints),
240+
p_opt("maxfee", param_msat, &maxfee),
240241
p_opt_dev("dev_use_shadow", param_bool, &dev_use_shadow, true),
241242
NULL))
242243
return command_param_failed();
@@ -272,19 +273,36 @@ static struct command_result *json_keysend(struct command *cmd, const char *buf,
272273
"We are the destination. Keysend cannot be used to send funds to yourself");
273274
}
274275

275-
if (!amount_msat_fee(&p->constraints.fee_budget, p->our_amount, 0,
276-
*maxfee_pct_millionths / 100)) {
277-
return command_fail(
278-
cmd, JSONRPC2_INVALID_PARAMS,
279-
"Overflow when computing fee budget, fee rate too high.");
280-
}
281-
282276
p->constraints.cltv_budget = *maxdelay;
283277

284278
payment_mod_keysend_get_data(p)->extra_tlvs =
285279
tal_steal(p, extra_fields);
286280

287-
payment_mod_exemptfee_get_data(p)->amount = *exemptfee;
281+
if (maxfee) {
282+
if (maxfee_pct_millionths || exemptfee) {
283+
return command_fail(
284+
cmd, JSONRPC2_INVALID_PARAMS,
285+
"If you specify maxfee, cannot specify maxfeepercent or exemptfee.");
286+
}
287+
p->constraints.fee_budget = *maxfee;
288+
payment_mod_exemptfee_get_data(p)->amount = AMOUNT_MSAT(0);
289+
} else {
290+
u64 maxppm;
291+
292+
if (maxfee_pct_millionths)
293+
maxppm = *maxfee_pct_millionths / 100;
294+
else
295+
maxppm = 500000 / 100;
296+
if (!amount_msat_fee(&p->constraints.fee_budget, p->our_amount, 0,
297+
maxppm)) {
298+
return command_fail(
299+
cmd, JSONRPC2_INVALID_PARAMS,
300+
"Overflow when computing fee budget, fee rate too high.");
301+
}
302+
payment_mod_exemptfee_get_data(p)->amount
303+
= exemptfee ? *exemptfee : AMOUNT_MSAT(5000);
304+
}
305+
288306
payment_mod_shadowroute_get_data(p)->use_shadow = *dev_use_shadow;
289307
p->label = tal_steal(p, label);
290308

0 commit comments

Comments
 (0)