diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 55363e4db..c7ffa5bb3 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -1142,30 +1142,25 @@ u32 feerate_min(struct lightningd *ld, bool *unknown) * * [1] https://github.com/ElementsProject/lightning/issues/6362 * */ - if (ld->config.ignore_fee_limits) - min = 1; - else { - min = 0xFFFFFFFF; - for (size_t i = 0; i < ARRAY_SIZE(topo->feerates); i++) { - for (size_t j = 0; j < tal_count(topo->feerates[i]); j++) { - if (topo->feerates[i][j].rate < min) - min = topo->feerates[i][j].rate; - } + min = 0xFFFFFFFF; + for (size_t i = 0; i < ARRAY_SIZE(topo->feerates); i++) { + for (size_t j = 0; j < tal_count(topo->feerates[i]); j++) { + if (topo->feerates[i][j].rate < min) + min = topo->feerates[i][j].rate; } - if (min == 0xFFFFFFFF) { - if (unknown) - *unknown = true; - min = 0; - } - - /* FIXME: This is what bcli used to do: halve the slow feerate! */ - min /= 2; - - /* We can't allow less than feerate_floor, since that won't relay */ - if (min < get_feerate_floor(topo)) - return get_feerate_floor(topo); + } + if (min == 0xFFFFFFFF) { + if (unknown) + *unknown = true; + min = 0; } + /* FIXME: This is what bcli used to do: halve the slow feerate! */ + min /= 2; + + /* We can't allow less than feerate_floor, since that won't relay */ + if (min < get_feerate_floor(topo)) + return get_feerate_floor(topo); return min; } @@ -1177,9 +1172,6 @@ u32 feerate_max(struct lightningd *ld, bool *unknown) if (unknown) *unknown = false; - if (ld->config.ignore_fee_limits) - return UINT_MAX; - for (size_t i = 0; i < ARRAY_SIZE(topo->feerates); i++) { for (size_t j = 0; j < tal_count(topo->feerates[i]); j++) { if (topo->feerates[i][j].rate > max) diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 27953d55c..9572e4f57 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -24,10 +24,10 @@ #include #include -static void update_feerates(struct lightningd *ld, struct channel *channel) +static void update_feerates(struct lightningd *ld, const struct channel *channel) { u8 *msg; - u32 min_feerate; + u32 min_feerate, max_feerate; bool anchors = channel_type_has_anchors(channel->type); u32 feerate = unilateral_feerate(ld->topology, anchors); @@ -40,6 +40,12 @@ static void update_feerates(struct lightningd *ld, struct channel *channel) min_feerate = get_feerate_floor(ld->topology); else min_feerate = feerate_min(ld, NULL); + max_feerate = feerate_max(ld, NULL); + + if (channel->ignore_fee_limits || ld->config.ignore_fee_limits) { + min_feerate = 1; + max_feerate = 0xFFFFFFFF; + } log_debug(ld->log, "update_feerates: feerate = %u, min=%u, max=%u, penalty=%u", @@ -50,7 +56,7 @@ static void update_feerates(struct lightningd *ld, struct channel *channel) msg = towire_channeld_feerates(NULL, feerate, min_feerate, - feerate_max(ld, NULL), + max_feerate, penalty_feerate(ld->topology)); subd_send_msg(channel->owner, take(msg)); } @@ -624,7 +630,7 @@ bool peer_start_channeld(struct channel *channel, struct secret last_remote_per_commit_secret; secp256k1_ecdsa_signature *remote_ann_node_sig, *remote_ann_bitcoin_sig; struct penalty_base *pbases; - u32 min_feerate; + u32 min_feerate, max_feerate; hsmfd = hsm_get_client_fd(ld, &channel->peer->id, channel->dbid, @@ -696,7 +702,7 @@ bool peer_start_channeld(struct channel *channel, } /* Warn once. */ - if (ld->config.ignore_fee_limits) + if (channel->ignore_fee_limits || ld->config.ignore_fee_limits) log_unusual(channel->log, "Ignoring fee limits!"); if (!wallet_remote_ann_sigs_load(tmpctx, channel->peer->ld->wallet, @@ -729,6 +735,12 @@ bool peer_start_channeld(struct channel *channel, min_feerate = get_feerate_floor(ld->topology); else min_feerate = feerate_min(ld, NULL); + max_feerate = feerate_max(ld, NULL); + + if (channel->ignore_fee_limits || ld->config.ignore_fee_limits) { + min_feerate = 1; + max_feerate = 0xFFFFFFFF; + } initmsg = towire_channeld_init(tmpctx, chainparams, @@ -744,7 +756,7 @@ bool peer_start_channeld(struct channel *channel, &channel->channel_info.their_config, channel->fee_states, min_feerate, - feerate_max(ld, NULL), + max_feerate, penalty_feerate(ld->topology), &channel->last_sig, &channel->channel_info.remote_fundingkey, diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index 9024b1a5c..f5ba5babb 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -199,10 +199,8 @@ static bool closing_fee_is_acceptable(struct lightningd *ld, struct channel *channel, const struct bitcoin_tx *tx) { - struct amount_sat fee, last_fee, min_fee; + struct amount_sat fee, last_fee; u64 weight; - u32 min_feerate; - bool feerate_unknown; /* Calculate actual fee (adds in eliminated outputs) */ fee = calc_tx_fee(channel->funding_sats, tx); @@ -219,16 +217,21 @@ static bool closing_fee_is_acceptable(struct lightningd *ld, type_to_string(tmpctx, struct amount_sat, &last_fee), weight); - /* If we don't have a feerate estimate, this gives feerate_floor */ - min_feerate = feerate_min(ld, &feerate_unknown); + if (!channel->ignore_fee_limits && !ld->config.ignore_fee_limits) { + struct amount_sat min_fee; + u32 min_feerate; - min_fee = amount_tx_fee(min_feerate, weight); - if (amount_sat_less(fee, min_fee)) { - log_debug(channel->log, "... That's below our min %s" - " for weight %"PRIu64" at feerate %u", - type_to_string(tmpctx, struct amount_sat, &min_fee), - weight, min_feerate); - return false; + /* If we don't have a feerate estimate, this gives feerate_floor */ + min_feerate = feerate_min(ld, NULL); + + min_fee = amount_tx_fee(min_feerate, weight); + if (amount_sat_less(fee, min_fee)) { + log_debug(channel->log, "... That's below our min %s" + " for weight %"PRIu64" at feerate %u", + type_to_string(tmpctx, struct amount_sat, &min_fee), + weight, min_feerate); + return false; + } } /* Prefer new over old: this covers the preference @@ -434,6 +437,11 @@ void peer_start_closingd(struct channel *channel, struct peer_fd *peer_fd) if (channel->closing_feerate_range) { min_feerate = channel->closing_feerate_range[0]; max_feerate = &channel->closing_feerate_range[1]; + } else if (channel->ignore_fee_limits || ld->config.ignore_fee_limits) { + min_feerate = 1; + tal_free(max_feerate); + max_feerate = tal(tmpctx, u32); + *max_feerate = 0xFFFFFFFF; } /* BOLT #3: diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 56d5166b1..180a9067c 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -926,6 +926,7 @@ bool peer_start_openingd(struct peer *peer, struct peer_fd *peer_fd) struct amount_msat min_effective_htlc_capacity; struct uncommitted_channel *uc; const u8 *msg; + u32 minrate, maxrate; assert(peer->uncommitted_channel); uc = peer->uncommitted_channel; @@ -957,6 +958,13 @@ bool peer_start_openingd(struct peer *peer, struct peer_fd *peer_fd) &max_to_self_delay, &min_effective_htlc_capacity); + if (peer->ld->config.ignore_fee_limits) { + minrate = 1; + maxrate = 0xFFFFFFFF; + } else { + minrate = feerate_min(peer->ld, NULL); + maxrate = feerate_max(peer->ld, NULL); + } msg = towire_openingd_init(NULL, chainparams, @@ -968,8 +976,7 @@ bool peer_start_openingd(struct peer *peer, struct peer_fd *peer_fd) &uc->local_basepoints, &uc->local_funding_pubkey, uc->minimum_depth, - feerate_min(peer->ld, NULL), - feerate_max(peer->ld, NULL), + minrate, maxrate, IFDEV(peer->ld->dev_force_tmp_channel_id, NULL), peer->ld->config.allowdustreserve); subd_send_msg(uc->open_daemon, take(msg));