Skip to content

Commit

Permalink
lsps2: temporary_channel_failure on low funds
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Sep 8, 2023
1 parent c56fd28 commit 4179176
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cln/cln_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

Expand Down
9 changes: 8 additions & 1 deletion lsps2/intercept_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"math"
"strings"
"time"

"github.com/breez/lspd/chain"
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 4179176

Please sign in to comment.