Skip to content

Commit f21e3f3

Browse files
authored
Merge pull request #9772 from yyforyongyu/show-all-inputs
sweep: return all inputs in `PendingSweeps`
2 parents b34afa3 + b610678 commit f21e3f3

15 files changed

+665
-515
lines changed

cmd/commands/walletrpc_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
44

55
// PendingSweep is a CLI-friendly type of the walletrpc.PendingSweep proto. We
66
// use this to show more useful string versions of byte slices and enums.
7+
//
8+
// TODO(yy): Remove this struct as it's easy to forget to update the values
9+
// here. Instead, we should rely on the struct defined in the proto
10+
// `PendingSweepsResponse` only.
711
type PendingSweep struct {
812
OutPoint OutPoint `json:"outpoint"`
913
WitnessType string `json:"witness_type"`
@@ -14,6 +18,7 @@ type PendingSweep struct {
1418
Immediate bool `json:"immediate"`
1519
Budget uint64 `json:"budget"`
1620
DeadlineHeight uint32 `json:"deadline_height"`
21+
MaturityHeight uint32 `json:"maturity_height"`
1722

1823
NextBroadcastHeight uint32 `json:"next_broadcast_height"`
1924
RequestedConfTarget uint32 `json:"requested_conf_target"`
@@ -33,6 +38,7 @@ func NewPendingSweepFromProto(pendingSweep *walletrpc.PendingSweep) *PendingSwee
3338
Immediate: pendingSweep.Immediate,
3439
Budget: pendingSweep.Budget,
3540
DeadlineHeight: pendingSweep.DeadlineHeight,
41+
MaturityHeight: pendingSweep.MaturityHeight,
3642

3743
// Deprecated fields.
3844
NextBroadcastHeight: pendingSweep.NextBroadcastHeight,

docs/release-notes/release-notes-0.19.0.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,15 @@ when running LND with an aux component injected (custom channels).
316316
to include any [gRPC metadata](https://grpc.io/docs/guides/metadata) pairs
317317
that are passed to the initial request via the `context.Context`.
318318

319+
* Previously when calling `PendingSweeps`, if the outputs being swept had a
320+
locktime in the future, they would be filtered out. This is now
321+
[changed](https://github.com/lightningnetwork/lnd/pull/9772) such that all
322+
outputs registered in the sweeper will be returned in the RPC response
323+
regardless of their locktime, which enables users to plan ahead about upcoming
324+
sweeps and implement customized aggregation logic. A new field
325+
`MaturityHeight` is added to `PendingSweep` to show the absolute locktime
326+
value.
327+
319328
## lncli Updates
320329

321330
* [Fixed](https://github.com/lightningnetwork/lnd/pull/9605) a case where

itest/lnd_channel_backup_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ func assertTimeLockSwept(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,
14541454
// Carol should sweep her funds immediately, as they are not
14551455
// timelocked.
14561456
ht.AssertNumPendingSweeps(carol, 2)
1457-
ht.AssertNumPendingSweeps(dave, 1)
1457+
ht.AssertNumPendingSweeps(dave, 2)
14581458

14591459
// We expect Carol to sweep her funds and her anchor in a single sweep
14601460
// tx. In addition, Dave will attempt to sweep his anchor output but
@@ -1577,9 +1577,10 @@ func assertDLPExecuted(ht *lntest.HarnessTest,
15771577

15781578
// Both Dave and Carol should have an anchor sweep request.
15791579
// Note that they cannot sweep them as these anchor sweepings
1580-
// are uneconomical.
1581-
ht.AssertNumPendingSweeps(dave, 1)
1582-
ht.AssertNumPendingSweeps(carol, 1)
1580+
// are uneconomical. In addition, they should also have their
1581+
// leased to_local commit output.
1582+
ht.AssertNumPendingSweeps(dave, 2)
1583+
ht.AssertNumPendingSweeps(carol, 2)
15831584

15841585
// After Carol's output matures, she should also reclaim her
15851586
// funds.
@@ -1620,7 +1621,7 @@ func assertDLPExecuted(ht *lntest.HarnessTest,
16201621
// timelocked. We also expect Carol and Dave sweep their
16211622
// anchors if it's an anchor channel.
16221623
if lntest.CommitTypeHasAnchors(commitType) {
1623-
ht.AssertNumPendingSweeps(carol, 1)
1624+
ht.AssertNumPendingSweeps(carol, 2)
16241625
ht.AssertNumPendingSweeps(dave, 2)
16251626
} else {
16261627
ht.AssertNumPendingSweeps(dave, 1)

itest/lnd_channel_force_close_test.go

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,18 @@ func runChannelForceClosureTest(ht *lntest.HarnessTest,
191191
// expect Alice's anchor sweeping tx being published.
192192
ht.MineBlocksAndAssertNumTxes(1, 1)
193193

194-
// Assert Alice's has one pending anchor output - because she doesn't
195-
// have incoming HTLCs, her outgoing HTLC won't have a deadline, thus
196-
// she won't use the anchor to perform CPFP.
197-
aliceAnchor := ht.AssertNumPendingSweeps(alice, 1)[0]
194+
// Assert Alice's has one pending anchor output and the commit output
195+
// sweep - because she doesn't have incoming HTLCs, her outgoing HTLC
196+
// won't have a deadline, thus she won't use the anchor to perform CPFP.
197+
sweeps := ht.AssertNumPendingSweeps(alice, 2)
198+
199+
// Find the anchor sweep - assume it's the first one, and change to the
200+
// second one if the first one has a larger value.
201+
aliceAnchor := sweeps[0]
202+
if aliceAnchor.AmountSat > sweeps[1].AmountSat {
203+
aliceAnchor = sweeps[1]
204+
}
205+
198206
require.Equal(ht, aliceAnchor.Outpoint.TxidStr,
199207
waitingClose.Commitments.LocalTxid)
200208

@@ -250,8 +258,9 @@ func runChannelForceClosureTest(ht *lntest.HarnessTest,
250258
// commit and anchor outputs.
251259
ht.MineBlocksAndAssertNumTxes(1, 1)
252260

253-
// Alice should still have the anchor sweeping request.
254-
ht.AssertNumPendingSweeps(alice, 1)
261+
// Alice should still have the anchor and commit output sweeping
262+
// requests.
263+
ht.AssertNumPendingSweeps(alice, 2)
255264

256265
// Alice should see the channel in her set of pending force closed
257266
// channels with her funds still in limbo.
@@ -282,8 +291,8 @@ func runChannelForceClosureTest(ht *lntest.HarnessTest,
282291

283292
// At this point, the CSV will expire in the next block, meaning that
284293
// the output should be offered to the sweeper.
285-
sweeps := ht.AssertNumPendingSweeps(alice, 2)
286-
commitSweep, anchorSweep := sweeps[0], sweeps[1]
294+
aliceSweeps := ht.AssertNumPendingSweeps(alice, 2)
295+
commitSweep, anchorSweep := aliceSweeps[0], aliceSweeps[1]
287296
if commitSweep.AmountSat < anchorSweep.AmountSat {
288297
commitSweep = anchorSweep
289298
}
@@ -790,10 +799,18 @@ func runChannelForceClosureTestRestart(ht *lntest.HarnessTest,
790799
// expect Alice's anchor sweeping tx being published.
791800
ht.MineBlocksAndAssertNumTxes(1, 1)
792801

793-
// Assert Alice's has one pending anchor output - because she doesn't
794-
// have incoming HTLCs, her outgoing HTLC won't have a deadline, thus
795-
// she won't use the anchor to perform CPFP.
796-
aliceAnchor := ht.AssertNumPendingSweeps(alice, 1)[0]
802+
// Assert Alice's has one pending anchor output and the commit output
803+
// sweep - because she doesn't have incoming HTLCs, her outgoing HTLC
804+
// won't have a deadline, thus she won't use the anchor to perform CPFP.
805+
sweeps := ht.AssertNumPendingSweeps(alice, 2)
806+
807+
// Find the anchor sweep - assume it's the first one, and change to the
808+
// second one if the first one has a larger value.
809+
aliceAnchor := sweeps[0]
810+
if aliceAnchor.AmountSat > sweeps[1].AmountSat {
811+
aliceAnchor = sweeps[1]
812+
}
813+
797814
require.Equal(ht, aliceAnchor.Outpoint.TxidStr,
798815
waitingClose.Commitments.LocalTxid)
799816

@@ -860,8 +877,9 @@ func runChannelForceClosureTestRestart(ht *lntest.HarnessTest,
860877
// commit and anchor outputs.
861878
ht.MineBlocksAndAssertNumTxes(1, 1)
862879

863-
// Alice should still have the anchor sweeping request.
864-
ht.AssertNumPendingSweeps(alice, 1)
880+
// Alice should still have the anchor and commit output sweeping
881+
// requests.
882+
ht.AssertNumPendingSweeps(alice, 2)
865883

866884
// The following restart checks to ensure that outputs in the contract
867885
// court are persisted while waiting for the required number of
@@ -918,7 +936,7 @@ func runChannelForceClosureTestRestart(ht *lntest.HarnessTest,
918936

919937
// At this point, the CSV will expire in the next block, meaning that
920938
// the output should be offered to the sweeper.
921-
sweeps := ht.AssertNumPendingSweeps(alice, 2)
939+
sweeps = ht.AssertNumPendingSweeps(alice, 2)
922940
commitSweep, anchorSweep := sweeps[0], sweeps[1]
923941
if commitSweep.AmountSat < anchorSweep.AmountSat {
924942
commitSweep, anchorSweep = anchorSweep, commitSweep

itest/lnd_htlc_timeout_resolver_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,9 @@ func testHtlcTimeoutResolverExtractPreimageLocal(ht *lntest.HarnessTest) {
309309

310310
// Once Bob's force closing tx is confirmed, he will re-offer the
311311
// anchor output to his sweeper, which won't be swept due to it being
312-
// uneconomical.
313-
ht.AssertNumPendingSweeps(bob, 1)
312+
// uneconomical. In addition, the to_local output should also be found
313+
// although it's immature.
314+
ht.AssertNumPendingSweeps(bob, 2)
314315

315316
// Mine 3 blocks so the output will be offered to the sweeper.
316317
ht.MineBlocks(defaultCSV - 1)

0 commit comments

Comments
 (0)