lightningd: clarify uses of dynamic (mempool) feerate floor, and static.

We have the FEERATE_FLOOR constant if you don't care, but usually you want
to use the current bitcoind lower limit, so call get_feerate_floor()
(which is currently the same, but coming!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-04-07 14:09:53 +09:30
parent 7aa8c76002
commit faae44713b
8 changed files with 29 additions and 12 deletions

View File

@ -1,8 +1,12 @@
#include "config.h"
#include <assert.h>
#include <bitcoin/feerate.h>
u32 feerate_from_style(u32 feerate, enum feerate_style style)
{
/* Make sure it's called somewhere! */
assert(feerate_floor_check() == FEERATE_FLOOR);
switch (style) {
case FEERATE_PER_KSIPA:
return feerate;

View File

@ -39,7 +39,7 @@ enum feerate_style {
FEERATE_PER_KBYTE
};
static inline u32 feerate_floor(void)
static inline u32 feerate_floor_check(void)
{
/* Assert that bitcoind will see this as above minRelayTxFee */
BUILD_ASSERT(FEERATE_BITCOIND_SEES(FEERATE_FLOOR, MINIMUM_TX_WEIGHT)

View File

@ -96,7 +96,9 @@ penalty_tx_create(const tal_t *ctx,
if (amount_sat_less(to_them_sats, min_out)) {
/* FIXME: We should use SIGHASH_NONE so others can take it */
fee = amount_tx_fee(feerate_floor(), weight);
/* We use the minimum possible fee here; if it doesn't
* propagate, who cares? */
fee = amount_tx_fee(FEERATE_FLOOR, weight);
}
/* This can only happen if feerate_floor() is still too high; shouldn't

View File

@ -415,8 +415,8 @@ static void update_feerates(struct bitcoind *bitcoind,
feerate, alpha);
}
if (feerate < feerate_floor()) {
feerate = feerate_floor();
if (feerate < get_feerate_floor(topo)) {
feerate = get_feerate_floor(topo);
log_debug(topo->log,
"... feerate estimate for %s hit floor %u",
feerate_name(i), feerate);
@ -487,6 +487,12 @@ u32 penalty_feerate(struct chain_topology *topo)
return try_get_feerate(topo, FEERATE_PENALTY);
}
u32 get_feerate_floor(const struct chain_topology *topo)
{
/* FIXME: Make this dynamic! */
return FEERATE_FLOOR;
}
static struct command_result *json_feerates(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
@ -936,8 +942,8 @@ u32 feerate_min(struct lightningd *ld, bool *unknown)
}
}
if (min < feerate_floor())
return feerate_floor();
if (min < get_feerate_floor(ld->topology))
return get_feerate_floor(ld->topology);
return min;
}

View File

@ -143,6 +143,9 @@ struct txlocator {
u32 index;
};
/* Get the minimum feerate that bitcoind will accept */
u32 get_feerate_floor(const struct chain_topology *topo);
/* This is the number of blocks which would have to be mined to invalidate
* the tx */
size_t get_tx_depth(const struct chain_topology *topo,

View File

@ -409,8 +409,8 @@ void peer_start_closingd(struct channel *channel, struct peer_fd *peer_fd)
feerate = mutual_close_feerate(ld->topology);
if (!feerate) {
feerate = final_commit_feerate / 2;
if (feerate < feerate_floor())
feerate = feerate_floor();
if (feerate < get_feerate_floor(ld->topology))
feerate = get_feerate_floor(ld->topology);
}
/* We use a feerate if anchor_outputs, otherwise max fee is set by

View File

@ -703,12 +703,13 @@ static struct bitcoin_tx *onchaind_tx(const tal_t *ctx,
if (amount_sat_less(out_sats, min_out)) {
/* FIXME: We should use SIGHASH_NONE so others can take it? */
fee = amount_tx_fee(feerate_floor(), weight);
/* Use lowest possible theoretical fee: who cares if it doesn't propagate */
fee = amount_tx_fee(FEERATE_FLOOR, weight);
*worthwhile = false;
} else
*worthwhile = true;
/* This can only happen if feerate_floor() is still too high; shouldn't
/* This can only happen if FEERATE_FLOOR is still too high; shouldn't
* happen! */
if (!amount_sat_sub(&amt, out_sats, fee)) {
amt = channel->our_config.dust_limit;

View File

@ -1159,9 +1159,10 @@ static struct command_result *json_fundchannel_start(struct command *cmd,
}
}
if (*feerate_per_kw < feerate_floor()) {
if (*feerate_per_kw < get_feerate_floor(cmd->ld->topology)) {
return command_fail(cmd, LIGHTNINGD,
"Feerate below feerate floor");
"Feerate below feerate floor %u perkw",
get_feerate_floor(cmd->ld->topology));
}
if (!topology_synced(cmd->ld->topology)) {