bitcoind: keep running fee estimate.

This avoids us having to query it when we create anchor transaction, and
lets us always use dynamic fee information.

The config options for max and min are now percentages, rather than absolute.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2016-08-18 14:23:46 +09:30
parent ab38fd7542
commit 02cb7abd9d
11 changed files with 97 additions and 101 deletions

View File

@@ -107,15 +107,18 @@ static void config_register_opts(struct lightningd_state *dstate)
opt_register_arg("--forever-confirms", opt_set_u32, opt_show_u32,
&dstate->config.forever_confirms,
"Confirmations after which we consider a reorg impossible");
opt_register_arg("--commit-fee-rate", opt_set_u64, opt_show_u64,
&dstate->config.commitment_fee_rate,
"Satoshis to offer for commitment transaction fee (per kb)");
opt_register_arg("--min-commit-fee-rate", opt_set_u64, opt_show_u64,
&dstate->config.commitment_fee_rate_min,
"Minimum satoshis to accept for commitment transaction fee (per kb)");
opt_register_arg("--closing-fee-rate", opt_set_u64, opt_show_u64,
&dstate->config.closing_fee_rate,
"Satoshis to use for mutual close transaction fee (per kb)");
opt_register_arg("--commit-fee-min=<percent>", opt_set_u32, opt_show_u32,
&dstate->config.commitment_fee_min_percent,
"Minimum percentage of fee to accept for commitment");
opt_register_arg("--commit-fee-max=<percent>", opt_set_u32, opt_show_u32,
&dstate->config.commitment_fee_max_percent,
"Maximum percentage of fee to accept for commitment");
opt_register_arg("--commit-fee=<percent>", opt_set_u32, opt_show_u32,
&dstate->config.commitment_fee_percent,
"Percentage of fee to request for their commitment");
opt_register_arg("--default-fee-rate", opt_set_u64, opt_show_u64,
&dstate->config.default_fee_rate,
"Satoshis per kb if can't estimate fees");
opt_register_arg("--min-htlc-expiry", opt_set_u32, opt_show_u32,
&dstate->config.min_htlc_expiry,
"Minimum number of blocks to accept an HTLC before expiry");
@@ -168,16 +171,15 @@ static void default_config(struct config *config)
*/
config->forever_confirms = 100;
/* FIXME: These should float with bitcoind's recommendations! */
/* Insist between 2 and 20 times the 2-block fee. */
config->commitment_fee_min_percent = 200;
config->commitment_fee_max_percent = 2000;
/* Pay hefty fee (double historic high of ~100k). */
config->commitment_fee_rate = 200000;
/* We offer to pay 5 times 2-block fee */
config->commitment_fee_percent = 500;
/* Don't accept less than double the average 2-block fee. */
config->commitment_fee_rate_min = 50000;
/* Use this for mutual close. */
config->closing_fee_rate = 20000;
/* Use this rate by default if estimatefee doesn't estimate. */
config->default_fee_rate = 40000;
/* Don't bother me unless I have 6 hours to collect. */
config->min_htlc_expiry = 6 * 6;
@@ -201,24 +203,12 @@ static void default_config(struct config *config)
static void check_config(struct lightningd_state *dstate)
{
/* BOLT #2:
* The sender MUST set `close_fee` lower than or equal to the
* fee of the final commitment transaction
*/
/* We do this by ensuring it's less than the minimum we would accept. */
if (dstate->config.closing_fee_rate > dstate->config.commitment_fee_rate_min)
fatal("Closing fee rate %"PRIu64
" can't exceed minimum commitment fee rate %"PRIu64,
dstate->config.closing_fee_rate,
dstate->config.commitment_fee_rate_min);
if (dstate->config.commitment_fee_rate_min
> dstate->config.commitment_fee_rate)
fatal("Minumum fee rate %"PRIu64
" can't exceed commitment fee rate %"PRIu64,
dstate->config.commitment_fee_rate_min,
dstate->config.commitment_fee_rate);
if (dstate->config.commitment_fee_max_percent
< dstate->config.commitment_fee_min_percent)
fatal("Commitment fee invalid min-max %u-%u",
dstate->config.commitment_fee_min_percent,
dstate->config.commitment_fee_max_percent);
if (dstate->config.forever_confirms < 100)
log_unusual(dstate->base_log,