Skip to content

Commit 3da4093

Browse files
committed
itest: fix tests re the new anchor behavior
1 parent 5ee54b3 commit 3da4093

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

itest/lnd_channel_force_close_test.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -978,15 +978,6 @@ func runChannelForceClosureTestRestart(ht *lntest.HarnessTest,
978978
Outpoint: commitSweep.Outpoint,
979979
AmountSat: uint64(aliceBalance),
980980
}
981-
op = fmt.Sprintf("%v:%v", anchorSweep.Outpoint.TxidStr,
982-
anchorSweep.Outpoint.OutputIndex)
983-
aliceReports[op] = &lnrpc.Resolution{
984-
ResolutionType: lnrpc.ResolutionType_ANCHOR,
985-
Outcome: lnrpc.ResolutionOutcome_CLAIMED,
986-
SweepTxid: sweepTxid.String(),
987-
Outpoint: anchorSweep.Outpoint,
988-
AmountSat: uint64(anchorSweep.AmountSat),
989-
}
990981

991982
// Check that we can find the commitment sweep in our set of known
992983
// sweeps, using the simple transaction id ListSweeps output.
@@ -1101,8 +1092,9 @@ func runChannelForceClosureTestRestart(ht *lntest.HarnessTest,
11011092

11021093
// Since Alice had numInvoices (6) htlcs extended to Carol before force
11031094
// closing, we expect Alice to broadcast an htlc timeout txn for each
1104-
// one.
1105-
ht.AssertNumPendingSweeps(alice, numInvoices)
1095+
// one. In addition, the anchor input is still pending due to it's
1096+
// uneconomical to sweep.
1097+
ht.AssertNumPendingSweeps(alice, numInvoices+1)
11061098

11071099
// Wait for them all to show up in the mempool
11081100
htlcTxid := ht.AssertNumTxsInMempool(1)[0]
@@ -1198,7 +1190,9 @@ func runChannelForceClosureTestRestart(ht *lntest.HarnessTest,
11981190
numBlocks := int(htlcCsvMaturityHeight - uint32(curHeight) - 1)
11991191
ht.MineEmptyBlocks(numBlocks)
12001192

1201-
ht.AssertNumPendingSweeps(alice, numInvoices)
1193+
// We should see numInvoices HTLC sweeps plus the uneconomical anchor
1194+
// sweep.
1195+
ht.AssertNumPendingSweeps(alice, numInvoices+1)
12021196

12031197
// Fetch the htlc sweep transaction from the mempool.
12041198
htlcSweepTx := ht.GetNumTxsFromMempool(1)[0]
@@ -1220,7 +1214,7 @@ func runChannelForceClosureTestRestart(ht *lntest.HarnessTest,
12201214
}, defaultTimeout)
12211215
require.NoError(ht, err, "timeout while checking force closed channel")
12221216

1223-
ht.AssertNumPendingSweeps(alice, numInvoices)
1217+
ht.AssertNumPendingSweeps(alice, numInvoices+1)
12241218

12251219
// Ensure the htlc sweep transaction only has one input for each htlc
12261220
// Alice extended before force closing.

itest/lnd_sweep_test.go

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,8 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
12241224
// 4. Alice force closes the channel.
12251225
//
12261226
// Test:
1227-
// 1. Alice's anchor sweeping is not attempted, instead, it should be swept
1228-
// together with her to_local output using the no deadline path.
1227+
// 1. Alice's CPFP-anchor sweeping is not attempted, instead, it should be
1228+
// swept using the no deadline path and failed due it's not economical.
12291229
// 2. Bob would also sweep his anchor and to_local outputs separately due to
12301230
// they have different deadline heights, which means only the to_local
12311231
// sweeping tx will succeed as the anchor sweeping is not economical.
@@ -1241,10 +1241,15 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
12411241
// config.
12421242
deadline := uint32(1000)
12431243

1244-
// deadlineA is the deadline used for Alice, since her commit output is
1245-
// offered to the sweeper at CSV-1. With a deadline of 1000, her actual
1246-
// width of her fee func is CSV+1000-1. Given we are using a CSV of 2
1247-
// here, her fee func deadline then becomes 1001.
1244+
// deadlineA is the deadline used for Alice, given that,
1245+
// - the force close tx is broadcast at height 445, her inputs are
1246+
// registered at the same height, so her to_local and anchor outputs
1247+
// have a deadline height of 1445.
1248+
// - the force close tx is mined at 446, which means her anchor output
1249+
// now has a deadline delta of (1445-446) = 999 blocks.
1250+
// - for her to_local output, with a deadline of 1000, the width of the
1251+
// fee func is CSV+1000-1. Given we are using a CSV of 2 here, her fee
1252+
// func deadline then becomes 1001.
12481253
deadlineA := deadline + 1
12491254

12501255
// deadlineB is the deadline used for Bob, the actual deadline used by
@@ -1267,6 +1272,11 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
12671272
// conf target is the deadline.
12681273
ht.SetFeeEstimateWithConf(startFeeRate, deadlineB)
12691274

1275+
// Set up the starting fee for Alice's anchor sweeping. With this low
1276+
// fee rate, her anchor sweeping should be attempted and failed due to
1277+
// dust output generated in the sweeping tx.
1278+
ht.SetFeeEstimateWithConf(startFeeRate, deadline-1)
1279+
12701280
// toLocalCSV is the CSV delay for Alice's to_local output. We use a
12711281
// small value to save us from mining blocks.
12721282
//
@@ -1427,10 +1437,10 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
14271437
// With Alice's starting fee rate being validated, we now calculate her
14281438
// ending fee rate and fee rate delta.
14291439
//
1430-
// Alice sweeps two inputs - anchor and commit, so the starting budget
1431-
// should come from the sum of these two. However, due to the value
1432-
// being too large, the actual ending fee rate used should be the
1433-
// sweeper's max fee rate configured.
1440+
// Alice sweeps the to_local input, so the starting budget should come
1441+
// from the to_local balance. However, due to the value being too large,
1442+
// the actual ending fee rate used should be the sweeper's max fee rate
1443+
// configured.
14341444
aliceTxWeight := uint64(ht.CalculateTxWeight(aliceSweepTx))
14351445
aliceEndingFeeRate := sweep.DefaultMaxFeeRate.FeePerKWeight()
14361446
aliceFeeRateDelta := (aliceEndingFeeRate - aliceStartingFeeRate) /
@@ -1507,10 +1517,10 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
15071517
}
15081518

