Skip to content

Commit 67c5fa9

Browse files
authored
Merge pull request #8946 from ziggie1984/fix-bumpforceclose-behaviour
Fix bumpforceclose behavior for force closes without htlcs.
2 parents 7f9fbbe + da7b95d commit 67c5fa9

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

contractcourt/channel_arbitrator.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ const (
4040
// arbitratorBlockBufferSize is the size of the buffer we give to each
4141
// channel arbitrator.
4242
arbitratorBlockBufferSize = 20
43+
44+
// AnchorOutputValue is the output value for the anchor output of an
45+
// anchor channel.
46+
// See BOLT 03 for more details:
47+
// https://github.com/lightning/bolts/blob/master/03-transactions.md
48+
AnchorOutputValue = btcutil.Amount(330)
4349
)
4450

4551
// WitnessSubscription represents an intent to be notified once new witnesses
@@ -1313,13 +1319,14 @@ func (c *ChannelArbitrator) sweepAnchors(anchors *lnwallet.AnchorResolutions,
13131319
}
13141320

13151321
// If we cannot find a deadline, it means there's no HTLCs at
1316-
// stake, which means we can relax our anchor sweeping as we
1317-
// don't have any time sensitive outputs to sweep.
1322+
// stake, which means we can relax our anchor sweeping
1323+
// conditions as we don't have any time sensitive outputs to
1324+
// sweep. However we need to register the anchor output with the
1325+
// sweeper so we are later able to bump the close fee.
13181326
if deadline.IsNone() {
13191327
log.Infof("ChannelArbitrator(%v): no HTLCs at stake, "+
1320-
"skipped anchor CPFP", c.cfg.ChanPoint)
1321-
1322-
return nil
1328+
"sweeping anchor with default deadline",
1329+
c.cfg.ChanPoint)
13231330
}
13241331

13251332
witnessType := input.CommitmentAnchor
@@ -1357,10 +1364,13 @@ func (c *ChannelArbitrator) sweepAnchors(anchors *lnwallet.AnchorResolutions,
13571364
// Calculate the budget based on the value under protection,
13581365
// which is the sum of all HTLCs on this commitment subtracted
13591366
// by their budgets.
1367+
// The anchor output in itself has a small output value of 330
1368+
// sats so we also include it in the budget to pay for the
1369+
// cpfp transaction.
13601370
budget := calculateBudget(
13611371
value, c.cfg.Budget.AnchorCPFPRatio,
13621372
c.cfg.Budget.AnchorCPFP,
1363-
)
1373+
) + AnchorOutputValue
13641374

13651375
log.Infof("ChannelArbitrator(%v): offering anchor from %s "+
13661376
"commitment %v to sweeper with deadline=%v, budget=%v",

docs/release-notes/release-notes-0.18.3.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
* The fee limit for payments [was made
4040
compatible](https://github.com/lightningnetwork/lnd/pull/8941) with inbound
4141
fees.
42+
43+
* [Fixed](https://github.com/lightningnetwork/lnd/pull/8946) a case where
44+
bumping an anchor channel closing was not possible when no HTLCs were on the
45+
commitment when the channel was force closed.
4246

4347
# New Features
4448
## Functional Enhancements

itest/lnd_sweep_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {
7373
htlcBudget := htlcValue.MulF64(contractcourt.DefaultBudgetRatio)
7474

7575
// cpfpBudget is the budget used to sweep the CPFP anchor.
76+
// In addition to the htlc amount to protect we also need to include
77+
// the anchor amount itself for the budget.
7678
cpfpBudget := (htlcValue - htlcBudget).MulF64(
7779
contractcourt.DefaultBudgetRatio,
78-
)
80+
) + contractcourt.AnchorOutputValue
7981

8082
// Create a preimage, that will be held by Carol.
8183
var preimage lntypes.Preimage
@@ -488,9 +490,11 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
488490
htlcBudget := htlcValue.MulF64(contractcourt.DefaultBudgetRatio)
489491

490492
// cpfpBudget is the budget used to sweep the CPFP anchor.
493+
// In addition to the htlc amount to protect we also need to include
494+
// the anchor amount itself for the budget.
491495
cpfpBudget := (htlcValue - htlcBudget).MulF64(
492496
contractcourt.DefaultBudgetRatio,
493-
)
497+
) + contractcourt.AnchorOutputValue
494498

495499
// Carol should have one incoming HTLC on channel Bob -> Carol.
496500
ht.AssertIncomingHTLCActive(carol, bcChanPoint, payHash[:])
@@ -1342,9 +1346,13 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
13421346
// PendingChannels RPC under the waiting close section.
13431347
ht.AssertChannelWaitingClose(alice, chanPoint)
13441348

1345-
// We should see neither Alice or Bob has any pending sweeps as there
1346-
// are no time-sensitive HTLCs.
1347-
ht.AssertNumPendingSweeps(alice, 0)
1349+
// Alice should see 2 anchor sweeps for the local and remote commitment.
1350+
// Even without HTLCs at stake the anchors are registered with the
1351+
// sweeper subsytem.
1352+
ht.AssertNumPendingSweeps(alice, 2)
1353+
1354+
// Bob did not force close the channel therefore he should have no
1355+
// pending sweeps.
13481356
ht.AssertNumPendingSweeps(bob, 0)
13491357

13501358
// Mine a block to confirm Alice's force closing tx. Once it's

0 commit comments

Comments
 (0)