mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-26 13:42:49 +02:00
itest: fix tests re the new anchor behavior
This commit is contained in:
@@ -978,15 +978,6 @@ func runChannelForceClosureTestRestart(ht *lntest.HarnessTest,
|
|||||||
Outpoint: commitSweep.Outpoint,
|
Outpoint: commitSweep.Outpoint,
|
||||||
AmountSat: uint64(aliceBalance),
|
AmountSat: uint64(aliceBalance),
|
||||||
}
|
}
|
||||||
op = fmt.Sprintf("%v:%v", anchorSweep.Outpoint.TxidStr,
|
|
||||||
anchorSweep.Outpoint.OutputIndex)
|
|
||||||
aliceReports[op] = &lnrpc.Resolution{
|
|
||||||
ResolutionType: lnrpc.ResolutionType_ANCHOR,
|
|
||||||
Outcome: lnrpc.ResolutionOutcome_CLAIMED,
|
|
||||||
SweepTxid: sweepTxid.String(),
|
|
||||||
Outpoint: anchorSweep.Outpoint,
|
|
||||||
AmountSat: uint64(anchorSweep.AmountSat),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that we can find the commitment sweep in our set of known
|
// Check that we can find the commitment sweep in our set of known
|
||||||
// sweeps, using the simple transaction id ListSweeps output.
|
// sweeps, using the simple transaction id ListSweeps output.
|
||||||
@@ -1101,8 +1092,9 @@ func runChannelForceClosureTestRestart(ht *lntest.HarnessTest,
|
|||||||
|
|
||||||
// Since Alice had numInvoices (6) htlcs extended to Carol before force
|
// Since Alice had numInvoices (6) htlcs extended to Carol before force
|
||||||
// closing, we expect Alice to broadcast an htlc timeout txn for each
|
// closing, we expect Alice to broadcast an htlc timeout txn for each
|
||||||
// one.
|
// one. In addition, the anchor input is still pending due to it's
|
||||||
ht.AssertNumPendingSweeps(alice, numInvoices)
|
// uneconomical to sweep.
|
||||||
|
ht.AssertNumPendingSweeps(alice, numInvoices+1)
|
||||||
|
|
||||||
// Wait for them all to show up in the mempool
|
// Wait for them all to show up in the mempool
|
||||||
htlcTxid := ht.AssertNumTxsInMempool(1)[0]
|
htlcTxid := ht.AssertNumTxsInMempool(1)[0]
|
||||||
@@ -1198,7 +1190,9 @@ func runChannelForceClosureTestRestart(ht *lntest.HarnessTest,
|
|||||||
numBlocks := int(htlcCsvMaturityHeight - uint32(curHeight) - 1)
|
numBlocks := int(htlcCsvMaturityHeight - uint32(curHeight) - 1)
|
||||||
ht.MineEmptyBlocks(numBlocks)
|
ht.MineEmptyBlocks(numBlocks)
|
||||||
|
|
||||||
ht.AssertNumPendingSweeps(alice, numInvoices)
|
// We should see numInvoices HTLC sweeps plus the uneconomical anchor
|
||||||
|
// sweep.
|
||||||
|
ht.AssertNumPendingSweeps(alice, numInvoices+1)
|
||||||
|
|
||||||
// Fetch the htlc sweep transaction from the mempool.
|
// Fetch the htlc sweep transaction from the mempool.
|
||||||
htlcSweepTx := ht.GetNumTxsFromMempool(1)[0]
|
htlcSweepTx := ht.GetNumTxsFromMempool(1)[0]
|
||||||
@@ -1220,7 +1214,7 @@ func runChannelForceClosureTestRestart(ht *lntest.HarnessTest,
|
|||||||
}, defaultTimeout)
|
}, defaultTimeout)
|
||||||
require.NoError(ht, err, "timeout while checking force closed channel")
|
require.NoError(ht, err, "timeout while checking force closed channel")
|
||||||
|
|
||||||
ht.AssertNumPendingSweeps(alice, numInvoices)
|
ht.AssertNumPendingSweeps(alice, numInvoices+1)
|
||||||
|
|
||||||
// Ensure the htlc sweep transaction only has one input for each htlc
|
// Ensure the htlc sweep transaction only has one input for each htlc
|
||||||
// Alice extended before force closing.
|
// Alice extended before force closing.
|
||||||
|
@@ -1224,8 +1224,8 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
|
|||||||
// 4. Alice force closes the channel.
|
// 4. Alice force closes the channel.
|
||||||
//
|
//
|
||||||
// Test:
|
// Test:
|
||||||
// 1. Alice's anchor sweeping is not attempted, instead, it should be swept
|
// 1. Alice's CPFP-anchor sweeping is not attempted, instead, it should be
|
||||||
// together with her to_local output using the no deadline path.
|
// swept using the no deadline path and failed due it's not economical.
|
||||||
// 2. Bob would also sweep his anchor and to_local outputs separately due to
|
// 2. Bob would also sweep his anchor and to_local outputs separately due to
|
||||||
// they have different deadline heights, which means only the to_local
|
// they have different deadline heights, which means only the to_local
|
||||||
// sweeping tx will succeed as the anchor sweeping is not economical.
|
// sweeping tx will succeed as the anchor sweeping is not economical.
|
||||||
@@ -1241,10 +1241,15 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
|
|||||||
// config.
|
// config.
|
||||||
deadline := uint32(1000)
|
deadline := uint32(1000)
|
||||||
|
|
||||||
// deadlineA is the deadline used for Alice, since her commit output is
|
// deadlineA is the deadline used for Alice, given that,
|
||||||
// offered to the sweeper at CSV-1. With a deadline of 1000, her actual
|
// - the force close tx is broadcast at height 445, her inputs are
|
||||||
// width of her fee func is CSV+1000-1. Given we are using a CSV of 2
|
// registered at the same height, so her to_local and anchor outputs
|
||||||
// here, her fee func deadline then becomes 1001.
|
// have a deadline height of 1445.
|
||||||
|
// - the force close tx is mined at 446, which means her anchor output
|
||||||
|
// now has a deadline delta of (1445-446) = 999 blocks.
|
||||||
|
// - for her to_local output, with a deadline of 1000, the width of the
|
||||||
|
// fee func is CSV+1000-1. Given we are using a CSV of 2 here, her fee
|
||||||
|
// func deadline then becomes 1001.
|
||||||
deadlineA := deadline + 1
|
deadlineA := deadline + 1
|
||||||
|
|
||||||
// deadlineB is the deadline used for Bob, the actual deadline used by
|
// deadlineB is the deadline used for Bob, the actual deadline used by
|
||||||
@@ -1267,6 +1272,11 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
|
|||||||
// conf target is the deadline.
|
// conf target is the deadline.
|
||||||
ht.SetFeeEstimateWithConf(startFeeRate, deadlineB)
|
ht.SetFeeEstimateWithConf(startFeeRate, deadlineB)
|
||||||
|
|
||||||
|
// Set up the starting fee for Alice's anchor sweeping. With this low
|
||||||
|
// fee rate, her anchor sweeping should be attempted and failed due to
|
||||||
|
// dust output generated in the sweeping tx.
|
||||||
|
ht.SetFeeEstimateWithConf(startFeeRate, deadline-1)
|
||||||
|
|
||||||
// toLocalCSV is the CSV delay for Alice's to_local output. We use a
|
// toLocalCSV is the CSV delay for Alice's to_local output. We use a
|
||||||
// small value to save us from mining blocks.
|
// small value to save us from mining blocks.
|
||||||
//
|
//
|
||||||
@@ -1427,10 +1437,10 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
|
|||||||
// With Alice's starting fee rate being validated, we now calculate her
|
// With Alice's starting fee rate being validated, we now calculate her
|
||||||
// ending fee rate and fee rate delta.
|
// ending fee rate and fee rate delta.
|
||||||
//
|
//
|
||||||
// Alice sweeps two inputs - anchor and commit, so the starting budget
|
// Alice sweeps the to_local input, so the starting budget should come
|
||||||
// should come from the sum of these two. However, due to the value
|
// from the to_local balance. However, due to the value being too large,
|
||||||
// being too large, the actual ending fee rate used should be the
|
// the actual ending fee rate used should be the sweeper's max fee rate
|
||||||
// sweeper's max fee rate configured.
|
// configured.
|
||||||
aliceTxWeight := uint64(ht.CalculateTxWeight(aliceSweepTx))
|
aliceTxWeight := uint64(ht.CalculateTxWeight(aliceSweepTx))
|
||||||
aliceEndingFeeRate := sweep.DefaultMaxFeeRate.FeePerKWeight()
|
aliceEndingFeeRate := sweep.DefaultMaxFeeRate.FeePerKWeight()
|
||||||
aliceFeeRateDelta := (aliceEndingFeeRate - aliceStartingFeeRate) /
|
aliceFeeRateDelta := (aliceEndingFeeRate - aliceStartingFeeRate) /
|
||||||
@@ -1507,10 +1517,10 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We should see two txns in the mempool:
|
// We should see two txns in the mempool:
|
||||||
// - Alice's sweeping tx, which sweeps both her anchor and
|
// - Alice's sweeping tx, which sweeps her commit output, using
|
||||||
// commit outputs, using the increased fee rate.
|
// the increased fee rate.
|
||||||
// - Bob's previous sweeping tx, which sweeps both his anchor
|
// - Bob's previous sweeping tx, which sweeps his commit output,
|
||||||
// and commit outputs, at the possible increased fee rate.
|
// at the possible increased fee rate.
|
||||||
txns := ht.GetNumTxsFromMempool(2)
|
txns := ht.GetNumTxsFromMempool(2)
|
||||||
|
|
||||||
// Assume the first tx is Alice's sweeping tx, if the second tx
|
// Assume the first tx is Alice's sweeping tx, if the second tx
|
||||||
@@ -1577,6 +1587,11 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
|
|||||||
// Mine a block to confirm both sweeping txns, this is needed to clean
|
// Mine a block to confirm both sweeping txns, this is needed to clean
|
||||||
// up the mempool.
|
// up the mempool.
|
||||||
ht.MineBlocksAndAssertNumTxes(1, 2)
|
ht.MineBlocksAndAssertNumTxes(1, 2)
|
||||||
|
|
||||||
|
// Finally, assert that both Alice and Bob still have the anchor
|
||||||
|
// outputs, which cannot be swept due to it being uneconomical.
|
||||||
|
ht.AssertNumPendingSweeps(alice, 1)
|
||||||
|
ht.AssertNumPendingSweeps(bob, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// testBumpForceCloseFee tests that when a force close transaction, in
|
// testBumpForceCloseFee tests that when a force close transaction, in
|
||||||
|
Reference in New Issue
Block a user