diff --git a/bitcoin/feerate.c b/bitcoin/feerate.c index fc7342394..7788ebb2d 100644 --- a/bitcoin/feerate.c +++ b/bitcoin/feerate.c @@ -1,8 +1,12 @@ #include "config.h" +#include #include 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; diff --git a/bitcoin/feerate.h b/bitcoin/feerate.h index 43bec2118..cab1e95e2 100644 --- a/bitcoin/feerate.h +++ b/bitcoin/feerate.h @@ -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) diff --git a/channeld/watchtower.c b/channeld/watchtower.c index 269b4f405..00f34d30f 100644 --- a/channeld/watchtower.c +++ b/channeld/watchtower.c @@ -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 diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 9cc00d9a7..2c8a97fa8 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -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; } diff --git a/lightningd/chaintopology.h b/lightningd/chaintopology.h index 486fab0f3..ce8e9f98a 100644 --- a/lightningd/chaintopology.h +++ b/lightningd/chaintopology.h @@ -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, diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index 702182586..105bd6be8 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -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 diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index d43e67280..a0803a209 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -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; diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 7156d5f62..7b993c3dd 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -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)) {