test: update switch persistence tests to account for bug fix in reconnection logic
With the recent bug fixes in the peer connection, it's no longer the case that just disconnecting a certain peer causes it to no longer connect to the other. As a result, we now shutdown Alice to ensure no reconnection occurs. We'll then later restart alice when we restart dave.
This commit is contained in:
parent
7f16e99a80
commit
179b25c580
54
lnd_test.go
54
lnd_test.go
@ -6787,6 +6787,27 @@ func assertActiveHtlcs(nodes []*lntest.HarnessNode, payHashes ...[]byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func assertNumActiveHtlcsChanPoint(node *lntest.HarnessNode,
|
||||||
|
chanPoint wire.OutPoint, numHtlcs int) bool {
|
||||||
|
|
||||||
|
req := &lnrpc.ListChannelsRequest{}
|
||||||
|
ctxb := context.Background()
|
||||||
|
nodeChans, err := node.ListChannels(ctxb, req)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, channel := range nodeChans.Channels {
|
||||||
|
if channel.ChannelPoint != chanPoint.String() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(channel.PendingHtlcs) == numHtlcs
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func assertNumActiveHtlcs(nodes []*lntest.HarnessNode, numHtlcs int) bool {
|
func assertNumActiveHtlcs(nodes []*lntest.HarnessNode, numHtlcs int) bool {
|
||||||
req := &lnrpc.ListChannelsRequest{}
|
req := &lnrpc.ListChannelsRequest{}
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
@ -9079,11 +9100,11 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
|
|||||||
t.Fatalf("htlc mismatch: %v", err)
|
t.Fatalf("htlc mismatch: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disconnect the two intermediaries, Alice and Dave, so that when carol
|
// Disconnect the two intermediaries, Alice and Dave, by shutting down
|
||||||
// restarts, the response will be held by Dave.
|
// Alice.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, timeout)
|
ctxt, _ = context.WithTimeout(ctxb, timeout)
|
||||||
if err := net.DisconnectNodes(ctxt, dave, net.Alice); err != nil {
|
if err := net.StopNode(net.Alice); err != nil {
|
||||||
t.Fatalf("unable to disconnect alice from dave: %v", err)
|
t.Fatalf("unable to shutdown alice: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now restart carol without hodl mode, to settle back the outstanding
|
// Now restart carol without hodl mode, to settle back the outstanding
|
||||||
@ -9101,10 +9122,12 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
|
|||||||
t.Fatalf("unable to reconnect dave and carol: %v", err)
|
t.Fatalf("unable to reconnect dave and carol: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for Carol to report no outstanding htlcs.
|
// Wait for Carol to report no outstanding htlcs, and also for Dav to
|
||||||
|
// receive all the settles from Carol.
|
||||||
carolNode := []*lntest.HarnessNode{carol}
|
carolNode := []*lntest.HarnessNode{carol}
|
||||||
err = lntest.WaitPredicate(func() bool {
|
err = lntest.WaitPredicate(func() bool {
|
||||||
return assertNumActiveHtlcs(carolNode, 0)
|
return assertNumActiveHtlcs(carolNode, 0) &&
|
||||||
|
assertNumActiveHtlcsChanPoint(dave, carolFundPoint, 0)
|
||||||
}, time.Second*15)
|
}, time.Second*15)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("htlc mismatch: %v", err)
|
t.Fatalf("htlc mismatch: %v", err)
|
||||||
@ -9113,7 +9136,10 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
|
|||||||
// Finally, restart dave who received the settles, but was unable to
|
// Finally, restart dave who received the settles, but was unable to
|
||||||
// deliver them to Alice since they were disconnected.
|
// deliver them to Alice since they were disconnected.
|
||||||
if err := net.RestartNode(dave, nil); err != nil {
|
if err := net.RestartNode(dave, nil); err != nil {
|
||||||
t.Fatalf("unable to reconnect alice to dave: %v", err)
|
t.Fatalf("unable to restart dave: %v", err)
|
||||||
|
}
|
||||||
|
if err = net.RestartNode(net.Alice, nil); err != nil {
|
||||||
|
t.Fatalf("unable to restart alice: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force Dave and Alice to reconnect before waiting for the htlcs to
|
// Force Dave and Alice to reconnect before waiting for the htlcs to
|
||||||
@ -9124,8 +9150,8 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
|
|||||||
t.Fatalf("unable to reconnect dave and carol: %v", err)
|
t.Fatalf("unable to reconnect dave and carol: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// After reconnection succeeds, the settles should be propagated all the
|
// After reconnection succeeds, the settles should be propagated all
|
||||||
// way back to the sender. All nodes should report no active htlcs.
|
// the way back to the sender. All nodes should report no active htlcs.
|
||||||
err = lntest.WaitPredicate(func() bool {
|
err = lntest.WaitPredicate(func() bool {
|
||||||
return assertNumActiveHtlcs(nodes, 0)
|
return assertNumActiveHtlcs(nodes, 0)
|
||||||
}, time.Second*15)
|
}, time.Second*15)
|
||||||
@ -9410,8 +9436,8 @@ func testSwitchOfflineDeliveryOutgoingOffline(
|
|||||||
// Disconnect the two intermediaries, Alice and Dave, so that when carol
|
// Disconnect the two intermediaries, Alice and Dave, so that when carol
|
||||||
// restarts, the response will be held by Dave.
|
// restarts, the response will be held by Dave.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, timeout)
|
ctxt, _ = context.WithTimeout(ctxb, timeout)
|
||||||
if err := net.DisconnectNodes(ctxt, dave, net.Alice); err != nil {
|
if err := net.StopNode(net.Alice); err != nil {
|
||||||
t.Fatalf("unable to disconnect alice from dave: %v", err)
|
t.Fatalf("unable to shutdown alice: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now restart carol without hodl mode, to settle back the outstanding
|
// Now restart carol without hodl mode, to settle back the outstanding
|
||||||
@ -9424,7 +9450,8 @@ func testSwitchOfflineDeliveryOutgoingOffline(
|
|||||||
// Wait for Carol to report no outstanding htlcs.
|
// Wait for Carol to report no outstanding htlcs.
|
||||||
carolNode := []*lntest.HarnessNode{carol}
|
carolNode := []*lntest.HarnessNode{carol}
|
||||||
err = lntest.WaitPredicate(func() bool {
|
err = lntest.WaitPredicate(func() bool {
|
||||||
return assertNumActiveHtlcs(carolNode, 0)
|
return assertNumActiveHtlcs(carolNode, 0) &&
|
||||||
|
assertNumActiveHtlcsChanPoint(dave, carolFundPoint, 0)
|
||||||
}, time.Second*15)
|
}, time.Second*15)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("htlc mismatch: %v", err)
|
t.Fatalf("htlc mismatch: %v", err)
|
||||||
@ -9451,6 +9478,9 @@ func testSwitchOfflineDeliveryOutgoingOffline(
|
|||||||
if err := net.RestartNode(dave, nil); err != nil {
|
if err := net.RestartNode(dave, nil); err != nil {
|
||||||
t.Fatalf("unable to restart dave: %v", err)
|
t.Fatalf("unable to restart dave: %v", err)
|
||||||
}
|
}
|
||||||
|
if err = net.RestartNode(net.Alice, nil); err != nil {
|
||||||
|
t.Fatalf("unable to restart alice: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure that Dave is reconnected to Alice before waiting for the htlcs
|
// Ensure that Dave is reconnected to Alice before waiting for the htlcs
|
||||||
// to clear.
|
// to clear.
|
||||||
|
Loading…
Reference in New Issue
Block a user