From 8e7428da53dd4ce4dd27f21ac96c137acb15b255 Mon Sep 17 00:00:00 2001 From: Rene Pickhardt Date: Sat, 27 Jul 2019 19:45:22 +0200 Subject: [PATCH] Added possibility to configure max_concurrent_htlcs value for our channels. Eclaire has a default of 30 and I thought why not going with their value and while doing so make it configureable. --- lightningd/lightningd.h | 3 +++ lightningd/opening_control.c | 8 +------- lightningd/options.c | 19 ++++++++++++++++++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index d68100739..148b98f65 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -42,6 +42,9 @@ struct config { u32 fee_base; u32 fee_per_satoshi; + /* htlcs per channel */ + u32 max_concurrent_htlcs; + /* How long between changing commit and sending COMMIT message. */ u32 commit_time_ms; diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 11f7ee73d..2eec09f3d 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -835,13 +835,7 @@ static void channel_config(struct lightningd *ld, */ ours->to_self_delay = ld->config.locktime_blocks; - /* BOLT #2: - * - * The receiving node MUST fail the channel if: - *... - * - `max_accepted_htlcs` is greater than 483. - */ - ours->max_accepted_htlcs = 483; + ours->max_accepted_htlcs = ld->config.max_concurrent_htlcs; /* This is filled in by lightning_openingd, for consistency. */ ours->channel_reserve = AMOUNT_SAT(UINT64_MAX); diff --git a/lightningd/options.c b/lightningd/options.c index 317ea18e0..1647969e4 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -457,6 +457,9 @@ static const struct config testnet_config = { /* We offer to pay 5 times 2-block fee */ .commitment_fee_percent = 500, + /* Testnet blockspace is free. */ + .max_concurrent_htlcs = 483, + /* Be aggressive on testnet. */ .cltv_expiry_delta = 6, .cltv_final = 10, @@ -513,6 +516,9 @@ static const struct config mainnet_config = { /* We offer to pay 5 times 2-block fee */ .commitment_fee_percent = 500, + /* While up to 483 htlcs are possible we do 30 by default (as eclair does) to save blockspace */ + .max_concurrent_htlcs = 30, + /* BOLT #2: * * 1. the `cltv_expiry_delta` for channels, `3R+2G+2S`: if in doubt, a @@ -569,7 +575,15 @@ static void check_config(struct lightningd *ld) fatal("Commitment fee invalid min-max %u-%u", ld->config.commitment_fee_min_percent, ld->config.commitment_fee_max_percent); - + /* BOLT #2: + * + * The receiving node MUST fail the channel if: + *... + * - `max_accepted_htlcs` is greater than 483. + */ + if (ld->config.max_concurrent_htlcs < 1 || ld->config.max_concurrent_htlcs > 483) + fatal("--max-concurrent-htlcs value must be between 1 and 483 it is: %u", + ld->config.max_concurrent_htlcs); if (ld->config.anchor_confirms == 0) fatal("anchor-confirms must be greater than zero"); @@ -928,6 +942,9 @@ static void register_opts(struct lightningd *ld) opt_register_arg("--fee-per-satoshi", opt_set_u32, opt_show_u32, &ld->config.fee_per_satoshi, "Microsatoshi fee for every satoshi in HTLC"); + opt_register_arg("--max-concurrent-htlcs", opt_set_u32, opt_show_u32, + &ld->config.max_concurrent_htlcs, + "Number of HTLCs one channel can handle concurrently. Should be between 1 and 483"); opt_register_arg("--min-capacity-sat", opt_set_u64, opt_show_u64, &ld->config.min_capacity_sat, "Minimum capacity in satoshis for accepting channels");