mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-12 18:49:42 +01:00
onchaind: Adjust the sweep target deadline for fee estimation
We used to always target `now() + 300`, which ends up never really confirming, as the fee estimate bumps into the min-relay-fee limit. With this commit we set an absolute target of 2 weeks, and a linear fee rampup, until we are at T-2h, at which point we just stick with the estimate, and try with this increased feerate to try and get the sweep confirmed. This ought to make RBF transactions much more efficient for closing channels. Changelog-Fixed onchaind: The sweep deadline for to_us outputs would be reset on each restart of the subdaemon. Now the deadline is absolute in terms of the close height.
This commit is contained in:
parent
46dcc6e031
commit
8c14c39c7e
1 changed files with 47 additions and 1 deletions
|
@ -518,6 +518,51 @@ static u32 infinite_block_deadline(const struct chain_topology *topo)
|
|||
return get_block_height(topo) + 300;
|
||||
}
|
||||
|
||||
/**
|
||||
* slow_sweep_dealine -- A smart(-ish) way of estimating sweep fees.
|
||||
*
|
||||
* We use the `close_blockheight` as the basis for the target. We then
|
||||
* target to have the funds back at most 2 weeks after the close,
|
||||
* linearly increasing the confirmation target until we get
|
||||
* close. However, we also don't want to panic and set a target that
|
||||
* is too close, in order not to waste too many funds on the sweep
|
||||
* fees.
|
||||
*/
|
||||
static u32 slow_sweep_deadline(const struct chain_topology *topo,
|
||||
const struct channel *c)
|
||||
{
|
||||
u32 closeheight, deadline, height = get_block_height(topo);
|
||||
|
||||
if (c->close_blockheight) {
|
||||
closeheight = *c->close_blockheight;
|
||||
} else {
|
||||
log_unusual(c->log,
|
||||
"Missing close_blockheight? Using current height "
|
||||
"+ 300 = %d",
|
||||
height + 300);
|
||||
return height + 300;
|
||||
}
|
||||
|
||||
/* A two week deadline seems like a not too bad default. We
|
||||
* should likely tweak this to hit the desired cost vs. idle
|
||||
* time tradeoff. */
|
||||
deadline = closeheight + 2016;
|
||||
|
||||
/* If we missed the deadline, don't panic, let's continue with
|
||||
* a somewhat reasonable target, and hope for the best. No
|
||||
* need to ramp up to confirmation target 1, we're supposed to
|
||||
* be slow. */
|
||||
if (deadline < height + 12)
|
||||
return height + 12;
|
||||
|
||||
/* At the same time don't be too lenient, we want this to
|
||||
* confirm and not just idle around forever. */
|
||||
if (deadline > height + 300)
|
||||
return height + 300;
|
||||
|
||||
return deadline;
|
||||
}
|
||||
|
||||
static struct onchain_signing_info *new_signing_info(const tal_t *ctx,
|
||||
struct channel *channel,
|
||||
enum onchaind_wire msgtype)
|
||||
|
@ -1104,7 +1149,8 @@ static void handle_onchaind_spend_to_us(struct channel *channel,
|
|||
}
|
||||
|
||||
/* No real deadline on this, it's just returning to our wallet. */
|
||||
info->deadline_block = infinite_block_deadline(channel->peer->ld->topology);
|
||||
info->deadline_block =
|
||||
slow_sweep_deadline(channel->peer->ld->topology, channel);
|
||||
create_onchain_tx(channel, &out, out_sats,
|
||||
channel->channel_info.their_config.to_self_delay, 0,
|
||||
sign_tx_to_us, info,
|
||||
|
|
Loading…
Add table
Reference in a new issue