Skip to content

Commit 1fe829c

Browse files
niftyneicdecker
authored andcommitted
lightningd: new option for htlc dust limit
To reduce the surface area of amount of a channel balance that can be eaten up as htlc dust, we introduce a new config '--max-dust-htlc-exposure-msat', which sets the max amount that any channel's balance can be added as dust Changelog-Added: config: new option --max-dust-htlc-exposure-msat, which limits the total amount of sats to be allowed as dust on a channel
1 parent 0f0a77e commit 1fe829c

File tree

13 files changed

+62
-5
lines changed

13 files changed

+62
-5
lines changed

channeld/test/run-full_channel.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ int main(int argc, const char *argv[])
406406

407407
local_config->max_htlc_value_in_flight = AMOUNT_MSAT(-1ULL);
408408
remote_config->max_htlc_value_in_flight = AMOUNT_MSAT(-1ULL);
409+
local_config->max_dust_htlc_exposure_msat = AMOUNT_MSAT(-1ULL);
410+
remote_config->max_dust_htlc_exposure_msat = AMOUNT_MSAT(-1ULL);
409411
local_config->channel_reserve = AMOUNT_SAT(0);
410412
remote_config->channel_reserve = AMOUNT_SAT(0);
411413
local_config->htlc_minimum = AMOUNT_MSAT(0);

common/channel_config.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ void towire_channel_config(u8 **pptr, const struct channel_config *config)
99
towire_amount_msat(pptr, config->htlc_minimum);
1010
towire_u16(pptr, config->to_self_delay);
1111
towire_u16(pptr, config->max_accepted_htlcs);
12+
towire_amount_msat(pptr, config->max_dust_htlc_exposure_msat);
1213
}
1314

