Skip to content

Commit 5259236

Browse files
committed
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-Changed onchaind: When sweeping funds from channel closes we now use an absolute deadline of 2 weeks, rather than a relative deadline which causes sweeps not confirm for prolonged times.
1 parent e6d5334 commit 5259236

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

lightningd/onchain_control.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,44 @@ static u32 infinite_block_deadline(const struct chain_topology *topo)
518518
return get_block_height(topo) + 300;
519519
}
520520

521+
/**
522+
* slow_sweep_dealine -- A smart(-ish) way of estimating sweep fees.
523+
*
524+
* We use the `close_blockheight` as the basis for the target. We then
525+
* target to have the funds back at most 2 weeks after the close,
526+
* linearly increasing the confirmation target until we get
527+
* close. However, we also don't want to panic and set a target that
528+
* is too close, in order not to waste too many funds on the sweep
529+
* fees.
530+
*/
531+
static u32 slow_sweep_deadline(const struct chain_topology *topo, const struct channel *channel)
532+
{
533+
u32 deadline, height = get_block_height(topo);
534+
u32 closeheight =
535+
channel->close_blockheight ? *channel->close_blockheight : 0;
536+
if (closeheight == 0)
537+
return get_block_height(topo) + 300;
538+
539+
/* A two week deadline seems like a not too bad default. We
540+
* should likely tweak this to hit the desired cost vs. idle
541+
* time tradeoff. */
542+
deadline = closeheight + 2016;
543+
544+
/* If we missed the deadline, don't panic, let's continue with
545+
* a somewhat reasonable target, and hope for the best. No
546+
* need to ramp up to confirmation target 1, we're supposed to
547+
* be slow. */
548+
if (deadline < height + 12)
549+
return height + 12;
550+
551+
/* At the same time don't be too lenient, we want this to
552+
* confirm and not just idle around forever. */
553+
if (deadline - height > 300)
554+
return height + 300;
555+
556+
return deadline;
557+
}
558+
521559
static struct onchain_signing_info *new_signing_info(const tal_t *ctx,
522560
struct channel *channel,
523561
enum onchaind_wire msgtype)
@@ -1104,7 +1142,8 @@ static void handle_onchaind_spend_to_us(struct channel *channel,
11041142
}
11051143

11061144
/* No real deadline on this, it's just returning to our wallet. */
1107-
info->deadline_block = infinite_block_deadline(channel->peer->ld->topology);
1145+
info->deadline_block =
1146+
slow_sweep_deadline(channel->peer->ld->topology, channel);
11081147
create_onchain_tx(channel, &out, out_sats,
11091148
channel->channel_info.their_config.to_self_delay, 0,
11101149
sign_tx_to_us, info,

0 commit comments

Comments
 (0)