mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
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:
@@ -1,8 +1,12 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include <assert.h>
|
||||||
#include <bitcoin/feerate.h>
|
#include <bitcoin/feerate.h>
|
||||||
|
|
||||||
u32 feerate_from_style(u32 feerate, enum feerate_style style)
|
u32 feerate_from_style(u32 feerate, enum feerate_style style)
|
||||||
{
|
{
|
||||||
|
/* Make sure it's called somewhere! */
|
||||||
|
assert(feerate_floor_check() == FEERATE_FLOOR);
|
||||||
|
|
||||||
switch (style) {
|
switch (style) {
|
||||||
case FEERATE_PER_KSIPA:
|
case FEERATE_PER_KSIPA:
|
||||||
return feerate;
|
return feerate;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ enum feerate_style {
|
|||||||
FEERATE_PER_KBYTE
|
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 */
|
/* Assert that bitcoind will see this as above minRelayTxFee */
|
||||||
BUILD_ASSERT(FEERATE_BITCOIND_SEES(FEERATE_FLOOR, MINIMUM_TX_WEIGHT)
|
BUILD_ASSERT(FEERATE_BITCOIND_SEES(FEERATE_FLOOR, MINIMUM_TX_WEIGHT)
|
||||||
|
|||||||
@@ -96,7 +96,9 @@ penalty_tx_create(const tal_t *ctx,
|
|||||||
|
|
||||||
if (amount_sat_less(to_them_sats, min_out)) {
|
if (amount_sat_less(to_them_sats, min_out)) {
|
||||||
/* FIXME: We should use SIGHASH_NONE so others can take it */
|
/* 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
|
/* This can only happen if feerate_floor() is still too high; shouldn't
|
||||||
|
|||||||
@@ -415,8 +415,8 @@ static void update_feerates(struct bitcoind *bitcoind,
|
|||||||
feerate, alpha);
|
feerate, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (feerate < feerate_floor()) {
|
if (feerate < get_feerate_floor(topo)) {
|
||||||
feerate = feerate_floor();
|
feerate = get_feerate_floor(topo);
|
||||||
log_debug(topo->log,
|
log_debug(topo->log,
|
||||||
"... feerate estimate for %s hit floor %u",
|
"... feerate estimate for %s hit floor %u",
|
||||||
feerate_name(i), feerate);
|
feerate_name(i), feerate);
|
||||||
@@ -487,6 +487,12 @@ u32 penalty_feerate(struct chain_topology *topo)
|
|||||||
return try_get_feerate(topo, FEERATE_PENALTY);
|
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,
|
static struct command_result *json_feerates(struct command *cmd,
|
||||||
const char *buffer,
|
const char *buffer,
|
||||||
const jsmntok_t *obj UNNEEDED,
|
const jsmntok_t *obj UNNEEDED,
|
||||||
@@ -936,8 +942,8 @@ u32 feerate_min(struct lightningd *ld, bool *unknown)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (min < feerate_floor())
|
if (min < get_feerate_floor(ld->topology))
|
||||||
return feerate_floor();
|
return get_feerate_floor(ld->topology);
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,9 @@ struct txlocator {
|
|||||||
u32 index;
|
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
|
/* This is the number of blocks which would have to be mined to invalidate
|
||||||
* the tx */
|
* the tx */
|
||||||
size_t get_tx_depth(const struct chain_topology *topo,
|
size_t get_tx_depth(const struct chain_topology *topo,
|
||||||
|
|||||||
@@ -409,8 +409,8 @@ void peer_start_closingd(struct channel *channel, struct peer_fd *peer_fd)
|
|||||||
feerate = mutual_close_feerate(ld->topology);
|
feerate = mutual_close_feerate(ld->topology);
|
||||||
if (!feerate) {
|
if (!feerate) {
|
||||||
feerate = final_commit_feerate / 2;
|
feerate = final_commit_feerate / 2;
|
||||||
if (feerate < feerate_floor())
|
if (feerate < get_feerate_floor(ld->topology))
|
||||||
feerate = feerate_floor();
|
feerate = get_feerate_floor(ld->topology);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We use a feerate if anchor_outputs, otherwise max fee is set by
|
/* We use a feerate if anchor_outputs, otherwise max fee is set by
|
||||||
|
|||||||
@@ -703,12 +703,13 @@ static struct bitcoin_tx *onchaind_tx(const tal_t *ctx,
|
|||||||
|
|
||||||
if (amount_sat_less(out_sats, min_out)) {
|
if (amount_sat_less(out_sats, min_out)) {
|
||||||
/* FIXME: We should use SIGHASH_NONE so others can take it? */
|
/* 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;
|
*worthwhile = false;
|
||||||
} else
|
} else
|
||||||
*worthwhile = true;
|
*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! */
|
* happen! */
|
||||||
if (!amount_sat_sub(&amt, out_sats, fee)) {
|
if (!amount_sat_sub(&amt, out_sats, fee)) {
|
||||||
amt = channel->our_config.dust_limit;
|
amt = channel->our_config.dust_limit;
|
||||||
|
|||||||
@@ -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,
|
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)) {
|
if (!topology_synced(cmd->ld->topology)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user