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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 35 deletions

View file

@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.Controllers
{
[Route("embed/{storeId}/{cryptoCode}/ln")]
[AllowAnonymous]
public class UIPublicLightningNodeInfoController : Controller
@ -43,11 +42,11 @@ namespace BTCPayServer.Controllers
var paymentMethodDetails = GetExistingLightningSupportedPaymentMethod(cryptoCode, store);
var network = _BtcPayNetworkProvider.GetNetwork<BTCPayNetwork>(cryptoCode);
var nodeInfo =
await _LightningLikePaymentHandler.GetNodeInfo(paymentMethodDetails, network, new InvoiceLogs());
await _LightningLikePaymentHandler.GetNodeInfo(paymentMethodDetails, network, new InvoiceLogs(), throws: true);
return View(new ShowLightningNodeInfoViewModel
{
Available = nodeInfo.Any(),
Available = true,
NodeInfo = nodeInfo.Select(n => new ShowLightningNodeInfoViewModel.NodeData(n)).ToArray(),
CryptoCode = cryptoCode,
CryptoImage = GetImage(paymentMethodDetails.PaymentId, network),

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 });
}

View file

@ -147,16 +147,11 @@ namespace BTCPayServer.Payments.Lightning
(!string.IsNullOrEmpty(ex.InnerException?.Message) ? $" ({ex.InnerException.Message})" : ""));
}
// Node info might be empty if there are no public URIs to announce. The UI also supports this.
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();
// Maybe the user does not have an easily accessible ln node. Node info should be optional. The UI also supports this.
// if (!nodeInfo.Any())
// {
// throw new PaymentMethodUnavailableException("No lightning node public address has been configured");
// }
var blocksGap = summary.Status.ChainHeight - info.BlockHeight;
if (blocksGap > 10)
{

View file

@ -27,6 +27,8 @@
</span>
</h4>
@if (Model.Available)
{
@if (Model.NodeInfo.Any())
{
@if (Model.NodeInfo.Length > 1)
{
@ -57,6 +59,11 @@
}
</div>
}
else
{
<p class="text-center mt-4">No public address available.</p>
}
}
</div>
</div>
</div>