mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 06:54:19 +01:00
Fix slow invoice creation
This commit is contained in:
@@ -120,7 +120,6 @@ namespace BTCPayServer.Tests
|
|||||||
.Build();
|
.Build();
|
||||||
_Host.Start();
|
_Host.Start();
|
||||||
InvoiceRepository = (InvoiceRepository)_Host.Services.GetService(typeof(InvoiceRepository));
|
InvoiceRepository = (InvoiceRepository)_Host.Services.GetService(typeof(InvoiceRepository));
|
||||||
((LightningLikePaymentHandler)_Host.Services.GetService(typeof(IPaymentMethodHandler<LightningSupportedPaymentMethod>))).SkipP2PTest = !InContainer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string HostName
|
public string HostName
|
||||||
|
|||||||
@@ -132,7 +132,8 @@ namespace BTCPayServer.Tests
|
|||||||
{
|
{
|
||||||
Url = connectionType == LightningConnectionType.Charge ? parent.MerchantCharge.Client.Uri.AbsoluteUri :
|
Url = connectionType == LightningConnectionType.Charge ? parent.MerchantCharge.Client.Uri.AbsoluteUri :
|
||||||
connectionType == LightningConnectionType.CLightning ? parent.MerchantLightningD.Address.AbsoluteUri
|
connectionType == LightningConnectionType.CLightning ? parent.MerchantLightningD.Address.AbsoluteUri
|
||||||
: throw new NotSupportedException(connectionType.ToString())
|
: throw new NotSupportedException(connectionType.ToString()),
|
||||||
|
SkipPortTest = true
|
||||||
}, "save", "BTC");
|
}, "save", "BTC");
|
||||||
if (storeController.ModelState.ErrorCount != 0)
|
if (storeController.ModelState.ErrorCount != 0)
|
||||||
Assert.False(true, storeController.ModelState.FirstOrDefault().Value.Errors[0].ErrorMessage);
|
Assert.False(true, storeController.ModelState.FirstOrDefault().Value.Errors[0].ErrorMessage);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||||
<Version>1.0.1.77</Version>
|
<Version>1.0.1.78</Version>
|
||||||
<NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn>
|
<NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using BTCPayServer.Payments.Lightning;
|
using BTCPayServer.Payments.Lightning;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using BTCPayServer.Data;
|
using BTCPayServer.Data;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace BTCPayServer.Controllers
|
namespace BTCPayServer.Controllers
|
||||||
{
|
{
|
||||||
@@ -127,6 +128,13 @@ namespace BTCPayServer.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var info = await handler.Test(paymentMethod, network);
|
var info = await handler.Test(paymentMethod, network);
|
||||||
|
if (!vm.SkipPortTest)
|
||||||
|
{
|
||||||
|
using (CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(20)))
|
||||||
|
{
|
||||||
|
await handler.TestConnection(info, cts.Token);
|
||||||
|
}
|
||||||
|
}
|
||||||
vm.StatusMessage = $"Connection to the lightning node succeed ({info})";
|
vm.StatusMessage = $"Connection to the lightning node succeed ({info})";
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -23,5 +23,6 @@ namespace BTCPayServer.Models.StoreViewModels
|
|||||||
}
|
}
|
||||||
public string StatusMessage { get; set; }
|
public string StatusMessage { get; set; }
|
||||||
public string InternalLightningNode { get; internal set; }
|
public string InternalLightningNode { get; internal set; }
|
||||||
|
public bool SkipPortTest { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,11 +57,6 @@ namespace BTCPayServer.Payments.Lightning
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Used for testing
|
|
||||||
/// </summary>
|
|
||||||
public bool SkipP2PTest { get; set; }
|
|
||||||
|
|
||||||
public async Task<NodeInfo> Test(LightningSupportedPaymentMethod supportedPaymentMethod, BTCPayNetwork network)
|
public async Task<NodeInfo> Test(LightningSupportedPaymentMethod supportedPaymentMethod, BTCPayNetwork network)
|
||||||
{
|
{
|
||||||
if (!_Dashboard.IsFullySynched(network.CryptoCode, out var summary))
|
if (!_Dashboard.IsFullySynched(network.CryptoCode, out var summary))
|
||||||
@@ -94,38 +89,34 @@ namespace BTCPayServer.Payments.Lightning
|
|||||||
throw new PaymentMethodUnavailableException($"The lightning is not synched ({blocksGap} blocks)");
|
throw new PaymentMethodUnavailableException($"The lightning is not synched ({blocksGap} blocks)");
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!SkipP2PTest)
|
|
||||||
{
|
|
||||||
await TestConnection(info.Address, info.P2PPort, cts.Token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new PaymentMethodUnavailableException($"Error while connecting to the lightning node via {info.Address}:{info.P2PPort} ({ex.Message})");
|
|
||||||
}
|
|
||||||
return new NodeInfo(info.NodeId, info.Address, info.P2PPort);
|
return new NodeInfo(info.NodeId, info.Address, info.P2PPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TestConnection(string addressStr, int port, CancellationToken cancellation)
|
public async Task TestConnection(NodeInfo nodeInfo, CancellationToken cancellation)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
IPAddress address = null;
|
IPAddress address = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
address = IPAddress.Parse(addressStr);
|
address = IPAddress.Parse(nodeInfo.Host);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
address = (await Dns.GetHostAddressesAsync(addressStr)).FirstOrDefault();
|
address = (await Dns.GetHostAddressesAsync(nodeInfo.Host)).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (address == null)
|
if (address == null)
|
||||||
throw new PaymentMethodUnavailableException($"DNS did not resolved {addressStr}");
|
throw new PaymentMethodUnavailableException($"DNS did not resolved {nodeInfo.Host}");
|
||||||
|
|
||||||
using (var tcp = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
|
using (var tcp = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
|
||||||
{
|
{
|
||||||
await WithTimeout(tcp.ConnectAsync(new IPEndPoint(address, port)), cancellation);
|
await WithTimeout(tcp.ConnectAsync(new IPEndPoint(address, nodeInfo.Port)), cancellation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new PaymentMethodUnavailableException($"Error while connecting to the lightning node via {nodeInfo.Host}:{nodeInfo.Port} ({ex.Message})");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user