mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-11 10:43:00 +02:00
itest: fix testSweepCPFPAnchorIncomingTimeout
This commit is contained in:
@@ -393,10 +393,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
|
|
||||||
// Set up the fee estimator to return the testing fee rate when the
|
// Set up the fee estimator to return the testing fee rate when the
|
||||||
// conf target is the deadline.
|
// conf target is the deadline.
|
||||||
//
|
ht.SetFeeEstimateWithConf(startFeeRateAnchor, deadlineDeltaAnchor)
|
||||||
// TODO(yy): switch to conf when `blockbeat` is in place.
|
|
||||||
// ht.SetFeeEstimateWithConf(startFeeRateAnchor, deadlineDeltaAnchor)
|
|
||||||
ht.SetFeeEstimate(startFeeRateAnchor)
|
|
||||||
|
|
||||||
// Create a preimage, that will be held by Carol.
|
// Create a preimage, that will be held by Carol.
|
||||||
var preimage lntypes.Preimage
|
var preimage lntypes.Preimage
|
||||||
@@ -513,40 +510,30 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
numBlocks := forceCloseHeight - currentHeight
|
numBlocks := forceCloseHeight - currentHeight
|
||||||
ht.MineEmptyBlocks(int(numBlocks))
|
ht.MineEmptyBlocks(int(numBlocks))
|
||||||
|
|
||||||
// Assert Bob's force closing tx has been broadcast.
|
// Assert Bob's force closing tx has been broadcast. We should see two
|
||||||
closeTxid := ht.AssertNumTxsInMempool(1)[0]
|
// txns in the mempool:
|
||||||
|
// 1. Bob's force closing tx.
|
||||||
|
// 2. Bob's anchor sweeping tx CPFPing the force close tx.
|
||||||
|
_, sweepTx := ht.AssertForceCloseAndAnchorTxnsInMempool()
|
||||||
|
|
||||||
// Bob should have two pending sweeps,
|
// Bob should have one pending sweep,
|
||||||
// - anchor sweeping from his local commitment.
|
// - anchor sweeping from his local commitment.
|
||||||
// - anchor sweeping from his remote commitment (invalid).
|
expectedNumSweeps := 1
|
||||||
sweeps := ht.AssertNumPendingSweeps(bob, 2)
|
|
||||||
|
|
||||||
// The two anchor sweeping should have the same deadline height.
|
// For neutrino backend, Bob would have two anchor sweeps - one from
|
||||||
|
// the local and the other from the remote.
|
||||||
|
if ht.IsNeutrinoBackend() {
|
||||||
|
expectedNumSweeps = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
anchorSweep := ht.AssertNumPendingSweeps(bob, expectedNumSweeps)[0]
|
||||||
|
|
||||||
|
// The anchor sweeping should have the expected deadline height.
|
||||||
deadlineHeight := forceCloseHeight + deadlineDeltaAnchor
|
deadlineHeight := forceCloseHeight + deadlineDeltaAnchor
|
||||||
require.Equal(ht, deadlineHeight, sweeps[0].DeadlineHeight)
|
require.Equal(ht, deadlineHeight, anchorSweep.DeadlineHeight)
|
||||||
require.Equal(ht, deadlineHeight, sweeps[1].DeadlineHeight)
|
|
||||||
|
|
||||||
// Remember the deadline height for the CPFP anchor.
|
// Remember the deadline height for the CPFP anchor.
|
||||||
anchorDeadline := sweeps[0].DeadlineHeight
|
anchorDeadline := anchorSweep.DeadlineHeight
|
||||||
|
|
||||||
// Mine a block so Bob's force closing tx stays in the mempool, which
|
|
||||||
// also triggers the CPFP anchor sweep.
|
|
||||||
ht.MineEmptyBlocks(1)
|
|
||||||
|
|
||||||
// Bob should still have two pending sweeps,
|
|
||||||
// - anchor sweeping from his local commitment.
|
|
||||||
// - anchor sweeping from his remote commitment (invalid).
|
|
||||||
ht.AssertNumPendingSweeps(bob, 2)
|
|
||||||
|
|
||||||
// We now check the expected fee and fee rate are used for Bob's anchor
|
|
||||||
// sweeping tx.
|
|
||||||
//
|
|
||||||
// We should see Bob's anchor sweeping tx triggered by the above
|
|
||||||
// block, along with his force close tx.
|
|
||||||
txns := ht.GetNumTxsFromMempool(2)
|
|
||||||
|
|
||||||
// Find the sweeping tx.
|
|
||||||
sweepTx := ht.FindSweepingTxns(txns, 1, closeTxid)[0]
|
|
||||||
|
|
||||||
// Get the weight for Bob's anchor sweeping tx.
|
// Get the weight for Bob's anchor sweeping tx.
|
||||||
txWeight := ht.CalculateTxWeight(sweepTx)
|
txWeight := ht.CalculateTxWeight(sweepTx)
|
||||||
@@ -558,11 +545,10 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
fee := uint64(ht.CalculateTxFee(sweepTx))
|
fee := uint64(ht.CalculateTxFee(sweepTx))
|
||||||
feeRate := uint64(ht.CalculateTxFeeRate(sweepTx))
|
feeRate := uint64(ht.CalculateTxFeeRate(sweepTx))
|
||||||
|
|
||||||
// feeFuncWidth is the width of the fee function. By the time we got
|
// feeFuncWidth is the width of the fee function. The fee function
|
||||||
// here, we've already mined one block, and the fee function maxes
|
// maxes out one block before the deadline, so the width is the
|
||||||
// out one block before the deadline, so the width is the original
|
// original deadline minus 1.
|
||||||
// deadline minus 2.
|
feeFuncWidth := deadlineDeltaAnchor - 1
|
||||||
feeFuncWidth := deadlineDeltaAnchor - 2
|
|
||||||
|
|
||||||
// Calculate the expected delta increased per block.
|
// Calculate the expected delta increased per block.
|
||||||
feeDelta := (cpfpBudget - startFeeAnchor).MulF64(
|
feeDelta := (cpfpBudget - startFeeAnchor).MulF64(
|
||||||
@@ -588,10 +574,15 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
// Bob's fee bumper should increase its fees.
|
// Bob's fee bumper should increase its fees.
|
||||||
ht.MineEmptyBlocks(1)
|
ht.MineEmptyBlocks(1)
|
||||||
|
|
||||||
// Bob should still have two pending sweeps,
|
// Bob should still have the anchor sweeping from his local
|
||||||
// - anchor sweeping from his local commitment.
|
// commitment. His anchor sweeping from his remote commitment
|
||||||
// - anchor sweeping from his remote commitment (invalid).
|
// is invalid and should be removed.
|
||||||
ht.AssertNumPendingSweeps(bob, 2)
|
ht.AssertNumPendingSweeps(bob, expectedNumSweeps)
|
||||||
|
|
||||||
|
// We expect to see two txns in the mempool,
|
||||||
|
// - Bob's force close tx.
|
||||||
|
// - Bob's anchor sweep tx.
|
||||||
|
ht.AssertNumTxsInMempool(2)
|
||||||
|
|
||||||
// Make sure Bob's old sweeping tx has been removed from the
|
// Make sure Bob's old sweeping tx has been removed from the
|
||||||
// mempool.
|
// mempool.
|
||||||
@@ -600,7 +591,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
// We expect to see two txns in the mempool,
|
// We expect to see two txns in the mempool,
|
||||||
// - Bob's force close tx.
|
// - Bob's force close tx.
|
||||||
// - Bob's anchor sweep tx.
|
// - Bob's anchor sweep tx.
|
||||||
ht.AssertNumTxsInMempool(2)
|
_, sweepTx = ht.AssertForceCloseAndAnchorTxnsInMempool()
|
||||||
|
|
||||||
// We expect the fees to increase by i*delta.
|
// We expect the fees to increase by i*delta.
|
||||||
expectedFee := startFeeAnchor + feeDelta.MulF64(float64(i))
|
expectedFee := startFeeAnchor + feeDelta.MulF64(float64(i))
|
||||||
@@ -608,13 +599,6 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
expectedFee, txWeight,
|
expectedFee, txWeight,
|
||||||
)
|
)
|
||||||
|
|
||||||
// We should see Bob's anchor sweeping tx being fee bumped
|
|
||||||
// since it's not confirmed, along with his force close tx.
|
|
||||||
txns = ht.GetNumTxsFromMempool(2)
|
|
||||||
|
|
||||||
// Find the sweeping tx.
|
|
||||||
sweepTx = ht.FindSweepingTxns(txns, 1, closeTxid)[0]
|
|
||||||
|
|
||||||
// Calculate the fee rate of Bob's new sweeping tx.
|
// Calculate the fee rate of Bob's new sweeping tx.
|
||||||
feeRate = uint64(ht.CalculateTxFeeRate(sweepTx))
|
feeRate = uint64(ht.CalculateTxFeeRate(sweepTx))
|
||||||
|
|
||||||
@@ -622,9 +606,9 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
fee = uint64(ht.CalculateTxFee(sweepTx))
|
fee = uint64(ht.CalculateTxFee(sweepTx))
|
||||||
|
|
||||||
ht.Logf("Bob(position=%v): txWeight=%v, expected: [fee=%d, "+
|
ht.Logf("Bob(position=%v): txWeight=%v, expected: [fee=%d, "+
|
||||||
"feerate=%v], got: [fee=%v, feerate=%v]",
|
"feerate=%v], got: [fee=%v, feerate=%v] in tx %v",
|
||||||
feeFuncWidth-i, txWeight, expectedFee,
|
feeFuncWidth-i, txWeight, expectedFee,
|
||||||
expectedFeeRate, fee, feeRate)
|
expectedFeeRate, fee, feeRate, sweepTx.TxHash())
|
||||||
|
|
||||||
// Assert Bob's tx has the expected fee and fee rate.
|
// Assert Bob's tx has the expected fee and fee rate.
|
||||||
require.InEpsilonf(ht, uint64(expectedFee), fee, 0.01,
|
require.InEpsilonf(ht, uint64(expectedFee), fee, 0.01,
|
||||||
@@ -644,15 +628,17 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
// Mine one more block, we'd use up all the CPFP budget.
|
// Mine one more block, we'd use up all the CPFP budget.
|
||||||
ht.MineEmptyBlocks(1)
|
ht.MineEmptyBlocks(1)
|
||||||
|
|
||||||
|
// We expect to see two txns in the mempool,
|
||||||
|
// - Bob's force close tx.
|
||||||
|
// - Bob's anchor sweep tx.
|
||||||
|
ht.AssertNumTxsInMempool(2)
|
||||||
|
|
||||||
// Make sure Bob's old sweeping tx has been removed from the mempool.
|
// Make sure Bob's old sweeping tx has been removed from the mempool.
|
||||||
ht.AssertTxNotInMempool(sweepTx.TxHash())
|
ht.AssertTxNotInMempool(sweepTx.TxHash())
|
||||||
|
|
||||||
// Get the last sweeping tx - we should see two txns here, Bob's anchor
|
// Get the last sweeping tx - we should see two txns here, Bob's anchor
|
||||||
// sweeping tx and his force close tx.
|
// sweeping tx and his force close tx.
|
||||||
txns = ht.GetNumTxsFromMempool(2)
|
_, sweepTx = ht.AssertForceCloseAndAnchorTxnsInMempool()
|
||||||
|
|
||||||
// Find the sweeping tx.
|
|
||||||
sweepTx = ht.FindSweepingTxns(txns, 1, closeTxid)[0]
|
|
||||||
|
|
||||||
// Calculate the fee of Bob's new sweeping tx.
|
// Calculate the fee of Bob's new sweeping tx.
|
||||||
fee = uint64(ht.CalculateTxFee(sweepTx))
|
fee = uint64(ht.CalculateTxFee(sweepTx))
|
||||||
@@ -670,10 +656,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
//
|
//
|
||||||
// We expect two txns here, one for the anchor sweeping, the other for
|
// We expect two txns here, one for the anchor sweeping, the other for
|
||||||
// the force close tx.
|
// the force close tx.
|
||||||
txns = ht.GetNumTxsFromMempool(2)
|
_, currentSweepTx := ht.AssertForceCloseAndAnchorTxnsInMempool()
|
||||||
|
|
||||||
// Find the sweeping tx.
|
|
||||||
currentSweepTx := ht.FindSweepingTxns(txns, 1, closeTxid)[0]
|
|
||||||
|
|
||||||
// Assert the anchor sweep tx stays unchanged.
|
// Assert the anchor sweep tx stays unchanged.
|
||||||
require.Equal(ht, sweepTx.TxHash(), currentSweepTx.TxHash())
|
require.Equal(ht, sweepTx.TxHash(), currentSweepTx.TxHash())
|
||||||
@@ -687,6 +670,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
// the HTLC sweeping behaviors so we just perform a simple check and
|
// the HTLC sweeping behaviors so we just perform a simple check and
|
||||||
// exit the test.
|
// exit the test.
|
||||||
ht.AssertNumPendingSweeps(bob, 1)
|
ht.AssertNumPendingSweeps(bob, 1)
|
||||||
|
ht.MineBlocksAndAssertNumTxes(1, 1)
|
||||||
|
|
||||||
// Finally, clean the mempool for the next test.
|
// Finally, clean the mempool for the next test.
|
||||||
ht.CleanShutDown()
|
ht.CleanShutDown()
|
||||||
|
Reference in New Issue
Block a user