15091519
// We should see two txns in the mempool:
1510-
// - Alice's sweeping tx, which sweeps both her anchor and
1511-
// commit outputs, using the increased fee rate.
1512-
// - Bob's previous sweeping tx, which sweeps both his anchor
1513-
// and commit outputs, at the possible increased fee rate.
1520+
// - Alice's sweeping tx, which sweeps her commit output, using
1521+
// the increased fee rate.
1522+
// - Bob's previous sweeping tx, which sweeps his commit output,
1523+
// at the possible increased fee rate.
15141524
txns := ht.GetNumTxsFromMempool(2)
15151525

15161526
// Assume the first tx is Alice's sweeping tx, if the second tx
@@ -1577,6 +1587,11 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
15771587
// Mine a block to confirm both sweeping txns, this is needed to clean
15781588
// up the mempool.
15791589
ht.MineBlocksAndAssertNumTxes(1, 2)
1590+
1591+
// Finally, assert that both Alice and Bob still have the anchor
1592+
// outputs, which cannot be swept due to it being uneconomical.
1593+
ht.AssertNumPendingSweeps(alice, 1)
1594+
ht.AssertNumPendingSweeps(bob, 1)
15801595
}
15811596

15821597
// testBumpForceCloseFee tests that when a force close transaction, in

0 commit comments

Comments
 (0)