From 3f12b641a5606ee6c4554f027a404a85a3057ba4 Mon Sep 17 00:00:00 2001 From: lollerfirst Date: Thu, 9 Jan 2025 16:19:19 +0100 Subject: [PATCH] Lnd gRPC --- cashu/lightning/lnd_grpc/lnd_grpc.py | 33 ++++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/cashu/lightning/lnd_grpc/lnd_grpc.py b/cashu/lightning/lnd_grpc/lnd_grpc.py index d6b8cb0f..10e5dcf8 100644 --- a/cashu/lightning/lnd_grpc/lnd_grpc.py +++ b/cashu/lightning/lnd_grpc/lnd_grpc.py @@ -245,21 +245,26 @@ async def pay_partial_invoice( ) """ # modify the mpp_record in the last hop - route_nr = 0 - r.routes[route_nr].hops[-1].mpp_record.payment_addr = bytes.fromhex( # type: ignore - payer_addr - ) - r.routes[route_nr].hops[ # type: ignore - -1 - ].mpp_record.total_amt_msat = total_amount_msat - - # Send to route request - r = await router_stub.SendToRouteV2( - routerrpc.SendToRouteRequest( - payment_hash=bytes.fromhex(invoice.payment_hash), - route=r.routes[route_nr], # type: ignore + for route_nr in range(len(r.routes)): + r.routes[route_nr].hops[-1].mpp_record.payment_addr = bytes.fromhex( # type: ignore + payer_addr ) - ) + r.routes[route_nr].hops[ # type: ignore + -1 + ].mpp_record.total_amt_msat = total_amount_msat + + # Send to route request + r = await router_stub.SendToRouteV2( + routerrpc.SendToRouteRequest( + payment_hash=bytes.fromhex(invoice.payment_hash), + route=r.routes[route_nr], # type: ignore + ) + ) + if r.status == lnrpc.HTLCAttempt.HTLCStatus.FAILED: + if r.failure.code == lnrpc.Failure.FailureCode.TEMPORARY_CHANNEL_FAILURE: + # Try a different route + continue + break except AioRpcError as e: logger.error(f"QueryRoute or SendToRouteV2 failed: {e}") return PaymentResponse(