itest: refactor testMultiHopHtlcLocalChainClaim
This commit is contained in:
2 files changed
+103
-180
No files matched your search
@@ -1,16 +1,13 @@
|
|||||||
package itest
|
package itest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/lncfg"
|
"github.com/lightningnetwork/lnd/lncfg"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||||
"github.com/lightningnetwork/lnd/lntest"
|
"github.com/lightningnetwork/lnd/lntemp"
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntemp/node"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -19,76 +16,66 @@ import (
|
|||||||
// we force close a channel with an incoming HTLC, and later find out the
|
// we force close a channel with an incoming HTLC, and later find out the
|
||||||
// preimage via the witness beacon, we properly settle the HTLC on-chain using
|
// preimage via the witness beacon, we properly settle the HTLC on-chain using
|
||||||
// the HTLC success transaction in order to ensure we don't lose any funds.
|
// the HTLC success transaction in order to ensure we don't lose any funds.
|
||||||
func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
func testMultiHopHtlcLocalChainClaim(ht *lntemp.HarnessTest,
|
||||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType,
|
alice, bob *node.HarnessNode, c lnrpc.CommitmentType, zeroConf bool) {
|
||||||
zeroConf bool) {
|
|
||||||
|
|
||||||
ctxb := context.Background()
|
|
||||||
|
|
||||||
// First, we'll create a three hop network: Alice -> Bob -> Carol, with
|
// First, we'll create a three hop network: Alice -> Bob -> Carol, with
|
||||||
// Carol refusing to actually settle or directly cancel any HTLC's
|
// Carol refusing to actually settle or directly cancel any HTLC's
|
||||||
// self.
|
// self.
|
||||||
aliceChanPoint, bobChanPoint, carol := createThreeHopNetworkOld(
|
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
|
||||||
t, net, alice, bob, false, c, zeroConf,
|
ht, alice, bob, false, c, zeroConf,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Clean up carol's node when the test finishes.
|
|
||||||
defer shutdownAndAssert(net, t, carol)
|
|
||||||
|
|
||||||
// With the network active, we'll now add a new hodl invoice at Carol's
|
// With the network active, we'll now add a new hodl invoice at Carol's
|
||||||
// end. Make sure the cltv expiry delta is large enough, otherwise Bob
|
// end. Make sure the cltv expiry delta is large enough, otherwise Bob
|
||||||
// won't send out the outgoing htlc.
|
// won't send out the outgoing htlc.
|
||||||
|
|
||||||
const invoiceAmt = 100000
|
const invoiceAmt = 100000
|
||||||
preimage := lntypes.Preimage{1, 2, 3}
|
var preimage lntypes.Preimage
|
||||||
|
copy(preimage[:], ht.Random32Bytes())
|
||||||
payHash := preimage.Hash()
|
payHash := preimage.Hash()
|
||||||
invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{
|
invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{
|
||||||
Value: invoiceAmt,
|
Value: invoiceAmt,
|
||||||
CltvExpiry: 40,
|
CltvExpiry: 40,
|
||||||
Hash: payHash[:],
|
Hash: payHash[:],
|
||||||
}
|
}
|
||||||
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
carolInvoice := carol.RPC.AddHoldInvoice(invoiceReq)
|
||||||
defer cancel()
|
|
||||||
carolInvoice, err := carol.AddHoldInvoice(ctxt, invoiceReq)
|
// Subscribe the invoice.
|
||||||
require.NoError(t.t, err)
|
stream := carol.RPC.SubscribeSingleInvoice(payHash[:])
|
||||||
|
|
||||||
// Now that we've created the invoice, we'll send a single payment from
|
// Now that we've created the invoice, we'll send a single payment from
|
||||||
// Alice to Carol. We won't wait for the response however, as Carol
|
// Alice to Carol. We won't wait for the response however, as Carol
|
||||||
// will not immediately settle the payment.
|
// will not immediately settle the payment.
|
||||||
ctx, cancel := context.WithCancel(ctxb)
|
req := &routerrpc.SendPaymentRequest{
|
||||||
defer cancel()
|
PaymentRequest: carolInvoice.PaymentRequest,
|
||||||
|
TimeoutSeconds: 60,
|
||||||
_, err = alice.RouterClient.SendPaymentV2(
|
FeeLimitMsat: noFeeLimitMsat,
|
||||||
ctx, &routerrpc.SendPaymentRequest{
|
}
|
||||||
PaymentRequest: carolInvoice.PaymentRequest,
|
alice.RPC.SendPayment(req)
|
||||||
TimeoutSeconds: 60,
|
|
||||||
FeeLimitMsat: noFeeLimitMsat,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// At this point, all 3 nodes should now have an active channel with
|
// At this point, all 3 nodes should now have an active channel with
|
||||||
// the created HTLC pending on all of them.
|
// the created HTLC pending on all of them.
|
||||||
nodes := []*lntest.HarnessNode{alice, bob, carol}
|
ht.AssertActiveHtlcs(alice, payHash[:])
|
||||||
err = wait.NoError(func() error {
|
ht.AssertActiveHtlcs(bob, payHash[:])
|
||||||
return assertActiveHtlcs(nodes, payHash[:])
|
ht.AssertActiveHtlcs(carol, payHash[:])
|
||||||
}, defaultTimeout)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// Wait for carol to mark invoice as accepted. There is a small gap to
|
// Wait for carol to mark invoice as accepted. There is a small gap to
|
||||||
// bridge between adding the htlc to the channel and executing the exit
|
// bridge between adding the htlc to the channel and executing the exit
|
||||||
// hop logic.
|
// hop logic.
|
||||||
waitForInvoiceAccepted(t, carol, payHash)
|
ht.AssertInvoiceState(stream, lnrpc.Invoice_ACCEPTED)
|
||||||
|
|
||||||
// Increase the fee estimate so that the following force close tx will
|
// Increase the fee estimate so that the following force close tx will
|
||||||
// be cpfp'ed.
|
// be cpfp'ed.
|
||||||
net.SetFeeEstimate(30000)
|
ht.SetFeeEstimate(30000)
|
||||||
|
|
||||||
// At this point, Bob decides that he wants to exit the channel
|
// At this point, Bob decides that he wants to exit the channel
|
||||||
// immediately, so he force closes his commitment transaction.
|
// immediately, so he force closes his commitment transaction.
|
||||||
hasAnchors := commitTypeHasAnchors(c)
|
hasAnchors := commitTypeHasAnchors(c)
|
||||||
bobForceClose := closeChannelAndAssertType(
|
closeStream, _ := ht.CloseChannelAssertPending(
|
||||||
t, net, bob, aliceChanPoint, hasAnchors, true,
|
bob, aliceChanPoint, true,
|
||||||
|
)
|
||||||
|
bobForceClose := ht.AssertStreamChannelForceClosed(
|
||||||
|
bob, aliceChanPoint, hasAnchors, closeStream,
|
||||||
)
|
)
|
||||||
|
|
||||||
var expectedTxes int
|
var expectedTxes int
|
||||||
@@ -101,73 +88,55 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
case lnrpc.CommitmentType_ANCHORS:
|
case lnrpc.CommitmentType_ANCHORS:
|
||||||
expectedTxes = 2
|
expectedTxes = 2
|
||||||
|
|
||||||
// Alice will sweep her anchor output immediately. Her commitment output
|
// Alice will sweep her anchor output immediately. Her commitment
|
||||||
// cannot be swept yet as it has incurred an additional CLTV due to
|
// output cannot be swept yet as it has incurred an additional CLTV due
|
||||||
// being the initiator of a script-enforced leased channel.
|
// to being the initiator of a script-enforced leased channel.
|
||||||
case lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE:
|
case lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE:
|
||||||
expectedTxes = 1
|
expectedTxes = 1
|
||||||
|
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unhandled commitment type %v", c)
|
ht.Fatalf("unhandled commitment type %v", c)
|
||||||
}
|
}
|
||||||
_, err = waitForNTxsInMempool(
|
|
||||||
net.Miner.Client, expectedTxes, minerMempoolTimeout,
|
ht.Miner.AssertNumTxsInMempool(expectedTxes)
|
||||||
)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// Suspend Bob to force Carol to go to chain.
|
// Suspend Bob to force Carol to go to chain.
|
||||||
restartBob, err := net.SuspendNode(bob)
|
restartBob := ht.SuspendNode(bob)
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// Settle invoice. This will just mark the invoice as settled, as there
|
// Settle invoice. This will just mark the invoice as settled, as there
|
||||||
// is no link anymore to remove the htlc from the commitment tx. For
|
// is no link anymore to remove the htlc from the commitment tx. For
|
||||||
// this test, it is important to actually settle and not leave the
|
// this test, it is important to actually settle and not leave the
|
||||||
// invoice in the accepted state, because without a known preimage, the
|
// invoice in the accepted state, because without a known preimage, the
|
||||||
// channel arbitrator won't go to chain.
|
// channel arbitrator won't go to chain.
|
||||||
ctx, cancel = context.WithTimeout(ctxb, defaultTimeout)
|
carol.RPC.SettleInvoice(preimage[:])
|
||||||
defer cancel()
|
|
||||||
_, err = carol.SettleInvoice(ctx, &invoicesrpc.SettleInvoiceMsg{
|
|
||||||
Preimage: preimage[:],
|
|
||||||
})
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// We'll now mine enough blocks so Carol decides that she needs to go
|
// We'll now mine enough blocks so Carol decides that she needs to go
|
||||||
// on-chain to claim the HTLC as Bob has been inactive.
|
// on-chain to claim the HTLC as Bob has been inactive.
|
||||||
numBlocks := padCLTV(uint32(invoiceReq.CltvExpiry -
|
numBlocks := padCLTV(uint32(invoiceReq.CltvExpiry -
|
||||||
lncfg.DefaultIncomingBroadcastDelta))
|
lncfg.DefaultIncomingBroadcastDelta))
|
||||||
|
ht.MineBlocksAssertNodesSync(numBlocks)
|
||||||
|
|
||||||
_, err = net.Miner.Client.Generate(numBlocks)
|
// Carol's commitment transaction should now be in the mempool. If
|
||||||
require.NoError(t.t, err)
|
// there is an anchor, Carol will sweep that too.
|
||||||
|
if commitTypeHasAnchors(c) {
|
||||||
// Carol's commitment transaction should now be in the mempool. If there
|
expectedTxes = 2
|
||||||
// is an anchor, Carol will sweep that too.
|
|
||||||
_, err = waitForNTxsInMempool(
|
|
||||||
net.Miner.Client, expectedTxes, minerMempoolTimeout,
|
|
||||||
)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
bobFundingTxid, err := lnrpc.GetChanPointFundingTxid(bobChanPoint)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
carolFundingPoint := wire.OutPoint{
|
|
||||||
Hash: *bobFundingTxid,
|
|
||||||
Index: bobChanPoint.OutputIndex,
|
|
||||||
}
|
}
|
||||||
|
ht.Miner.AssertNumTxsInMempool(expectedTxes)
|
||||||
|
|
||||||
// Look up the closing transaction. It should be spending from the
|
// Look up the closing transaction. It should be spending from the
|
||||||
// funding transaction,
|
// funding transaction,
|
||||||
closingTx := getSpendingTxInMempool(
|
closingTx := ht.Miner.AssertOutpointInMempool(
|
||||||
t, net.Miner.Client, minerMempoolTimeout, carolFundingPoint,
|
ht.OutPointFromChannelPoint(bobChanPoint),
|
||||||
)
|
)
|
||||||
closingTxid := closingTx.TxHash()
|
closingTxid := closingTx.TxHash()
|
||||||
|
|
||||||
// Mine a block that should confirm the commit tx, the anchor if present
|
// Mine a block that should confirm the commit tx, the anchor if
|
||||||
// and the coinbase.
|
// present and the coinbase.
|
||||||
block := mineBlocks(t, net, 1, expectedTxes)[0]
|
block := ht.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)[0]
|
||||||
require.Len(t.t, block.Transactions, expectedTxes+1)
|
ht.Miner.AssertTxInBlock(block, &closingTxid)
|
||||||
assertTxInBlock(t, block, &closingTxid)
|
|
||||||
|
|
||||||
// Restart bob again.
|
// Restart bob again.
|
||||||
err = restartBob()
|
require.NoError(ht, restartBob())
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// After the force close transaction is mined, transactions will be
|
// After the force close transaction is mined, transactions will be
|
||||||
// broadcast by both Bob and Carol.
|
// broadcast by both Bob and Carol.
|
||||||
@@ -187,28 +156,25 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// commitment output yet as it has incurred an additional CLTV due to
|
// commitment output yet as it has incurred an additional CLTV due to
|
||||||
// being the initiator of a script-enforced leased channel.
|
// being the initiator of a script-enforced leased channel.
|
||||||
case lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE:
|
case lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE:
|
||||||
expectedTxes = 3
|
expectedTxes = 2
|
||||||
|
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unhandled commitment type %v", c)
|
ht.Fatalf("unhandled commitment type %v", c)
|
||||||
}
|
}
|
||||||
txes, err := getNTxsFromMempool(
|
|
||||||
net.Miner.Client, expectedTxes, minerMempoolTimeout,
|
txes := ht.Miner.GetNumTxsFromMempool(expectedTxes)
|
||||||
)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// Both Carol's second level transaction and Bob's sweep should be
|
// Both Carol's second level transaction and Bob's sweep should be
|
||||||
// spending from the commitment transaction.
|
// spending from the commitment transaction.
|
||||||
assertAllTxesSpendFrom(t, txes, closingTxid)
|
ht.AssertAllTxesSpendFrom(txes, closingTxid)
|
||||||
|
|
||||||
// At this point we suspend Alice to make sure she'll handle the
|
// At this point we suspend Alice to make sure she'll handle the
|
||||||
// on-chain settle after a restart.
|
// on-chain settle after a restart.
|
||||||
restartAlice, err := net.SuspendNode(alice)
|
restartAlice := ht.SuspendNode(alice)
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// Mine a block to confirm the expected transactions (+ the coinbase).
|
// Mine a block to confirm the expected transactions (+ the coinbase).
|
||||||
block = mineBlocks(t, net, 1, expectedTxes)[0]
|
block = ht.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)[0]
|
||||||
require.Len(t.t, block.Transactions, expectedTxes+1)
|
require.Len(ht, block.Transactions, expectedTxes+1)
|
||||||
|
|
||||||
// For non-anchor channel types, the nursery will handle sweeping the
|
// For non-anchor channel types, the nursery will handle sweeping the
|
||||||
// second level output, and it will wait one extra block before
|
// second level output, and it will wait one extra block before
|
||||||
@@ -228,18 +194,10 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// When Bob notices Carol's second level transaction in the block, he
|
// When Bob notices Carol's second level transaction in the block, he
|
||||||
// will extract the preimage and broadcast a second level tx to claim
|
// will extract the preimage and broadcast a second level tx to claim
|
||||||
// the HTLC in his (already closed) channel with Alice.
|
// the HTLC in his (already closed) channel with Alice.
|
||||||
bobSecondLvlTx, err := waitForTxInMempool(
|
bobSecondLvlTx := ht.Miner.GetNumTxsFromMempool(1)[0]
|
||||||
net.Miner.Client, minerMempoolTimeout,
|
|
||||||
)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// It should spend from the commitment in the channel with Alice.
|
// It should spend from the commitment in the channel with Alice.
|
||||||
tx, err := net.Miner.Client.GetRawTransaction(bobSecondLvlTx)
|
ht.AssertTxSpendFrom(bobSecondLvlTx, *bobForceClose)
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
require.Equal(
|
|
||||||
t.t, *bobForceClose, tx.MsgTx().TxIn[0].PreviousOutPoint.Hash,
|
|
||||||
)
|
|
||||||
|
|
||||||
// At this point, Bob should have broadcast his second layer success
|
// At this point, Bob should have broadcast his second layer success
|
||||||
// transaction, and should have sent it to the nursery for incubation.
|
// transaction, and should have sent it to the nursery for incubation.
|
||||||
@@ -247,33 +205,14 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
|
if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
|
||||||
numPendingChans++
|
numPendingChans++
|
||||||
}
|
}
|
||||||
err = waitForNumChannelPendingForceClose(
|
ht.AssertNumPendingForceClose(bob, numPendingChans)
|
||||||
bob, numPendingChans, func(c *lnrpcForceCloseChannel) error {
|
ht.AssertNumHTLCsAndStage(bob, aliceChanPoint, 1, 1)
|
||||||
if c.Channel.LocalBalance != 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(c.PendingHtlcs) != 1 {
|
|
||||||
return fmt.Errorf("bob should have pending " +
|
|
||||||
"htlc but doesn't")
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.PendingHtlcs[0].Stage != 1 {
|
|
||||||
return fmt.Errorf("bob's htlc should have "+
|
|
||||||
"advanced to the first stage but was "+
|
|
||||||
"stage: %v", c.PendingHtlcs[0].Stage)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// We'll now mine a block which should confirm Bob's second layer
|
// We'll now mine a block which should confirm Bob's second layer
|
||||||
// transaction.
|
// transaction.
|
||||||
block = mineBlocks(t, net, 1, 1)[0]
|
block = ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0]
|
||||||
require.Len(t.t, block.Transactions, 2)
|
bobSecondLvlTxid := bobSecondLvlTx.TxHash()
|
||||||
assertTxInBlock(t, block, bobSecondLvlTx)
|
ht.Miner.AssertTxInBlock(block, &bobSecondLvlTxid)
|
||||||
|
|
||||||
// Keep track of Bob's second level maturity, and decrement our track
|
// Keep track of Bob's second level maturity, and decrement our track
|
||||||
// of Carol's.
|
// of Carol's.
|
||||||
@@ -282,93 +221,77 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
|
|
||||||
// Now that the preimage from Bob has hit the chain, restart Alice to
|
// Now that the preimage from Bob has hit the chain, restart Alice to
|
||||||
// ensure she'll pick it up.
|
// ensure she'll pick it up.
|
||||||
err = restartAlice()
|
require.NoError(ht, restartAlice())
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// If we then mine 3 additional blocks, Carol's second level tx should
|
// If we then mine 3 additional blocks, Carol's second level tx should
|
||||||
// mature, and she can pull the funds from it with a sweep tx.
|
// mature, and she can pull the funds from it with a sweep tx.
|
||||||
_, err = net.Miner.Client.Generate(carolSecondLevelCSV)
|
ht.MineBlocksAssertNodesSync(carolSecondLevelCSV)
|
||||||
require.NoError(t.t, err)
|
carolSweep := ht.Miner.AssertNumTxsInMempool(1)[0]
|
||||||
bobSecondLevelCSV -= carolSecondLevelCSV
|
|
||||||
|
|
||||||
carolSweep, err := waitForTxInMempool(net.Miner.Client, minerMempoolTimeout)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// Mining one additional block, Bob's second level tx is mature, and he
|
// Mining one additional block, Bob's second level tx is mature, and he
|
||||||
// can sweep the output.
|
// can sweep the output.
|
||||||
block = mineBlocks(t, net, bobSecondLevelCSV, 1)[0]
|
bobSecondLevelCSV -= carolSecondLevelCSV
|
||||||
assertTxInBlock(t, block, carolSweep)
|
block = ht.Miner.MineBlocksAndAssertNumTxes(bobSecondLevelCSV, 1)[0]
|
||||||
|
ht.Miner.AssertTxInBlock(block, carolSweep)
|
||||||
|
|
||||||
bobSweep, err := waitForTxInMempool(net.Miner.Client, minerMempoolTimeout)
|
bobSweep := ht.Miner.GetNumTxsFromMempool(1)[0]
|
||||||
require.NoError(t.t, err)
|
bobSweepTxid := bobSweep.TxHash()
|
||||||
|
|
||||||
// Make sure it spends from the second level tx.
|
// Make sure it spends from the second level tx.
|
||||||
tx, err = net.Miner.Client.GetRawTransaction(bobSweep)
|
ht.AssertTxSpendFrom(bobSweep, bobSecondLvlTxid)
|
||||||
require.NoError(t.t, err)
|
|
||||||
require.Equal(
|
|
||||||
t.t, *bobSecondLvlTx, tx.MsgTx().TxIn[0].PreviousOutPoint.Hash,
|
|
||||||
)
|
|
||||||
|
|
||||||
// When we mine one additional block, that will confirm Bob's sweep.
|
// When we mine one additional block, that will confirm Bob's sweep.
|
||||||
// Now Bob should have no pending channels anymore, as this just
|
// Now Bob should have no pending channels anymore, as this just
|
||||||
// resolved it by the confirmation of the sweep transaction.
|
// resolved it by the confirmation of the sweep transaction.
|
||||||
block = mineBlocks(t, net, 1, 1)[0]
|
block = ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0]
|
||||||
assertTxInBlock(t, block, bobSweep)
|
ht.Miner.AssertTxInBlock(block, &bobSweepTxid)
|
||||||
|
|
||||||
// With the script-enforced lease commitment type, Alice and Bob still
|
// With the script-enforced lease commitment type, Alice and Bob still
|
||||||
// haven't been able to sweep their respective commit outputs due to the
|
// haven't been able to sweep their respective commit outputs due to the
|
||||||
// additional CLTV. We'll need to mine enough blocks for the timelock to
|
// additional CLTV. We'll need to mine enough blocks for the timelock to
|
||||||
// expire and prompt their sweep.
|
// expire and prompt their sweep.
|
||||||
if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
|
if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
|
||||||
for _, node := range []*lntest.HarnessNode{alice, bob} {
|
for _, node := range []*node.HarnessNode{alice, bob} {
|
||||||
err = waitForNumChannelPendingForceClose(node, 1, nil)
|
ht.AssertNumPendingForceClose(node, 1)
|
||||||
require.NoError(t.t, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Due to the way the test is set up, Alice and Bob share the
|
// Due to the way the test is set up, Alice and Bob share the
|
||||||
// same CLTV for their commit outputs even though it's enforced
|
// same CLTV for their commit outputs even though it's enforced
|
||||||
// on different channels (Alice-Bob and Bob-Carol).
|
// on different channels (Alice-Bob and Bob-Carol).
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
resp := alice.RPC.PendingChannels()
|
||||||
resp, err := alice.PendingChannels(
|
require.Len(ht, resp.PendingForceClosingChannels, 1)
|
||||||
ctxt, &lnrpc.PendingChannelsRequest{},
|
|
||||||
)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
require.Len(t.t, resp.PendingForceClosingChannels, 1)
|
|
||||||
forceCloseChan := resp.PendingForceClosingChannels[0]
|
forceCloseChan := resp.PendingForceClosingChannels[0]
|
||||||
require.Positive(t.t, forceCloseChan.BlocksTilMaturity)
|
require.Positive(ht, forceCloseChan.BlocksTilMaturity)
|
||||||
|
|
||||||
// Mine enough blocks for the timelock to expire.
|
// Mine enough blocks for the timelock to expire.
|
||||||
numBlocks := uint32(forceCloseChan.BlocksTilMaturity)
|
numBlocks := uint32(forceCloseChan.BlocksTilMaturity)
|
||||||
_, err = net.Miner.Client.Generate(numBlocks)
|
ht.MineBlocksAssertNodesSync(numBlocks)
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// Both Alice and Bob show broadcast their commit sweeps.
|
// Both Alice and Bob show broadcast their commit sweeps.
|
||||||
aliceCommitOutpoint := wire.OutPoint{Hash: *bobForceClose, Index: 3}
|
aliceCommitOutpoint := wire.OutPoint{
|
||||||
aliceCommitSweep := assertSpendingTxInMempool(
|
Hash: *bobForceClose, Index: 3,
|
||||||
t, net.Miner.Client, minerMempoolTimeout,
|
}
|
||||||
|
aliceCommitSweep := ht.Miner.AssertOutpointInMempool(
|
||||||
aliceCommitOutpoint,
|
aliceCommitOutpoint,
|
||||||
)
|
).TxHash()
|
||||||
bobCommitOutpoint := wire.OutPoint{Hash: closingTxid, Index: 3}
|
bobCommitOutpoint := wire.OutPoint{Hash: closingTxid, Index: 3}
|
||||||
bobCommitSweep := assertSpendingTxInMempool(
|
bobCommitSweep := ht.Miner.AssertOutpointInMempool(
|
||||||
t, net.Miner.Client, minerMempoolTimeout,
|
|
||||||
bobCommitOutpoint,
|
bobCommitOutpoint,
|
||||||
)
|
).TxHash()
|
||||||
|
|
||||||
// Confirm their sweeps.
|
// Confirm their sweeps.
|
||||||
block := mineBlocks(t, net, 1, 2)[0]
|
block := ht.Miner.MineBlocksAndAssertNumTxes(1, 2)[0]
|
||||||
assertTxInBlock(t, block, &aliceCommitSweep)
|
ht.Miner.AssertTxInBlock(block, &aliceCommitSweep)
|
||||||
assertTxInBlock(t, block, &bobCommitSweep)
|
ht.Miner.AssertTxInBlock(block, &bobCommitSweep)
|
||||||
}
|
}
|
||||||
|
|
||||||
// All nodes should show zero pending and open channels.
|
// All nodes should show zero pending and open channels.
|
||||||
for _, node := range []*lntest.HarnessNode{alice, bob, carol} {
|
for _, node := range []*node.HarnessNode{alice, bob, carol} {
|
||||||
err = waitForNumChannelPendingForceClose(node, 0, nil)
|
ht.AssertNumPendingForceClose(node, 0)
|
||||||
require.NoError(t.t, err)
|
ht.AssertNodeNumChannels(node, 0)
|
||||||
assertNodeNumChannels(t, node, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, check that the Alice's payment is correctly marked
|
// Finally, check that the Alice's payment is correctly marked
|
||||||
// succeeded.
|
// succeeded.
|
||||||
err = checkPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
|
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
|
||||||
require.NoError(t.t, err)
|
|
||||||
}
|
}
|
||||||
@@ -51,14 +51,14 @@ func testMultiHopHtlcClaims(ht *lntemp.HarnessTest) {
|
|||||||
name: "remote force close on-chain htlc timeout",
|
name: "remote force close on-chain htlc timeout",
|
||||||
test: testMultiHopRemoteForceCloseOnChainHtlcTimeout,
|
test: testMultiHopRemoteForceCloseOnChainHtlcTimeout,
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// // bob: outgoing our commit watch and see, they sweep
|
// bob: outgoing our commit watch and see, they sweep
|
||||||
// // on chain
|
// on chain
|
||||||
// // bob: incoming our commit watch and learn preimage
|
// bob: incoming our commit watch and learn preimage
|
||||||
// // carol: incoming their commit know preimage
|
// carol: incoming their commit know preimage
|
||||||
// name: "local chain claim",
|
name: "local chain claim",
|
||||||
// test: testMultiHopHtlcLocalChainClaim,
|
test: testMultiHopHtlcLocalChainClaim,
|
||||||
// },
|
},
|
||||||
// {
|
// {
|
||||||
// // bob: outgoing their commit watch and see, they sweep
|
// // bob: outgoing their commit watch and see, they sweep
|
||||||
// // on chain
|
// // on chain
|
||||||
|
|||||||
Reference in new issue
Block a user