From 6dcf6008e5b4be7a85157890f4695e804cb29723 Mon Sep 17 00:00:00 2001 From: darosior Date: Wed, 11 Mar 2020 13:37:24 +0100 Subject: [PATCH] bcli: register --dev-max-fee-multiplier on our side That way we pass the real min_acceptable (SLOW/2) and max_acceptable (URGENT * 10) feerates to lightningd. --- lightningd/bitcoind.c | 3 +-- lightningd/chaintopology.c | 8 +------- lightningd/lightningd.h | 4 ---- lightningd/options.c | 13 ------------- plugins/bcli.c | 24 +++++++++++++++++++++++- 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c index 3e8e630f6dac..60ee21f3fce9 100644 --- a/lightningd/bitcoind.c +++ b/lightningd/bitcoind.c @@ -153,8 +153,7 @@ static void bitcoin_plugin_send(struct bitcoind *bitcoind, * - `htlc_resolution` is used for resolving onchain HTLCs * - `penalty` is used for resolving revoked transactions * - `min` is the minimum acceptable feerate - * - `max` is the maximum acceptable feerate, note that it will be multiplied by the - * config's `max_fee_multiplier`. + * - `max` is the maximum acceptable feerate * * Plugin response: * { diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 8a63dc91e1b9..fb8479e21357 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -862,12 +862,6 @@ u32 feerate_min(struct lightningd *ld, bool *unknown) return min; } -/* BOLT #2: - * - * Given the variance in fees, and the fact that the transaction may be - * spent in the future, it's a good idea for the fee payer to keep a good - * margin (say 5x the expected fee requirement) - */ u32 feerate_max(struct lightningd *ld, bool *unknown) { u32 feerate; @@ -892,7 +886,7 @@ u32 feerate_max(struct lightningd *ld, bool *unknown) if (feehistory[i] > feerate) feerate = feehistory[i]; } - return feerate * ld->config.max_fee_multiplier; + return feerate; } /* On shutdown, channels get deleted last. That frees from our list, so diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index d42c8441f457..a2dfc5540010 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -61,10 +61,6 @@ struct config { /* ipv6 bind disable */ bool no_ipv6_bind; - /* Accept fee changes only if they are in the range our_fee - - * our_fee*multiplier */ - u32 max_fee_multiplier; - /* Are we allowed to use DNS lookup for peers. */ bool use_dns; diff --git a/lightningd/options.c b/lightningd/options.c index d76b30f6feb9..c921359b4918 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -518,13 +518,6 @@ static void dev_register_opts(struct lightningd *ld) opt_register_arg("--dev-bitcoind-poll", opt_set_u32, opt_show_u32, &ld->topology->poll_seconds, "Time between polling for new transactions"); - opt_register_arg("--dev-max-fee-multiplier", opt_set_u32, opt_show_u32, - &ld->config.max_fee_multiplier, - "Allow the fee proposed by the remote end to be up to " - "multiplier times higher than our own. Small values " - "will cause channels to be closed more often due to " - "fee fluctuations, large values may result in large " - "fees."); opt_register_noarg("--dev-fast-gossip", opt_set_bool, &ld->dev_fast_gossip, @@ -598,9 +591,6 @@ static const struct config testnet_config = { /* Rescan 5 hours of blocks on testnet, it's reorg happy */ .rescan = 30, - /* Fees may be in the range our_fee - 10*our_fee */ - .max_fee_multiplier = 10, - .use_dns = true, /* Sets min_effective_htlc_capacity - at 1000$/BTC this is 10ct */ @@ -659,9 +649,6 @@ static const struct config mainnet_config = { /* Rescan 2.5 hours of blocks on startup, it's not so reorg happy */ .rescan = 15, - /* Fees may be in the range our_fee - 10*our_fee */ - .max_fee_multiplier = 10, - .use_dns = true, /* Sets min_effective_htlc_capacity - at 1000$/BTC this is 10ct */ diff --git a/plugins/bcli.c b/plugins/bcli.c index ec19ad6d32be..5c27cc171920 100644 --- a/plugins/bcli.c +++ b/plugins/bcli.c @@ -59,6 +59,10 @@ struct bitcoind { /* Passthrough parameters for bitcoin-cli */ char *rpcuser, *rpcpass, *rpcconnect, *rpcport; + + /* The factor to time the urgent feerate by to get the maximum + * acceptable feerate. */ + u32 max_fee_multiplier; }; static struct bitcoind *bitcoind; @@ -535,7 +539,14 @@ static struct command_result *estimatefees_final_step(struct bitcoin_cli *bcli) /* We divide the slow feerate for the minimum acceptable, lightningd * will use floor if it's hit, though. */ json_add_u64(response, "min_acceptable", stash->slow / 2); - json_add_u64(response, "max_acceptable", stash->urgent); + /* BOLT #2: + * + * Given the variance in fees, and the fact that the transaction may be + * spent in the future, it's a good idea for the fee payer to keep a good + * margin (say 5x the expected fee requirement) + */ + json_add_u64(response, "max_acceptable", + stash->urgent * bitcoind->max_fee_multiplier); return command_finished(bcli->cmd, response); } @@ -910,6 +921,7 @@ int main(int argc, char *argv[]) bitcoind->rpcpass = NULL; bitcoind->rpcconnect = NULL; bitcoind->rpcport = NULL; + bitcoind->max_fee_multiplier = 10; plugin_main(argv, init, PLUGIN_STATIC, commands, ARRAY_SIZE(commands), NULL, 0, NULL, 0, @@ -942,5 +954,15 @@ int main(int argc, char *argv[]) "how long to keep retrying to contact bitcoind" " before fatally exiting", u64_option, &bitcoind->retry_timeout), +#if DEVELOPER + plugin_option("dev-max-fee-multiplier", + "string", + "Allow the fee proposed by the remote end to" + " be up to multiplier times higher than our " + "own. Small values will cause channels to be" + " closed more often due to fee fluctuations," + " large values may result in large fees.", + u32_option, &bitcoind->max_fee_multiplier), +#endif /* DEVELOPER */ NULL); }