Skip to content

Commit d122a2e

Browse files
committed
itest+lntest: add flakePaymentStreamReturnEarly
Fix the flake found in the `testRelayingBlindedError` and documents the flake found in other tests in one place.
1 parent e029608 commit d122a2e

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

itest/flakes.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,22 @@ func flakeInconsistentHTLCView() {
142142
// the ListChannels.
143143
time.Sleep(2 * time.Second)
144144
}
145+
146+
// flakePaymentStreamReturnEarly documents a flake found in the test which
147+
// relies on a given payment to be settled before testing other state changes.
148+
// The issue comes from the payment stream created from the RPC `SendPaymentV2`
149+
// gives premature settled event for a given payment, which is found in,
150+
// - if we force close the channel immediately, we may get an error because
151+
// the commitment dance is not finished.
152+
// - if we subscribe HTLC events immediately, we may get extra events, which
153+
// is also related to the above unfinished commitment dance.
154+
//
155+
// TODO(yy): Make sure we only mark the payment being settled once the
156+
// commitment dance is finished. In addition, we should also fix the exit hop
157+
// logic in the invoice settlement flow to make sure the invoice is only marked
158+
// as settled after the commitment dance is finished.
159+
func flakePaymentStreamReturnEarly() {
160+
// Sleep 2 seconds so the pending HTLCs will be removed from the
161+
// commitment.
162+
time.Sleep(2 * time.Second)
163+
}

itest/lnd_channel_backup_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,13 +1224,7 @@ func testDataLossProtection(ht *lntest.HarnessTest) {
12241224
// payment hashes.
12251225
ht.CompletePaymentRequests(carol, payReqs[numInvoices/2:])
12261226

1227-
// TODO(yy): remove the sleep once the following bug is fixed.
1228-
//
1229-
// While the payment is reported as settled, the commitment
1230-
// dance may not be finished, which leaves several HTLCs in the
1231-
// commitment. Later on, when Carol force closes this channel,
1232-
// she would have HTLCs there and the test won't pass.
1233-
time.Sleep(2 * time.Second)
1227+
flakePaymentStreamReturnEarly()
12341228

12351229
// Now we shutdown Dave, copying over the its temporary
12361230
// database state which has the *prior* channel state over his

itest/lnd_route_blinding_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,10 @@ func testRelayingBlindedError(ht *lntest.HarnessTest) {
667667
// so that she can't forward the payment to Dave.
668668
testCase.drainCarolLiquidity(false)
669669

670+
// NOTE: The above draining requires Carol to send a payment, which may
671+
// create extra events, causing the `AssertHtlcEvents` to fail below.
672+
flakePaymentStreamReturnEarly()
673+
670674
// Subscribe to Carol's HTLC events so that we can observe the payment
671675
// coming in.
672676
carolEvents := testCase.carol.RPC.SubscribeHtlcEvents()

itest/lnd_wipe_fwdpkgs_test.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package itest
22

33
import (
4-
"time"
5-
64
"github.com/lightningnetwork/lnd/chainreg"
75
"github.com/lightningnetwork/lnd/lnrpc"
86
"github.com/lightningnetwork/lnd/lntest"
@@ -49,13 +47,7 @@ func testWipeForwardingPackages(ht *lntest.HarnessTest) {
4947
ht.CompletePaymentRequests(alice, []string{resp.PaymentRequest})
5048
}
5149

52-
// TODO(yy): remove the sleep once the following bug is fixed.
53-
// When the invoice is reported settled, the commitment dance is not
54-
// yet finished, which can cause an error when closing the channel,
55-
// saying there's active HTLCs. We need to investigate this issue and
56-
// reverse the order to, first finish the commitment dance, then report
57-
// the invoice as settled.
58-
time.Sleep(2 * time.Second)
50+
flakePaymentStreamReturnEarly()
5951

6052
// Firstly, Bob force closes the channel.
6153
ht.CloseChannelAssertPending(bob, chanPointAB, true)

lntest/harness_assertion.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2329,7 +2329,8 @@ func (h *HarnessTest) AssertHtlcEvents(client rpc.HtlcEventsClient,
23292329
event := h.ReceiveHtlcEvent(client)
23302330

23312331
require.Containsf(h, eventTypes, event.EventType,
2332-
"wrong event type, got %v", userType, event.EventType)
2332+
"wrong event type, want %v, got %v", userType,
2333+
event.EventType)
23332334

23342335
events = append(events, event)
23352336

0 commit comments

Comments
 (0)