itest: spin up new nodes for multi-hop tests
This will let us set their commitment type for the subtest.
This commit is contained in:
6 files changed
+124
-73
No files matched your search
@@ -22,7 +22,8 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
name string
|
name string
|
||||||
test func(net *lntest.NetworkHarness, t *harnessTest)
|
test func(net *lntest.NetworkHarness, t *harnessTest, alice,
|
||||||
|
bob *lntest.HarnessNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
subTests := []testCase{
|
subTests := []testCase{
|
||||||
@@ -66,13 +67,32 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
args := []string{}
|
||||||
|
alice, err := net.NewNode("Alice", args)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to create new node: %v", err)
|
||||||
|
}
|
||||||
|
defer shutdownAndAssert(net, t, alice)
|
||||||
|
|
||||||
|
bob, err := net.NewNode("Bob", args)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to create new node: %v", err)
|
||||||
|
}
|
||||||
|
defer shutdownAndAssert(net, t, bob)
|
||||||
|
|
||||||
|
ctxb := context.Background()
|
||||||
|
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
|
if err := net.ConnectNodes(ctxt, alice, bob); err != nil {
|
||||||
|
t.Fatalf("unable to connect alice to bob: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
for _, subTest := range subTests {
|
for _, subTest := range subTests {
|
||||||
subTest := subTest
|
subTest := subTest
|
||||||
|
|
||||||
success := t.t.Run(subTest.name, func(t *testing.T) {
|
success := t.t.Run(subTest.name, func(t *testing.T) {
|
||||||
ht := newHarnessTest(t, net)
|
ht := newHarnessTest(t, net)
|
||||||
|
|
||||||
subTest.test(net, ht)
|
subTest.test(net, ht, alice, bob)
|
||||||
})
|
})
|
||||||
if !success {
|
if !success {
|
||||||
return
|
return
|
||||||
@@ -84,14 +104,16 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// 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(net *lntest.NetworkHarness, t *harnessTest,
|
||||||
|
alice, bob *lntest.HarnessNode) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
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 := createThreeHopNetwork(
|
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
|
||||||
t, net, false,
|
t, net, alice, bob, false,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Clean up carol's node when the test finishes.
|
// Clean up carol's node when the test finishes.
|
||||||
@@ -122,7 +144,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
ctx, cancel := context.WithCancel(ctxb)
|
ctx, cancel := context.WithCancel(ctxb)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
alicePayStream, err := net.Alice.SendPayment(ctx)
|
alicePayStream, err := alice.SendPayment(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create payment stream for alice: %v", err)
|
t.Fatalf("unable to create payment stream for alice: %v", err)
|
||||||
}
|
}
|
||||||
@@ -136,7 +158,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
// 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.
|
||||||
var predErr error
|
var predErr error
|
||||||
nodes := []*lntest.HarnessNode{net.Alice, net.Bob, carol}
|
nodes := []*lntest.HarnessNode{alice, bob, carol}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
predErr = assertActiveHtlcs(nodes, payHash[:])
|
predErr = assertActiveHtlcs(nodes, payHash[:])
|
||||||
if predErr != nil {
|
if predErr != nil {
|
||||||
@@ -157,7 +179,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
// 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.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
||||||
bobForceClose := closeChannelAndAssert(ctxt, t, net, net.Bob,
|
bobForceClose := closeChannelAndAssert(ctxt, t, net, bob,
|
||||||
aliceChanPoint, true)
|
aliceChanPoint, true)
|
||||||
|
|
||||||
// Alice will sweep her output immediately.
|
// Alice will sweep her output immediately.
|
||||||
@@ -168,7 +190,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Suspend Bob to force Carol to go to chain.
|
// Suspend Bob to force Carol to go to chain.
|
||||||
restartBob, err := net.SuspendNode(net.Bob)
|
restartBob, err := net.SuspendNode(bob)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to suspend bob: %v", err)
|
t.Fatalf("unable to suspend bob: %v", err)
|
||||||
}
|
}
|
||||||
@@ -260,7 +282,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
|
|
||||||
// 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(net.Alice)
|
restartAlice, err := net.SuspendNode(alice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to suspend alice: %v", err)
|
t.Fatalf("unable to suspend alice: %v", err)
|
||||||
}
|
}
|
||||||
@@ -302,7 +324,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
pendingChansRequest := &lnrpc.PendingChannelsRequest{}
|
pendingChansRequest := &lnrpc.PendingChannelsRequest{}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
pendingChanResp, err := net.Bob.PendingChannels(
|
pendingChanResp, err := bob.PendingChannels(
|
||||||
ctxt, pendingChansRequest,
|
ctxt, pendingChansRequest,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -400,7 +422,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
|
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
pendingChanResp, err := net.Bob.PendingChannels(
|
pendingChanResp, err := bob.PendingChannels(
|
||||||
ctxt, pendingChansRequest,
|
ctxt, pendingChansRequest,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -415,7 +437,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
}
|
}
|
||||||
req := &lnrpc.ListChannelsRequest{}
|
req := &lnrpc.ListChannelsRequest{}
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
chanInfo, err := net.Bob.ListChannels(ctxt, req)
|
chanInfo, err := bob.ListChannels(ctxt, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
predErr = fmt.Errorf("unable to query for open "+
|
predErr = fmt.Errorf("unable to query for open "+
|
||||||
"channels: %v", err)
|
"channels: %v", err)
|
||||||
@@ -474,7 +496,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
// succeeded.
|
// succeeded.
|
||||||
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout)
|
||||||
err = checkPaymentStatus(
|
err = checkPaymentStatus(
|
||||||
ctxt, net.Alice, preimage, lnrpc.Payment_SUCCEEDED,
|
ctxt, alice, preimage, lnrpc.Payment_SUCCEEDED,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf(err.Error())
|
t.Fatalf(err.Error())
|
||||||
@@ -563,30 +585,48 @@ func checkPaymentStatus(ctxt context.Context, node *lntest.HarnessNode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
||||||
carolHodl bool) (*lnrpc.ChannelPoint, *lnrpc.ChannelPoint,
|
alice, bob *lntest.HarnessNode, carolHodl bool) (*lnrpc.ChannelPoint,
|
||||||
*lntest.HarnessNode) {
|
*lnrpc.ChannelPoint, *lntest.HarnessNode) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
|
|
||||||
|
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
|
err := net.EnsureConnected(ctxt, alice, bob)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to connect peers: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctxt, _ = context.WithTimeout(context.Background(), defaultTimeout)
|
||||||
|
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, alice)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to send coins to Alice: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctxt, _ = context.WithTimeout(context.Background(), defaultTimeout)
|
||||||
|
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, bob)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to send coins to Bob: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// We'll start the test by creating a channel between Alice and Bob,
|
// We'll start the test by creating a channel between Alice and Bob,
|
||||||
// which will act as the first leg for out multi-hop HTLC.
|
// which will act as the first leg for out multi-hop HTLC.
|
||||||
const chanAmt = 1000000
|
const chanAmt = 1000000
|
||||||
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
|
||||||
aliceChanPoint := openChannelAndAssert(
|
aliceChanPoint := openChannelAndAssert(
|
||||||
ctxt, t, net, net.Alice, net.Bob,
|
ctxt, t, net, alice, bob,
|
||||||
lntest.OpenChannelParams{
|
lntest.OpenChannelParams{
|
||||||
Amt: chanAmt,
|
Amt: chanAmt,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
err := net.Alice.WaitForNetworkChannelOpen(ctxt, aliceChanPoint)
|
err = alice.WaitForNetworkChannelOpen(ctxt, aliceChanPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("alice didn't report channel: %v", err)
|
t.Fatalf("alice didn't report channel: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
err = net.Bob.WaitForNetworkChannelOpen(ctxt, aliceChanPoint)
|
err = bob.WaitForNetworkChannelOpen(ctxt, aliceChanPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("bob didn't report channel: %v", err)
|
t.Fatalf("bob didn't report channel: %v", err)
|
||||||
}
|
}
|
||||||
@@ -603,7 +643,7 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
t.Fatalf("unable to create new node: %v", err)
|
t.Fatalf("unable to create new node: %v", err)
|
||||||
}
|
}
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
if err := net.ConnectNodes(ctxt, net.Bob, carol); err != nil {
|
if err := net.ConnectNodes(ctxt, bob, carol); err != nil {
|
||||||
t.Fatalf("unable to connect bob to carol: %v", err)
|
t.Fatalf("unable to connect bob to carol: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -611,13 +651,13 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
// open, our topology looks like: A -> B -> C.
|
// open, our topology looks like: A -> B -> C.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
|
||||||
bobChanPoint := openChannelAndAssert(
|
bobChanPoint := openChannelAndAssert(
|
||||||
ctxt, t, net, net.Bob, carol,
|
ctxt, t, net, bob, carol,
|
||||||
lntest.OpenChannelParams{
|
lntest.OpenChannelParams{
|
||||||
Amt: chanAmt,
|
Amt: chanAmt,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
err = net.Bob.WaitForNetworkChannelOpen(ctxt, bobChanPoint)
|
err = bob.WaitForNetworkChannelOpen(ctxt, bobChanPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("alice didn't report channel: %v", err)
|
t.Fatalf("alice didn't report channel: %v", err)
|
||||||
}
|
}
|
||||||
@@ -627,7 +667,7 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
t.Fatalf("bob didn't report channel: %v", err)
|
t.Fatalf("bob didn't report channel: %v", err)
|
||||||
}
|
}
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
err = net.Alice.WaitForNetworkChannelOpen(ctxt, bobChanPoint)
|
err = alice.WaitForNetworkChannelOpen(ctxt, bobChanPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("bob didn't report channel: %v", err)
|
t.Fatalf("bob didn't report channel: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,14 +21,17 @@ import (
|
|||||||
// it using the HTLC timeout transaction. Any dust HTLC's should be immediately
|
// it using the HTLC timeout transaction. Any dust HTLC's should be immediately
|
||||||
// canceled backwards. Once the timeout has been reached, then we should sweep
|
// canceled backwards. Once the timeout has been reached, then we should sweep
|
||||||
// it on-chain, and cancel the HTLC backwards.
|
// it on-chain, and cancel the HTLC backwards.
|
||||||
func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest) {
|
func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest,
|
||||||
|
alice, bob *lntest.HarnessNode) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
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 :=
|
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
|
||||||
createThreeHopNetwork(t, net, true)
|
t, net, alice, bob, true,
|
||||||
|
)
|
||||||
|
|
||||||
// Clean up carol's node when the test finishes.
|
// Clean up carol's node when the test finishes.
|
||||||
defer shutdownAndAssert(net, t, carol)
|
defer shutdownAndAssert(net, t, carol)
|
||||||
@@ -47,7 +50,7 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
ctx, cancel := context.WithCancel(ctxb)
|
ctx, cancel := context.WithCancel(ctxb)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
alicePayStream, err := net.Alice.SendPayment(ctx)
|
alicePayStream, err := alice.SendPayment(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create payment stream for alice: %v", err)
|
t.Fatalf("unable to create payment stream for alice: %v", err)
|
||||||
}
|
}
|
||||||
@@ -79,7 +82,7 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Verify that all nodes in the path now have two HTLC's with the
|
// Verify that all nodes in the path now have two HTLC's with the
|
||||||
// proper parameters.
|
// proper parameters.
|
||||||
var predErr error
|
var predErr error
|
||||||
nodes := []*lntest.HarnessNode{net.Alice, net.Bob, carol}
|
nodes := []*lntest.HarnessNode{alice, bob, carol}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
predErr = assertActiveHtlcs(nodes, dustPayHash, payHash)
|
predErr = assertActiveHtlcs(nodes, dustPayHash, payHash)
|
||||||
if predErr != nil {
|
if predErr != nil {
|
||||||
@@ -125,7 +128,7 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// At this point, Bob should have canceled backwards the dust HTLC
|
// At this point, Bob should have canceled backwards the dust HTLC
|
||||||
// that we sent earlier. This means Alice should now only have a single
|
// that we sent earlier. This means Alice should now only have a single
|
||||||
// HTLC on her channel.
|
// HTLC on her channel.
|
||||||
nodes = []*lntest.HarnessNode{net.Alice}
|
nodes = []*lntest.HarnessNode{alice}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
predErr = assertActiveHtlcs(nodes, payHash)
|
predErr = assertActiveHtlcs(nodes, payHash)
|
||||||
if predErr != nil {
|
if predErr != nil {
|
||||||
@@ -160,7 +163,7 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// output pending.
|
// output pending.
|
||||||
pendingChansRequest := &lnrpc.PendingChannelsRequest{}
|
pendingChansRequest := &lnrpc.PendingChannelsRequest{}
|
||||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
pendingChanResp, err := net.Bob.PendingChannels(ctxt, pendingChansRequest)
|
pendingChanResp, err := bob.PendingChannels(ctxt, pendingChansRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to query for pending channels: %v", err)
|
t.Fatalf("unable to query for pending channels: %v", err)
|
||||||
}
|
}
|
||||||
@@ -191,7 +194,7 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// The block should have confirmed Bob's HTLC timeout transaction.
|
// The block should have confirmed Bob's HTLC timeout transaction.
|
||||||
// Therefore, at this point, there should be no active HTLC's on the
|
// Therefore, at this point, there should be no active HTLC's on the
|
||||||
// commitment transaction from Alice -> Bob.
|
// commitment transaction from Alice -> Bob.
|
||||||
nodes = []*lntest.HarnessNode{net.Alice}
|
nodes = []*lntest.HarnessNode{alice}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
predErr = assertNumActiveHtlcs(nodes, 0)
|
predErr = assertNumActiveHtlcs(nodes, 0)
|
||||||
if predErr != nil {
|
if predErr != nil {
|
||||||
@@ -206,7 +209,7 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// At this point, Bob should show that the pending HTLC has advanced to
|
// At this point, Bob should show that the pending HTLC has advanced to
|
||||||
// the second stage and is to be swept.
|
// the second stage and is to be swept.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
pendingChanResp, err = net.Bob.PendingChannels(ctxt, pendingChansRequest)
|
pendingChanResp, err = bob.PendingChannels(ctxt, pendingChansRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to query for pending channels: %v", err)
|
t.Fatalf("unable to query for pending channels: %v", err)
|
||||||
}
|
}
|
||||||
@@ -225,7 +228,7 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// no longer has any pending channels.
|
// no longer has any pending channels.
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
pendingChanResp, err = net.Bob.PendingChannels(ctxt, pendingChansRequest)
|
pendingChanResp, err = bob.PendingChannels(ctxt, pendingChansRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
predErr = fmt.Errorf("unable to query for pending "+
|
predErr = fmt.Errorf("unable to query for pending "+
|
||||||
"channels: %v", err)
|
"channels: %v", err)
|
||||||
@@ -246,5 +249,5 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
||||||
closeChannelAndAssert(ctxt, t, net, net.Alice, aliceChanPoint, false)
|
closeChannelAndAssert(ctxt, t, net, alice, aliceChanPoint, false)
|
||||||
}
|
}
|
||||||
@@ -24,14 +24,16 @@ import (
|
|||||||
// transaction. In this scenario, the node that sent the outgoing HTLC should
|
// transaction. In this scenario, the node that sent the outgoing HTLC should
|
||||||
// extract the preimage from the sweep transaction, and finish settling the
|
// extract the preimage from the sweep transaction, and finish settling the
|
||||||
// HTLC backwards into the route.
|
// HTLC backwards into the route.
|
||||||
func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest) {
|
func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
||||||
|
alice, bob *lntest.HarnessNode) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
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 := createThreeHopNetwork(
|
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
|
||||||
t, net, false,
|
t, net, alice, bob, false,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Clean up carol's node when the test finishes.
|
// Clean up carol's node when the test finishes.
|
||||||
@@ -62,7 +64,7 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
ctx, cancel := context.WithCancel(ctxb)
|
ctx, cancel := context.WithCancel(ctxb)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
alicePayStream, err := net.Alice.SendPayment(ctx)
|
alicePayStream, err := alice.SendPayment(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create payment stream for alice: %v", err)
|
t.Fatalf("unable to create payment stream for alice: %v", err)
|
||||||
}
|
}
|
||||||
@@ -76,7 +78,7 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
// 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.
|
||||||
var predErr error
|
var predErr error
|
||||||
nodes := []*lntest.HarnessNode{net.Alice, net.Bob, carol}
|
nodes := []*lntest.HarnessNode{alice, bob, carol}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
predErr = assertActiveHtlcs(nodes, payHash[:])
|
predErr = assertActiveHtlcs(nodes, payHash[:])
|
||||||
if predErr != nil {
|
if predErr != nil {
|
||||||
@@ -94,7 +96,7 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
// hop logic.
|
// hop logic.
|
||||||
waitForInvoiceAccepted(t, carol, payHash)
|
waitForInvoiceAccepted(t, carol, payHash)
|
||||||
|
|
||||||
restartBob, err := net.SuspendNode(net.Bob)
|
restartBob, err := net.SuspendNode(bob)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to suspend bob: %v", err)
|
t.Fatalf("unable to suspend bob: %v", err)
|
||||||
}
|
}
|
||||||
@@ -231,7 +233,7 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
// Once the second-level transaction confirmed, Bob should have
|
// Once the second-level transaction confirmed, Bob should have
|
||||||
// extracted the preimage from the chain, and sent it back to Alice,
|
// extracted the preimage from the chain, and sent it back to Alice,
|
||||||
// clearing the HTLC off-chain.
|
// clearing the HTLC off-chain.
|
||||||
nodes = []*lntest.HarnessNode{net.Alice}
|
nodes = []*lntest.HarnessNode{alice}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
predErr = assertNumActiveHtlcs(nodes, 0)
|
predErr = assertNumActiveHtlcs(nodes, 0)
|
||||||
if predErr != nil {
|
if predErr != nil {
|
||||||
@@ -303,7 +305,7 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
// succeeded.
|
// succeeded.
|
||||||
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout)
|
||||||
err = checkPaymentStatus(
|
err = checkPaymentStatus(
|
||||||
ctxt, net.Alice, preimage, lnrpc.Payment_SUCCEEDED,
|
ctxt, alice, preimage, lnrpc.Payment_SUCCEEDED,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf(err.Error())
|
t.Fatalf(err.Error())
|
||||||
@@ -312,5 +314,5 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
// We'll close out the channel between Alice and Bob, then shutdown
|
// We'll close out the channel between Alice and Bob, then shutdown
|
||||||
// carol to conclude the test.
|
// carol to conclude the test.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
||||||
closeChannelAndAssert(ctxt, t, net, net.Alice, aliceChanPoint, false)
|
closeChannelAndAssert(ctxt, t, net, alice, aliceChanPoint, false)
|
||||||
}
|
}
|
||||||
@@ -22,14 +22,16 @@ import (
|
|||||||
// we found out the preimage via the witness beacon, we properly settle the
|
// we found out the preimage via the witness beacon, we properly settle the
|
||||||
// HTLC directly on-chain using the preimage in order to ensure that we don't
|
// HTLC directly on-chain using the preimage in order to ensure that we don't
|
||||||
// lose any funds.
|
// lose any funds.
|
||||||
func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest) {
|
func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
||||||
|
alice, bob *lntest.HarnessNode) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
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 := createThreeHopNetwork(
|
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
|
||||||
t, net, false,
|
t, net, alice, bob, false,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Clean up carol's node when the test finishes.
|
// Clean up carol's node when the test finishes.
|
||||||
@@ -59,7 +61,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
|||||||
ctx, cancel := context.WithCancel(ctxb)
|
ctx, cancel := context.WithCancel(ctxb)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
alicePayStream, err := net.Alice.SendPayment(ctx)
|
alicePayStream, err := alice.SendPayment(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create payment stream for alice: %v", err)
|
t.Fatalf("unable to create payment stream for alice: %v", err)
|
||||||
}
|
}
|
||||||
@@ -73,7 +75,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
|||||||
// 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.
|
||||||
var predErr error
|
var predErr error
|
||||||
nodes := []*lntest.HarnessNode{net.Alice, net.Bob, carol}
|
nodes := []*lntest.HarnessNode{alice, bob, carol}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
predErr = assertActiveHtlcs(nodes, payHash[:])
|
predErr = assertActiveHtlcs(nodes, payHash[:])
|
||||||
if predErr != nil {
|
if predErr != nil {
|
||||||
@@ -95,12 +97,12 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
|||||||
// immediately force close the channel by broadcast her commitment
|
// immediately force close the channel by broadcast her commitment
|
||||||
// transaction.
|
// transaction.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
||||||
aliceForceClose := closeChannelAndAssert(ctxt, t, net, net.Alice,
|
aliceForceClose := closeChannelAndAssert(ctxt, t, net, alice,
|
||||||
aliceChanPoint, true)
|
aliceChanPoint, true)
|
||||||
|
|
||||||
// Wait for the channel to be marked pending force close.
|
// Wait for the channel to be marked pending force close.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
err = waitForChannelPendingForceClose(ctxt, net.Alice, aliceChanPoint)
|
err = waitForChannelPendingForceClose(ctxt, alice, aliceChanPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("channel not pending force close: %v", err)
|
t.Fatalf("channel not pending force close: %v", err)
|
||||||
}
|
}
|
||||||
@@ -119,7 +121,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Suspend bob, so Carol is forced to go on chain.
|
// Suspend bob, so Carol is forced to go on chain.
|
||||||
restartBob, err := net.SuspendNode(net.Bob)
|
restartBob, err := net.SuspendNode(bob)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to suspend bob: %v", err)
|
t.Fatalf("unable to suspend bob: %v", err)
|
||||||
}
|
}
|
||||||
@@ -256,7 +258,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
|||||||
pendingChansRequest := &lnrpc.PendingChannelsRequest{}
|
pendingChansRequest := &lnrpc.PendingChannelsRequest{}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
pendingChanResp, err := net.Bob.PendingChannels(
|
pendingChanResp, err := bob.PendingChannels(
|
||||||
ctxt, pendingChansRequest,
|
ctxt, pendingChansRequest,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -338,7 +340,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
|||||||
// succeeded.
|
// succeeded.
|
||||||
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout)
|
||||||
err = checkPaymentStatus(
|
err = checkPaymentStatus(
|
||||||
ctxt, net.Alice, preimage, lnrpc.Payment_SUCCEEDED,
|
ctxt, alice, preimage, lnrpc.Payment_SUCCEEDED,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf(err.Error())
|
t.Fatalf(err.Error())
|
||||||
|
|||||||
@@ -20,14 +20,16 @@ import (
|
|||||||
// that's timed out. At this point, the node should timeout the HTLC using the
|
// that's timed out. At this point, the node should timeout the HTLC using the
|
||||||
// HTLC timeout transaction, then cancel it backwards as normal.
|
// HTLC timeout transaction, then cancel it backwards as normal.
|
||||||
func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
||||||
t *harnessTest) {
|
t *harnessTest, alice, bob *lntest.HarnessNode) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
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 :=
|
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
|
||||||
createThreeHopNetwork(t, net, true)
|
t, net, alice, bob, true,
|
||||||
|
)
|
||||||
|
|
||||||
// Clean up carol's node when the test finishes.
|
// Clean up carol's node when the test finishes.
|
||||||
defer shutdownAndAssert(net, t, carol)
|
defer shutdownAndAssert(net, t, carol)
|
||||||
@@ -42,7 +44,7 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
ctx, cancel := context.WithCancel(ctxb)
|
ctx, cancel := context.WithCancel(ctxb)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
alicePayStream, err := net.Alice.SendPayment(ctx)
|
alicePayStream, err := alice.SendPayment(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create payment stream for alice: %v", err)
|
t.Fatalf("unable to create payment stream for alice: %v", err)
|
||||||
}
|
}
|
||||||
@@ -63,7 +65,7 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
// Once the HTLC has cleared, all channels in our mini network should
|
// Once the HTLC has cleared, all channels in our mini network should
|
||||||
// have the it locked in.
|
// have the it locked in.
|
||||||
var predErr error
|
var predErr error
|
||||||
nodes := []*lntest.HarnessNode{net.Alice, net.Bob, carol}
|
nodes := []*lntest.HarnessNode{alice, bob, carol}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
predErr = assertActiveHtlcs(nodes, payHash)
|
predErr = assertActiveHtlcs(nodes, payHash)
|
||||||
if predErr != nil {
|
if predErr != nil {
|
||||||
@@ -80,14 +82,14 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
// force close the Bob -> Carol channel. This should trigger contract
|
// force close the Bob -> Carol channel. This should trigger contract
|
||||||
// resolution mode for both of them.
|
// resolution mode for both of them.
|
||||||
ctxt, _ := context.WithTimeout(ctxb, channelCloseTimeout)
|
ctxt, _ := context.WithTimeout(ctxb, channelCloseTimeout)
|
||||||
closeChannelAndAssert(ctxt, t, net, net.Bob, bobChanPoint, true)
|
closeChannelAndAssert(ctxt, t, net, bob, bobChanPoint, true)
|
||||||
|
|
||||||
// At this point, Bob should have a pending force close channel as he
|
// At this point, Bob should have a pending force close channel as he
|
||||||
// just went to chain.
|
// just went to chain.
|
||||||
pendingChansRequest := &lnrpc.PendingChannelsRequest{}
|
pendingChansRequest := &lnrpc.PendingChannelsRequest{}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
pendingChanResp, err := net.Bob.PendingChannels(ctxt,
|
pendingChanResp, err := bob.PendingChannels(ctxt,
|
||||||
pendingChansRequest)
|
pendingChansRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
predErr = fmt.Errorf("unable to query for pending "+
|
predErr = fmt.Errorf("unable to query for pending "+
|
||||||
@@ -136,7 +138,7 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
// that's now in stage one.
|
// that's now in stage one.
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
pendingChanResp, err := net.Bob.PendingChannels(
|
pendingChanResp, err := bob.PendingChannels(
|
||||||
ctxt, pendingChansRequest,
|
ctxt, pendingChansRequest,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -183,7 +185,7 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
|
|
||||||
// With the second layer timeout transaction confirmed, Bob should have
|
// With the second layer timeout transaction confirmed, Bob should have
|
||||||
// canceled backwards the HTLC that carol sent.
|
// canceled backwards the HTLC that carol sent.
|
||||||
nodes = []*lntest.HarnessNode{net.Alice}
|
nodes = []*lntest.HarnessNode{alice}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
predErr = assertNumActiveHtlcs(nodes, 0)
|
predErr = assertNumActiveHtlcs(nodes, 0)
|
||||||
if predErr != nil {
|
if predErr != nil {
|
||||||
@@ -199,7 +201,7 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
// second stage.
|
// second stage.
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
pendingChanResp, err := net.Bob.PendingChannels(
|
pendingChanResp, err := bob.PendingChannels(
|
||||||
ctxt, pendingChansRequest,
|
ctxt, pendingChansRequest,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -253,7 +255,7 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
// close.
|
// close.
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
pendingChanResp, err := net.Bob.PendingChannels(
|
pendingChanResp, err := bob.PendingChannels(
|
||||||
ctxt, pendingChansRequest,
|
ctxt, pendingChansRequest,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -274,5 +276,5 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
||||||
closeChannelAndAssert(ctxt, t, net, net.Alice, aliceChanPoint, false)
|
closeChannelAndAssert(ctxt, t, net, alice, aliceChanPoint, false)
|
||||||
}
|
}
|
||||||
@@ -20,14 +20,16 @@ import (
|
|||||||
// transaction once the timeout has expired. Once we sweep the transaction, we
|
// transaction once the timeout has expired. Once we sweep the transaction, we
|
||||||
// should also cancel back the initial HTLC.
|
// should also cancel back the initial HTLC.
|
||||||
func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
||||||
t *harnessTest) {
|
t *harnessTest, alice, bob *lntest.HarnessNode) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
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 :=
|
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
|
||||||
createThreeHopNetwork(t, net, true)
|
t, net, alice, bob, true,
|
||||||
|
)
|
||||||
|
|
||||||
// Clean up carol's node when the test finishes.
|
// Clean up carol's node when the test finishes.
|
||||||
defer shutdownAndAssert(net, t, carol)
|
defer shutdownAndAssert(net, t, carol)
|
||||||
@@ -43,7 +45,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
ctx, cancel := context.WithCancel(ctxb)
|
ctx, cancel := context.WithCancel(ctxb)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
alicePayStream, err := net.Alice.SendPayment(ctx)
|
alicePayStream, err := alice.SendPayment(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create payment stream for alice: %v", err)
|
t.Fatalf("unable to create payment stream for alice: %v", err)
|
||||||
}
|
}
|
||||||
@@ -64,7 +66,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
// Once the HTLC has cleared, all the nodes in our mini network should
|
// Once the HTLC has cleared, all the nodes in our mini network should
|
||||||
// show that the HTLC has been locked in.
|
// show that the HTLC has been locked in.
|
||||||
var predErr error
|
var predErr error
|
||||||
nodes := []*lntest.HarnessNode{net.Alice, net.Bob, carol}
|
nodes := []*lntest.HarnessNode{alice, bob, carol}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
predErr = assertActiveHtlcs(nodes, payHash)
|
predErr = assertActiveHtlcs(nodes, payHash)
|
||||||
if predErr != nil {
|
if predErr != nil {
|
||||||
@@ -88,7 +90,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
pendingChansRequest := &lnrpc.PendingChannelsRequest{}
|
pendingChansRequest := &lnrpc.PendingChannelsRequest{}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
pendingChanResp, err := net.Bob.PendingChannels(
|
pendingChanResp, err := bob.PendingChannels(
|
||||||
ctxt, pendingChansRequest,
|
ctxt, pendingChansRequest,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -128,7 +130,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
// first stage since this is a direct HTLC.
|
// first stage since this is a direct HTLC.
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
pendingChanResp, err := net.Bob.PendingChannels(
|
pendingChanResp, err := bob.PendingChannels(
|
||||||
ctxt, pendingChansRequest,
|
ctxt, pendingChansRequest,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -191,7 +193,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
// Now that the sweeping transaction has been confirmed, Bob should
|
// Now that the sweeping transaction has been confirmed, Bob should
|
||||||
// cancel back that HTLC. As a result, Alice should not know of any
|
// cancel back that HTLC. As a result, Alice should not know of any
|
||||||
// active HTLC's.
|
// active HTLC's.
|
||||||
nodes = []*lntest.HarnessNode{net.Alice}
|
nodes = []*lntest.HarnessNode{alice}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
predErr = assertNumActiveHtlcs(nodes, 0)
|
predErr = assertNumActiveHtlcs(nodes, 0)
|
||||||
if predErr != nil {
|
if predErr != nil {
|
||||||
@@ -208,7 +210,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
// he should show no additional pending transactions.
|
// he should show no additional pending transactions.
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
pendingChanResp, err := net.Bob.PendingChannels(
|
pendingChanResp, err := bob.PendingChannels(
|
||||||
ctxt, pendingChansRequest,
|
ctxt, pendingChansRequest,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -232,5 +234,5 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
// and then shutting down the new node we created as its no longer
|
// and then shutting down the new node we created as its no longer
|
||||||
// needed.
|
// needed.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
||||||
closeChannelAndAssert(ctxt, t, net, net.Alice, aliceChanPoint, false)
|
closeChannelAndAssert(ctxt, t, net, alice, aliceChanPoint, false)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user