Skip to content

Commit

Permalink
itest+lntest: fix flake in MPP-related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yyforyongyu committed Nov 25, 2024
1 parent 1499901 commit 64a59ac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
26 changes: 26 additions & 0 deletions itest/lnd_mpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,32 @@ func (c *mppTestScenario) setupSendPaymentCase() btcutil.Amount {
// - 2nd attempt(75,000 sats): Alice->Dave->Bob: 155,000 sats.
// - 3rd attempt(75,000 sats): Alice->Carol->Eve->Bob: 155,000 sats.
//
// There is a case where the payment will fail due to the channel
// capacity not being updated in the graph, which has been seen many
// times:
// 1. the 1st attempt (150,000 sats) is sent via
// Alice->Carol->Eve->Bob, after which the capacity in Carol->Eve
// should decrease.
// 2. the 2nd attempt (75,000 sats) is sent via Alice->Carol->Eve->Bob,
// which shouldn't happen because the capacity in Carol->Eve is
// depleted. However, since the HTLCs are sent in parallel, the 2nd
// attempt can be sent before the capacity is updated in the graph.
// 3. if the 2nd attempt succeeds, the 1st attempt will fail and be
// split into two attempts, each holding 75,000 sats. At this point,
// we have three attempts to send, but only two routes are
// available, causing the payment to be failed.
// 4. In addition, with recent fee buffer addition, the attempts will
// fail even earlier without being further split.
//
// To avoid this case, we now increase the channel capacity of the
// route Carol->Eve->Bob such that even the above case happened, we can
// still send the HTLCs.
//
// TODO(yy): we should properly fix this in the router. Atm we only
// perform this hack to unblock the CI.
req.amtEveBob = 285_000
req.amtCarolEve = 285_000

// Open the channels as described above.
c.openChannels(req)

Expand Down
7 changes: 4 additions & 3 deletions lntest/harness_assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -1513,13 +1513,14 @@ func (h *HarnessTest) AssertNumHTLCsAndStage(hn *node.HarnessNode,
lnutils.SpewLogClosure(target.PendingHtlcs)())
}

for i, htlc := range target.PendingHtlcs {
for _, htlc := range target.PendingHtlcs {
if htlc.Stage == stage {
continue
}

return fmt.Errorf("HTLC %d got stage: %v, "+
"want stage: %v", i, htlc.Stage, stage)
return fmt.Errorf("HTLC %s got stage: %v, "+
"want stage: %v", htlc.Outpoint, htlc.Stage,
stage)
}

return nil
Expand Down

0 comments on commit 64a59ac

Please sign in to comment.