Skip to content

Commit

Permalink
itest: set error codes for failed lnd payments
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Nov 21, 2024
1 parent 46b2571 commit f147b24
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion itest/lntest/lnd_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,28 @@ func (n *LndNode) PayViaRoute(amountMsat uint64, paymentHash []byte, paymentSecr
}

if resp.PaymentRoute == nil {
n.harness.T.Fatal(fmt.Errorf("missing payment route after pay"))
payments, err := n.runtime.rpc.ListPayments(n.harness.Ctx, &lnd.ListPaymentsRequest{
IncludeIncomplete: true,
})
CheckError(n.harness.T, err)

paymentHashStr := hex.EncodeToString(paymentHash)
for _, payment := range payments.Payments {
if payment.PaymentHash != paymentHashStr {
continue
}

switch payment.Htlcs[0].Failure.Code {
case lnd.Failure_TEMPORARY_CHANNEL_FAILURE:
return nil, fmt.Errorf("WIRE_TEMPORARY_CHANNEL_FAILURE")
case lnd.Failure_UNKNOWN_NEXT_PEER:
return nil, fmt.Errorf("WIRE_UNKNOWN_NEXT_PEER")
case lnd.Failure_UNKNOWN_FAILURE:
return nil, fmt.Errorf("WIRE_TEMPORARY_CHANNEL_FAILURE")
}
}

return nil, fmt.Errorf("missing payment route after pay")
}

lastHop := resp.PaymentRoute.Hops[len(resp.PaymentRoute.Hops)-1]
Expand Down

0 comments on commit f147b24

Please sign in to comment.