Skip to content

Commit 67e9826

Browse files
committed
lnwallet/chancloser: fix flake in TestRbfCloseClosingNegotiationLocal
In this commit, we fix a flake in the rbf loop sub-test for the TestRbfCloseClosingNegotiationLocal test case. The fix here is that when we go from ClosePending for an RBF iteration loop, we first transition to LocalCloseStart. However we only do this extra transition if we're doing an iteration (starting from ClosePending). To fix this, we add a new bool that tracks if this is an iteration or not. We can then also eliminate the extra assertion at the end, as we'll terminate in `ClosePending` which is checked by `assertLocalClosePending()` in `assertSingleRbfIteration`. Fixes #9526.
1 parent 193d2a6 commit 67e9826

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

lnwallet/chancloser/rbf_coop_test.go

+18-20
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ func (d dustExpectation) String() string {
508508
// message to the remote party, and all the other intermediate steps.
509509
func (r *rbfCloserTestHarness) expectHalfSignerIteration(
510510
initEvent ProtocolEvent, balanceAfterClose, absoluteFee btcutil.Amount,
511-
dustExpect dustExpectation) {
511+
dustExpect dustExpectation, iteration bool) {
512512

513513
ctx := context.Background()
514514
numFeeCalls := 2
@@ -569,8 +569,14 @@ func (r *rbfCloserTestHarness) expectHalfSignerIteration(
569569
}
570570

571571
case *SendOfferEvent:
572-
573572
expectedStates = []RbfState{&ClosingNegotiation{}}
573+
574+
// If we're in the middle of an iteration, then we expect a transition
575+
// from ClosePending -> LocalCloseStart.
576+
if iteration {
577+
expectedStates = append(expectedStates, &ClosingNegotiation{})
578+
}
579+
574580
case *ChannelFlushed:
575581
// If we're sending a flush event here, then this means that we
576582
// also have enough balance to cover the fee so we'll have
@@ -585,10 +591,6 @@ func (r *rbfCloserTestHarness) expectHalfSignerIteration(
585591

586592
// We should transition from the negotiation state back to
587593
// itself.
588-
//
589-
// TODO(roasbeef): take in expected set of transitions!!!
590-
// * or base off of event, if shutdown recv'd know we're doing a full
591-
// loop
592594
r.assertStateTransitions(expectedStates...)
593595

594596
// If we examine the final resting state, we should see that
@@ -610,14 +612,15 @@ func (r *rbfCloserTestHarness) expectHalfSignerIteration(
610612

611613
func (r *rbfCloserTestHarness) assertSingleRbfIteration(
612614
initEvent ProtocolEvent, balanceAfterClose, absoluteFee btcutil.Amount,
613-
dustExpect dustExpectation) {
615+
dustExpect dustExpectation, iteration bool) {
614616

615617
ctx := context.Background()
616618

617619
// We'll now send in the send offer event, which should trigger 1/2 of
618620
// the RBF loop, ending us in the LocalOfferSent state.
619621
r.expectHalfSignerIteration(
620622
initEvent, balanceAfterClose, absoluteFee, noDustExpect,
623+
iteration,
621624
)
622625

623626
// Now that we're in the local offer sent state, we'll send the
@@ -1299,7 +1302,7 @@ func TestRbfChannelFlushingTransitions(t *testing.T) {
12991302
// flow.
13001303
closeHarness.expectHalfSignerIteration(
13011304
&flushEvent, balanceAfterClose, absoluteFee,
1302-
noDustExpect,
1305+
noDustExpect, false,
13031306
)
13041307
})
13051308
}
@@ -1418,7 +1421,7 @@ func TestRbfCloseClosingNegotiationLocal(t *testing.T) {
14181421
// pending state.
14191422
closeHarness.assertSingleRbfIteration(
14201423
sendOfferEvent, balanceAfterClose, absoluteFee,
1421-
noDustExpect,
1424+
noDustExpect, false,
14221425
)
14231426
})
14241427

@@ -1434,7 +1437,7 @@ func TestRbfCloseClosingNegotiationLocal(t *testing.T) {
14341437
// event to advance the state machine.
14351438
closeHarness.expectHalfSignerIteration(
14361439
sendOfferEvent, balanceAfterClose, absoluteFee,
1437-
noDustExpect,
1440+
noDustExpect, false,
14381441
)
14391442

14401443
// We'll now craft the local sig received event, but this time
@@ -1489,7 +1492,7 @@ func TestRbfCloseClosingNegotiationLocal(t *testing.T) {
14891492
// proper field is set.
14901493
closeHarness.expectHalfSignerIteration(
14911494
sendOfferEvent, balanceAfterClose, absoluteFee,
1492-
remoteDustExpect,
1495+
remoteDustExpect, false,
14931496
)
14941497
})
14951498

@@ -1516,7 +1519,7 @@ func TestRbfCloseClosingNegotiationLocal(t *testing.T) {
15161519
dustBalance := btcutil.Amount(100)
15171520
closeHarness.expectHalfSignerIteration(
15181521
sendOfferEvent, dustBalance, absoluteFee,
1519-
localDustExpect,
1522+
localDustExpect, false,
15201523
)
15211524
})
15221525

@@ -1581,7 +1584,7 @@ func TestRbfCloseClosingNegotiationLocal(t *testing.T) {
15811584
// assuming we start in this negotiation state.
15821585
closeHarness.assertSingleRbfIteration(
15831586
sendOfferEvent, balanceAfterClose, absoluteFee,
1584-
noDustExpect,
1587+
noDustExpect, false,
15851588
)
15861589

15871590
// Next, we'll send in a new SendOfferEvent event which
@@ -1596,12 +1599,7 @@ func TestRbfCloseClosingNegotiationLocal(t *testing.T) {
15961599
// initiate a new local sig).
15971600
closeHarness.assertSingleRbfIteration(
15981601
localOffer, balanceAfterClose, absoluteFee,
1599-
noDustExpect,
1600-
)
1601-
1602-
// We should terminate in the negotiation state.
1603-
closeHarness.assertStateTransitions(
1604-
&ClosingNegotiation{},
1602+
noDustExpect, true,
16051603
)
16061604
})
16071605

@@ -2004,7 +2002,7 @@ func TestRbfCloseErr(t *testing.T) {
20042002
// initiate a new local sig).
20052003
closeHarness.assertSingleRbfIteration(
20062004
localOffer, balanceAfterClose, absoluteFee,
2007-
noDustExpect,
2005+
noDustExpect, false,
20082006
)
20092007

20102008
// We should terminate in the negotiation state.

0 commit comments

Comments
 (0)