From 0d0477d661e382e9b20cef337983ea731c8485ed Mon Sep 17 00:00:00 2001 From: d11n Date: Tue, 20 Jun 2023 10:28:16 +0200 Subject: [PATCH] Lightning: Relax GetInfo constraint for LNDhub connections (#5083) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Lightning: Relax GetInfo constraint for LNDhub connections The LNDhub-compatible implementation by LNbits does not support the `GetInfo` call for all their funding sources — see lnbits/lnbits#1182. By catching that exception in combination with the `LndHubLightningClient`, we give people the ability to still use their LNbits-based LNDhub as a Lightning node. Fixes #4482. * Update approach to handling unsupported GetInfo calls --- BTCPayServer/BTCPayServer.csproj | 2 +- .../Lightning/LightningLikePaymentHandler.cs | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index 347d60944..e6d131559 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -48,7 +48,7 @@ - + diff --git a/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs b/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs index 3d9fee8c8..7c2252301 100644 --- a/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs +++ b/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs @@ -9,6 +9,7 @@ using BTCPayServer.Configuration; using BTCPayServer.Data; using BTCPayServer.HostedServices; using BTCPayServer.Lightning; +using BTCPayServer.Lightning.LndHub; using BTCPayServer.Logging; using BTCPayServer.Models; using BTCPayServer.Models.InvoicingModels; @@ -122,11 +123,16 @@ namespace BTCPayServer.Payments.Lightning { if (!_Dashboard.IsFullySynched(network.CryptoCode, out var summary)) throw new PaymentMethodUnavailableException("Full node not available"); - + try { using var cts = new CancellationTokenSource(LightningTimeout); var client = CreateLightningClient(supportedPaymentMethod, network); + + // LNDhub-compatible implementations might not offer all of GetInfo data. + // Skip checks in those cases, see https://github.com/lnbits/lnbits/issues/1182 + var isLndHub = client is LndHubLightningClient; + LightningNodeInformation info; try { @@ -136,6 +142,10 @@ namespace BTCPayServer.Payments.Lightning { throw new PaymentMethodUnavailableException("The lightning node did not reply in a timely manner"); } + catch (NotSupportedException) when (isLndHub) + { + return new NodeInfo[] {}; + } catch (Exception ex) { throw new PaymentMethodUnavailableException($"Error while connecting to the API: {ex.Message}" + @@ -146,9 +156,9 @@ namespace BTCPayServer.Payments.Lightning var nodeInfo = preferOnion != null && info.NodeInfoList.Any(i => i.IsTor == preferOnion) ? info.NodeInfoList.Where(i => i.IsTor == preferOnion.Value).ToArray() : info.NodeInfoList.Select(i => i).ToArray(); - + var blocksGap = summary.Status.ChainHeight - info.BlockHeight; - if (blocksGap > 10) + if (blocksGap > 10 && !(isLndHub && info.BlockHeight == 0)) { throw new PaymentMethodUnavailableException($"The lightning node is not synched ({blocksGap} blocks left)"); }