Skip to content

Commit

Permalink
contractcourt: offer outgoing htlc one block earlier before its expiry
Browse files Browse the repository at this point in the history
We need to offer the outgoing htlc one block earlier to make sure when
the expiry height hits, the sweeper will not miss sweeping it in the
same block. This also means the outgoing contest resolver now only does
one thing - watch for preimage spend till height expiry-1, which can
easily be moved into the timeout resolver instead in the future.
  • Loading branch information
yyforyongyu committed Dec 10, 2024
1 parent 1fee03d commit cebad6d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion contractcourt/htlc_outgoing_contest_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,14 @@ func (h *htlcOutgoingContestResolver) Resolve() (ContractResolver, error) {
// fail.
newHeight := uint32(newBlock.Height)
expiry := h.htlcResolution.Expiry
if newHeight >= expiry {

// Check if the expiry height is about to be reached.
// We offer this HTLC one block earlier to make sure
// when the next block arrives, the sweeper will pick
// up this input and sweep it immediately. The sweeper
// will handle the waiting for the one last block till
// expiry.
if newHeight >= expiry-1 {
h.log.Infof("HTLC about to expire "+
"(height=%v, expiry=%v), transforming "+
"into timeout resolver", h,
Expand Down

0 comments on commit cebad6d

Please sign in to comment.