Do not throw when local node is not synced and using external ln node (#5859)

* Do not throw when local node is not synced and using external ln node

* Fix additional bug when ln conn strings without server would crash
This commit is contained in:
Andrew Camilleri 2024-03-22 10:06:38 +01:00 committed by GitHub
parent 6b0087ab69
commit 6b45eb0d3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 6 deletions

View file

@ -132,7 +132,7 @@ namespace BTCPayServer.Payments.Lightning
// 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
{
@ -163,11 +163,14 @@ namespace BTCPayServer.Payments.Lightning
? 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 && !(isLndHub && info.BlockHeight == 0))
if (summary.Status is not null)
{
throw new PaymentMethodUnavailableException(
$"The lightning node is not synched ({blocksGap} blocks left)");
var blocksGap = summary.Status.ChainHeight - info.BlockHeight;
if (blocksGap > 10 && !(isLndHub && info.BlockHeight == 0))
{
throw new PaymentMethodUnavailableException(
$"The lightning node is not synched ({blocksGap} blocks left)");
}
}
return nodeInfo;
}

View file

@ -508,8 +508,15 @@ namespace BTCPayServer.Payments.Lightning
try
{
var lightningClient = _lightningClientFactory.Create(ConnectionString, _network);
if(lightningClient is null)
return;
uri = lightningClient.GetServerUri();
logUrl = string.IsNullOrEmpty(uri.UserInfo) ? uri.ToString() : uri.ToString().Replace(uri.UserInfo, "***");
logUrl = uri switch
{
null when LightningConnectionStringHelper.ExtractValues(ConnectionString, out var type) is not null => type,
null => string.Empty,
_ => string.IsNullOrEmpty(uri.UserInfo) ? uri.ToString() : uri.ToString().Replace(uri.UserInfo, "***")
};
Logs.PayServer.LogInformation("{CryptoCode} (Lightning): Start listening {Uri}", _network.CryptoCode, logUrl);
using var session = await lightningClient.Listen(cancellation);
// Just in case the payment arrived after our last poll but before we listened.