From 417917623637fb5eb17416a268f0279922a028bc Mon Sep 17 00:00:00 2001 From: Jesse de Wit Date: Fri, 8 Sep 2023 14:35:07 +0200 Subject: [PATCH] lsps2: temporary_channel_failure on low funds --- cln/cln_client.go | 5 +++++ lsps2/intercept_handler.go | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cln/cln_client.go b/cln/cln_client.go index 29098064..5c5f53e6 100644 --- a/cln/cln_client.go +++ b/cln/cln_client.go @@ -12,6 +12,7 @@ import ( "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" "github.com/elementsproject/glightning/glightning" + "github.com/elementsproject/glightning/jrpc2" "golang.org/x/exp/slices" ) @@ -126,6 +127,10 @@ func (c *ClnClient) OpenChannel(req *lightning.OpenChannelRequest) (*wire.OutPoi if err != nil { log.Printf("CLN: client.FundChannelExt(%v, %v) error: %v", pubkey, req.CapacitySat, err) + rpcError, ok := err.(*jrpc2.RpcError) + if ok && rpcError.Code == 301 { + return nil, fmt.Errorf("not enough funds: %w", err) + } return nil, err } diff --git a/lsps2/intercept_handler.go b/lsps2/intercept_handler.go index 5a3ec6ed..91b9a811 100644 --- a/lsps2/intercept_handler.go +++ b/lsps2/intercept_handler.go @@ -6,6 +6,7 @@ import ( "fmt" "log" "math" + "strings" "time" "github.com/breez/lspd/chain" @@ -500,6 +501,12 @@ func (i *Interceptor) ensureChannelOpen(payment *paymentState) { capacity, err, ) + + code := shared.FAILURE_UNKNOWN_NEXT_PEER + if strings.Contains(err.Error(), "not enough funds") { + code = shared.FAILURE_TEMPORARY_CHANNEL_FAILURE + } + // TODO: Verify that a client disconnect before receiving // funding_signed doesn't cause the OpenChannel call to error. // unknown_next_peer should only be returned if the client rejects @@ -508,7 +515,7 @@ func (i *Interceptor) ensureChannelOpen(payment *paymentState) { // temporary_channel_failure should be returned. i.paymentFailure <- &paymentFailureEvent{ paymentId: payment.id, - code: shared.FAILURE_UNKNOWN_NEXT_PEER, + code: code, } return }