1415
void fromwire_channel_config(const u8 **ptr, size_t *max,
@@ -20,4 +21,5 @@ void fromwire_channel_config(const u8 **ptr, size_t *max,
2021
config->htlc_minimum = fromwire_amount_msat(ptr, max);
2122
config->to_self_delay = fromwire_u16(ptr, max);
2223
config->max_accepted_htlcs = fromwire_u16(ptr, max);
24+
config->max_dust_htlc_exposure_msat = fromwire_amount_msat(ptr, max);
2325
}

common/channel_config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ struct channel_config {
7171
* similarly, `max_accepted_htlcs` limits the number of outstanding
7272
* HTLCs the other node can offer. */
7373
u16 max_accepted_htlcs;
74+
75+
/* BOLT-TBD #X
76+
*
77+
* maximum dust exposure allowed for this channel
78+
*/
79+
struct amount_msat max_dust_htlc_exposure_msat;
7480
};
7581

7682
void towire_channel_config(u8 **pptr, const struct channel_config *config);

devtools/mkcommit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ static int parse_config(char *argv[],
149149
config->max_htlc_value_in_flight = AMOUNT_MSAT(-1ULL);
150150
config->htlc_minimum = AMOUNT_MSAT(0);
151151
config->max_accepted_htlcs = 483;
152+
config->max_dust_htlc_exposure_msat = AMOUNT_MSAT(-1ULL);
152153

153154
config->to_self_delay = atoi(argv[argnum]);
154155
argnum++;

doc/lightning-listconfigs.7.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ On success, an object is returned, containing:
7171
- **rescan** (integer, optional): `rescan` field from config or cmdline, or default
7272
- **fee-per-satoshi** (u32, optional): `fee-per-satoshi` field from config or cmdline, or default
7373
- **max-concurrent-htlcs** (u32, optional): `max-concurrent-htlcs` field from config or cmdline, or default
74+
- **max-dust-htlc-exposure-msat** (msat, optional): `max-dust-htlc-exposure-mast` field from config or cmdline, or default
7475
- **min-capacity-sat** (u64, optional): `min-capacity-sat` field from config or cmdline, or default
7576
- **addr** (string, optional): `addr` field from config or cmdline (can be more than one)
7677
- **announce-addr** (string, optional): `announce-addr` field from config or cmdline (can be more than one)
@@ -206,4 +207,4 @@ RESOURCES
206207
---------
207208

208209
Main web site: <https://github.com/ElementsProject/lightning>
209-
[comment]: # ( SHA256STAMP:47c067588120e0f9a71206313685cebb2a8c515e9b04b688b202d2772c8f8146)
210+
[comment]: # ( SHA256STAMP:71a911b67203f75e7c1f717be611f505713fce4e8113fc4a84c89bc50730d2bf)

doc/schemas/listconfigs.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@
183183
"type": "u32",
184184
"description": "`max-concurrent-htlcs` field from config or cmdline, or default"
185185
},
186+
"max-dust-htlc-exposure-msat": {
187+
"type": "msat",
188+
"description": "`max-dust-htlc-exposure-mast` field from config or cmdline, or default"
189+
},
186190
"min-capacity-sat": {
187191
"type": "u64",
188192
"description": "`min-capacity-sat` field from config or cmdline, or default"

lightningd/lightningd.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <sys/stat.h>
88
#include <wallet/wallet.h>
99

10+
struct amount_msat;
11+
1012
/* Various adjustable things. */
1113
struct config {
1214
/* How long do we want them to lock up their funds? (blocks) */
@@ -31,6 +33,9 @@ struct config {
3133
/* htlcs per channel */
3234
u32 max_concurrent_htlcs;
3335

36+
/* Max amount of dust allowed per channel */
37+
struct amount_msat max_dust_htlc_exposure_msat;
38+
3439
/* How long between changing commit and sending COMMIT message. */
3540
u32 commit_time_ms;
3641

lightningd/opening_common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ void channel_config(struct lightningd *ld,
132132
ours->dust_limit = chainparams->dust_limit;
133133
ours->max_htlc_value_in_flight = AMOUNT_MSAT(UINT64_MAX);
134134

135+
ours->max_dust_htlc_exposure_msat
136+
= ld->config.max_dust_htlc_exposure_msat;
137+
135138
/* Don't care */
136139
ours->htlc_minimum = AMOUNT_MSAT(0);
137140

lightningd/options.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <common/features.h>
1111
#include <common/hsm_encryption.h>
1212
#include <common/json_command.h>
13+
#include <common/json_helpers.h>
1314
#include <common/json_tok.h>
1415
#include <common/param.h>
1516
#include <common/type_to_string.h>
@@ -671,6 +672,9 @@ static const struct config testnet_config = {
671672
/* Testnet blockspace is free. */
672673
.max_concurrent_htlcs = 483,
673674

675+
/* Max amount of dust allowed per channel (50ksat) */
676+
.max_dust_htlc_exposure_msat = AMOUNT_MSAT(50000000),
677+
674678
/* Be aggressive on testnet. */
675679
.cltv_expiry_delta = 6,
676680
.cltv_final = 10,
@@ -717,6 +721,9 @@ static const struct config mainnet_config = {
717721
/* While up to 483 htlcs are possible we do 30 by default (as eclair does) to save blockspace */
718722
.max_concurrent_htlcs = 30,
719723

724+
/* Max amount of dust allowed per channel (50ksat) */
725+
.max_dust_htlc_exposure_msat = AMOUNT_MSAT(50000000),
726+
720727
/* BOLT #2:
721728
*
722729
* 1. the `cltv_expiry_delta` for channels, `3R+2G+2S`: if in doubt, a
@@ -842,6 +849,14 @@ static char *opt_start_daemon(struct lightningd *ld)
842849
errx(1, "Died with signal %u", WTERMSIG(exitcode));
843850
}
844851

852+
static char *opt_set_msat(const char *arg, struct amount_msat *amt)
853+
{
854+
if (!parse_amount_msat(amt, arg, strlen(arg)))
855+
return tal_fmt(NULL, "Unable to parse millisatoshi '%s'", arg);
856+
857+
return NULL;
858+
}
859+
845860
static char *opt_set_wumbo(struct lightningd *ld)
846861
{
847862
feature_set_or(ld->our_features,
@@ -1005,6 +1020,9 @@ static void register_opts(struct lightningd *ld)
10051020
opt_register_arg("--max-concurrent-htlcs", opt_set_u32, opt_show_u32,
10061021
&ld->config.max_concurrent_htlcs,
10071022
"Number of HTLCs one channel can handle concurrently. Should be between 1 and 483");
1023+
opt_register_arg("--max-dust-htlc-exposure-msat", opt_set_msat,
1024+
NULL, &ld->config.max_dust_htlc_exposure_msat,
1025+
"Max HTLC amount that can be trimmed");
10081026
opt_register_arg("--min-capacity-sat", opt_set_u64, opt_show_u64,
10091027
&ld->config.min_capacity_sat,
10101028
"Minimum capacity in satoshis for accepting channels");
@@ -1496,6 +1514,8 @@ static void add_config(struct lightningd *ld,
14961514
|| opt->cb_arg == (void *)plugin_opt_flag_set) {
14971515
/* FIXME: We actually treat it as if they specified
14981516
* --plugin for each one, so ignore these */
1517+
} else if (opt->cb_arg == (void *)opt_set_msat) {
1518+
json_add_amount_msat_only(response, name0, ld->config.max_dust_htlc_exposure_msat);
14991519
#if EXPERIMENTAL_FEATURES
15001520
} else if (opt->cb_arg == (void *)opt_set_accept_extra_tlv_types) {
15011521
/* TODO Actually print the option */

openingd/dualopend.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ static struct tx_state *new_tx_state(const tal_t *ctx)
134134
tx_state->lease_chan_max_msat = 0;
135135
tx_state->lease_chan_max_ppt = 0;
136136

137+
/* no max_htlc_dust_exposure on remoteconf, we exclusively use the local's */
138+
tx_state->remoteconf.max_dust_htlc_exposure_msat = AMOUNT_MSAT(0);
139+
137140
for (size_t i = 0; i < NUM_TX_MSGS; i++)
138141
tx_state->tx_msg_count[i] = 0;
139142

0 commit comments

Comments
 (0)