Skip to content

Commit

Permalink
bcli: register --dev-max-fee-multiplier on our side
Browse files Browse the repository at this point in the history
That way we pass the real min_acceptable (SLOW/2) and max_acceptable
(URGENT * 10) feerates to lightningd.
  • Loading branch information
darosior committed Mar 11, 2020
1 parent 90c50ec commit 6dcf600
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
3 changes: 1 addition & 2 deletions lightningd/bitcoind.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
* {
Expand Down
8 changes: 1 addition & 7 deletions lightningd/chaintopology.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lightningd/lightningd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 0 additions & 13 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
24 changes: 23 additions & 1 deletion plugins/bcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

0 comments on commit 6dcf600

Please sign in to comment.