Lightning: Better handling for non-public nodes (#4263)

Fixes #4246. 

`LightningLikePaymentHandler.GetNodeInfo` needed the `throws` argument to handle the cases as previously, otherwise the catch case in `ShowLightningNodeInfo` never occured.

State with this PR: A node can be available, but not have any public addresses. The latter will now be reported when testing the connection and on the public node info page.
This commit is contained in:
d11n
2022-11-05 12:21:24 +01:00
committed by GitHub
parent 167c5297fa
commit 562f88555c
4 changed files with 39 additions and 35 deletions

View File

@@ -194,12 +194,15 @@ namespace BTCPayServer.Controllers
try
{
var info = await handler.GetNodeInfo(paymentMethod, network, new InvoiceLogs(), Request.IsOnion(), true);
if (!vm.SkipPortTest)
var hasPublicAddress = info.Any();
if (!vm.SkipPortTest && hasPublicAddress)
{
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(20));
await handler.TestConnection(info.First(), cts.Token);
}
TempData[WellKnownTempData.SuccessMessage] = $"Connection to the Lightning node successful. Your node address: {info.First()}";
TempData[WellKnownTempData.SuccessMessage] = "Connection to the Lightning node successful" + (hasPublicAddress
? $". Your node address: {info.First()}"
: ", but no public address has been configured");
}
catch (Exception ex)
{
@@ -225,7 +228,7 @@ namespace BTCPayServer.Controllers
var lightning = GetExistingLightningSupportedPaymentMethod(cryptoCode, store);
if (lightning == null)
{
TempData[WellKnownTempData.ErrorMessage] = $"You need to connect to a Lightning node before adjusting its settings.";
TempData[WellKnownTempData.ErrorMessage] = "You need to connect to a Lightning node before adjusting its settings.";
return RedirectToAction(nameof(SetupLightningNode), new { storeId, cryptoCode });
}