@@ -1619,8 +1619,9 @@ func (h *HarnessTest) CompletePaymentRequests(hn *node.HarnessNode,
16191619}
16201620
16211621// CompletePaymentRequestsNoWait sends payments from a node to complete all
1622- // payment requests without waiting for the results. Instead, it checks the
1623- // number of updates in the specified channel has increased.
1622+ // payment requests without waiting for the results. Instead, it waits for
1623+ // all HTLCs to be locked in on the sender's channel by checking the number
1624+ // of pending HTLCs.
16241625func (h * HarnessTest ) CompletePaymentRequestsNoWait (hn * node.HarnessNode ,
16251626 paymentRequests []string , chanPoint * lnrpc.ChannelPoint ) {
16261627
@@ -1629,31 +1630,50 @@ func (h *HarnessTest) CompletePaymentRequestsNoWait(hn *node.HarnessNode,
16291630 // we return.
16301631 oldResp := h .GetChannelByChanPoint (hn , chanPoint )
16311632
1633+ // countOutgoing counts the number of outgoing HTLCs in the given list.
1634+ countOutgoing := func (htlcs []* lnrpc.HTLC ) int {
1635+ count := 0
1636+ for _ , htlc := range htlcs {
1637+ if ! htlc .Incoming {
1638+ count ++
1639+ }
1640+ }
1641+
1642+ return count
1643+ }
1644+
1645+ // Count existing outgoing HTLCs before sending.
1646+ oldOutgoingCount := countOutgoing (oldResp .PendingHtlcs )
1647+
1648+ numPayments := len (paymentRequests )
1649+
16321650 // Send payments and assert they are in-flight.
16331651 h .completePaymentRequestsAssertStatus (
16341652 hn , paymentRequests , lnrpc .Payment_IN_FLIGHT ,
16351653 )
16361654
1637- // We are not waiting for feedback in the form of a response, but we
1638- // should still wait long enough for the server to receive and handle
1639- // the send before cancelling the request. We wait for the number of
1640- // updates to one of our channels has increased before we return .
1655+ // Wait for all HTLCs to be locked in. We check that the number of
1656+ // outgoing pending HTLCs has increased by exactly the number of
1657+ // payments sent. This ensures all HTLCs are committed on the sender's
1658+ // side .
16411659 err := wait .NoError (func () error {
16421660 newResp := h .GetChannelByChanPoint (hn , chanPoint )
16431661
1644- // If this channel has an increased number of updates, we
1645- // assume the payments are committed, and we can return.
1646- if newResp .NumUpdates > oldResp .NumUpdates {
1662+ // Count current outgoing HTLCs.
1663+ newOutgoingCount := countOutgoing (newResp .PendingHtlcs )
1664+
1665+ htlcsAdded := newOutgoingCount - oldOutgoingCount
1666+
1667+ // Verify all HTLCs are locked in.
1668+ if htlcsAdded == numPayments {
16471669 return nil
16481670 }
16491671
1650- // Otherwise return an error as the NumUpdates are not
1651- // increased.
1652- return fmt .Errorf ("%s: channel:%v not updated after sending " +
1653- "payments, old updates: %v, new updates: %v" , hn .Name (),
1654- chanPoint , oldResp .NumUpdates , newResp .NumUpdates )
1672+ return fmt .Errorf ("%s: channel:%v waiting for HTLCs, " +
1673+ "added: %d/%d" , hn .Name (), chanPoint ,
1674+ htlcsAdded , numPayments )
16551675 }, DefaultTimeout )
1656- require .NoError (h , err , "timeout while checking for channel updates " )
1676+ require .NoError (h , err , "timeout while waiting for HTLCs to lock in " )
16571677}
16581678
16591679// OpenChannelPsbt attempts to open a channel between srcNode and destNode with
0 commit comments