mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
lightningd: don't override fee limits in feerate_min/max, do so in callers.
Since it's going to be per-channel, this makes more sense. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
95b69c2cf8
commit
472db2390f
4 changed files with 63 additions and 44 deletions
|
@ -1142,30 +1142,25 @@ u32 feerate_min(struct lightningd *ld, bool *unknown)
|
||||||
*
|
*
|
||||||
* [1] https://github.com/ElementsProject/lightning/issues/6362
|
* [1] https://github.com/ElementsProject/lightning/issues/6362
|
||||||
* */
|
* */
|
||||||
if (ld->config.ignore_fee_limits)
|
min = 0xFFFFFFFF;
|
||||||
min = 1;
|
for (size_t i = 0; i < ARRAY_SIZE(topo->feerates); i++) {
|
||||||
else {
|
for (size_t j = 0; j < tal_count(topo->feerates[i]); j++) {
|
||||||
min = 0xFFFFFFFF;
|
if (topo->feerates[i][j].rate < min)
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(topo->feerates); i++) {
|
min = topo->feerates[i][j].rate;
|
||||||
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)
|
if (min == 0xFFFFFFFF) {
|
||||||
*unknown = true;
|
if (unknown)
|
||||||
min = 0;
|
*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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1177,9 +1172,6 @@ u32 feerate_max(struct lightningd *ld, bool *unknown)
|
||||||
if (unknown)
|
if (unknown)
|
||||||
*unknown = false;
|
*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 i = 0; i < ARRAY_SIZE(topo->feerates); i++) {
|
||||||
for (size_t j = 0; j < tal_count(topo->feerates[i]); j++) {
|
for (size_t j = 0; j < tal_count(topo->feerates[i]); j++) {
|
||||||
if (topo->feerates[i][j].rate > max)
|
if (topo->feerates[i][j].rate > max)
|
||||||
|
|
|
@ -24,10 +24,10 @@
|
||||||
#include <lightningd/peer_fd.h>
|
#include <lightningd/peer_fd.h>
|
||||||
#include <wally_bip32.h>
|
#include <wally_bip32.h>
|
||||||
|
|
||||||
static void update_feerates(struct lightningd *ld, struct channel *channel)
|
static void update_feerates(struct lightningd *ld, const struct channel *channel)
|
||||||
{
|
{
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
u32 min_feerate;
|
u32 min_feerate, max_feerate;
|
||||||
bool anchors = channel_type_has_anchors(channel->type);
|
bool anchors = channel_type_has_anchors(channel->type);
|
||||||
u32 feerate = unilateral_feerate(ld->topology, anchors);
|
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);
|
min_feerate = get_feerate_floor(ld->topology);
|
||||||
else
|
else
|
||||||
min_feerate = feerate_min(ld, NULL);
|
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,
|
log_debug(ld->log,
|
||||||
"update_feerates: feerate = %u, min=%u, max=%u, penalty=%u",
|
"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,
|
msg = towire_channeld_feerates(NULL, feerate,
|
||||||
min_feerate,
|
min_feerate,
|
||||||
feerate_max(ld, NULL),
|
max_feerate,
|
||||||
penalty_feerate(ld->topology));
|
penalty_feerate(ld->topology));
|
||||||
subd_send_msg(channel->owner, take(msg));
|
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;
|
struct secret last_remote_per_commit_secret;
|
||||||
secp256k1_ecdsa_signature *remote_ann_node_sig, *remote_ann_bitcoin_sig;
|
secp256k1_ecdsa_signature *remote_ann_node_sig, *remote_ann_bitcoin_sig;
|
||||||
struct penalty_base *pbases;
|
struct penalty_base *pbases;
|
||||||
u32 min_feerate;
|
u32 min_feerate, max_feerate;
|
||||||
|
|
||||||
hsmfd = hsm_get_client_fd(ld, &channel->peer->id,
|
hsmfd = hsm_get_client_fd(ld, &channel->peer->id,
|
||||||
channel->dbid,
|
channel->dbid,
|
||||||
|
@ -696,7 +702,7 @@ bool peer_start_channeld(struct channel *channel,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Warn once. */
|
/* 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!");
|
log_unusual(channel->log, "Ignoring fee limits!");
|
||||||
|
|
||||||
if (!wallet_remote_ann_sigs_load(tmpctx, channel->peer->ld->wallet,
|
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);
|
min_feerate = get_feerate_floor(ld->topology);
|
||||||
else
|
else
|
||||||
min_feerate = feerate_min(ld, NULL);
|
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,
|
initmsg = towire_channeld_init(tmpctx,
|
||||||
chainparams,
|
chainparams,
|
||||||
|
@ -744,7 +756,7 @@ bool peer_start_channeld(struct channel *channel,
|
||||||
&channel->channel_info.their_config,
|
&channel->channel_info.their_config,
|
||||||
channel->fee_states,
|
channel->fee_states,
|
||||||
min_feerate,
|
min_feerate,
|
||||||
feerate_max(ld, NULL),
|
max_feerate,
|
||||||
penalty_feerate(ld->topology),
|
penalty_feerate(ld->topology),
|
||||||
&channel->last_sig,
|
&channel->last_sig,
|
||||||
&channel->channel_info.remote_fundingkey,
|
&channel->channel_info.remote_fundingkey,
|
||||||
|
|
|
@ -199,10 +199,8 @@ static bool closing_fee_is_acceptable(struct lightningd *ld,
|
||||||
struct channel *channel,
|
struct channel *channel,
|
||||||
const struct bitcoin_tx *tx)
|
const struct bitcoin_tx *tx)
|
||||||
{
|
{
|
||||||
struct amount_sat fee, last_fee, min_fee;
|
struct amount_sat fee, last_fee;
|
||||||
u64 weight;
|
u64 weight;
|
||||||
u32 min_feerate;
|
|
||||||
bool feerate_unknown;
|
|
||||||
|
|
||||||
/* Calculate actual fee (adds in eliminated outputs) */
|
/* Calculate actual fee (adds in eliminated outputs) */
|
||||||
fee = calc_tx_fee(channel->funding_sats, tx);
|
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),
|
type_to_string(tmpctx, struct amount_sat, &last_fee),
|
||||||
weight);
|
weight);
|
||||||
|
|
||||||
/* If we don't have a feerate estimate, this gives feerate_floor */
|
if (!channel->ignore_fee_limits && !ld->config.ignore_fee_limits) {
|
||||||
min_feerate = feerate_min(ld, &feerate_unknown);
|
struct amount_sat min_fee;
|
||||||
|
u32 min_feerate;
|
||||||
|
|
||||||
min_fee = amount_tx_fee(min_feerate, weight);
|
/* If we don't have a feerate estimate, this gives feerate_floor */
|
||||||
if (amount_sat_less(fee, min_fee)) {
|
min_feerate = feerate_min(ld, NULL);
|
||||||
log_debug(channel->log, "... That's below our min %s"
|
|
||||||
" for weight %"PRIu64" at feerate %u",
|
min_fee = amount_tx_fee(min_feerate, weight);
|
||||||
type_to_string(tmpctx, struct amount_sat, &min_fee),
|
if (amount_sat_less(fee, min_fee)) {
|
||||||
weight, min_feerate);
|
log_debug(channel->log, "... That's below our min %s"
|
||||||
return false;
|
" 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
|
/* 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) {
|
if (channel->closing_feerate_range) {
|
||||||
min_feerate = channel->closing_feerate_range[0];
|
min_feerate = channel->closing_feerate_range[0];
|
||||||
max_feerate = &channel->closing_feerate_range[1];
|
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:
|
/* BOLT #3:
|
||||||
|
|
|
@ -926,6 +926,7 @@ bool peer_start_openingd(struct peer *peer, struct peer_fd *peer_fd)
|
||||||
struct amount_msat min_effective_htlc_capacity;
|
struct amount_msat min_effective_htlc_capacity;
|
||||||
struct uncommitted_channel *uc;
|
struct uncommitted_channel *uc;
|
||||||
const u8 *msg;
|
const u8 *msg;
|
||||||
|
u32 minrate, maxrate;
|
||||||
|
|
||||||
assert(peer->uncommitted_channel);
|
assert(peer->uncommitted_channel);
|
||||||
uc = 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,
|
&max_to_self_delay,
|
||||||
&min_effective_htlc_capacity);
|
&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,
|
msg = towire_openingd_init(NULL,
|
||||||
chainparams,
|
chainparams,
|
||||||
|
@ -968,8 +976,7 @@ bool peer_start_openingd(struct peer *peer, struct peer_fd *peer_fd)
|
||||||
&uc->local_basepoints,
|
&uc->local_basepoints,
|
||||||
&uc->local_funding_pubkey,
|
&uc->local_funding_pubkey,
|
||||||
uc->minimum_depth,
|
uc->minimum_depth,
|
||||||
feerate_min(peer->ld, NULL),
|
minrate, maxrate,
|
||||||
feerate_max(peer->ld, NULL),
|
|
||||||
IFDEV(peer->ld->dev_force_tmp_channel_id, NULL),
|
IFDEV(peer->ld->dev_force_tmp_channel_id, NULL),
|
||||||
peer->ld->config.allowdustreserve);
|
peer->ld->config.allowdustreserve);
|
||||||
subd_send_msg(uc->open_daemon, take(msg));
|
subd_send_msg(uc->open_daemon, take(msg));
|
||||||
|
|
Loading…
Add table
Reference in a new issue