Refactor Flow 2 JIT into an abstract class, clean up references

This commit is contained in:
Dennis Reimann 2025-04-29 12:41:19 +02:00
parent ccd80fad4c
commit 3de73adb19
No known key found for this signature in database
GPG Key ID: 5009E1797F03F8D0
4 changed files with 25 additions and 27 deletions

View File

@ -307,7 +307,7 @@ public static class LDKExtensions
provider.GetRequiredService<LockableScore>(),
ProbabilisticScoringFeeParameters.with_default()));
services.AddScoped<Router>(provider => provider.GetRequiredService<DefaultRouter>().as_Router());
services.AddScoped<VoltageFlow2Jit>();
//services.AddScoped<VoltageFlow2Jit>();
services.AddScoped<OlympusFlow2Jit>();
//services.AddScoped<IScopedHostedService>(provider => provider.GetRequiredService<VoltageFlow2Jit>());
services.AddScoped<IScopedHostedService>(provider => provider.GetRequiredService<OlympusFlow2Jit>());

View File

@ -358,7 +358,7 @@ public class PaymentsManager :
_channelManager.claim_funds(preimage);
return;
}
if (accept.AdditionalData.TryGetValue(VoltageFlow2Jit.LightningPaymentLSPKey, out var lspDoc) &&
if (accept.AdditionalData.TryGetValue(Flow2Jit.LightningPaymentLSPKey, out var lspDoc) &&
lspDoc.Deserialize<string>() is { } lsp &&
await _ldkNode.GetJITLSPService() is { } lspService && lspService.ProviderName == lsp &&
await lspService.IsAcceptable(accept!, eventPaymentClaimable))

View File

@ -14,9 +14,10 @@ using JsonSerializer = System.Text.Json.JsonSerializer;
namespace BTCPayApp.Core.LSP.JIT;
/// <summary>
/// https://docs.voltage.cloud/flow/flow-2.0
/// https://www.voltage.cloud/blog/introducing-flow-v2
/// https://www.voltage.cloud/blog/deprecating-flow-2-0---paving-the-way-for-a-superior-solution
/// </summary>
public class VoltageFlow2Jit : IJITService, IScopedHostedService, ILDKEventHandler<Event.Event_ChannelPending>
public abstract class Flow2Jit : IJITService, IScopedHostedService, ILDKEventHandler<Event.Event_ChannelPending>
{
private const string LightningPaymentOriginalPaymentRequest = "OriginalPaymentRequest";
private const string LightningPaymentJITFeeKey = "JITFeeKey";
@ -26,37 +27,20 @@ public class VoltageFlow2Jit : IJITService, IScopedHostedService, ILDKEventHandl
private readonly Network _network;
private readonly LDKNode _node;
private readonly ChannelManager _channelManager;
private readonly ILogger<VoltageFlow2Jit> _logger;
private readonly ILogger<Flow2Jit> _logger;
private readonly LDKOpenChannelRequestEventHandler _openChannelRequestEventHandler;
private CancellationTokenSource _cts = new();
private readonly ConcurrentDictionary<long, Event.Event_OpenChannelRequest> _acceptedChannels = new();
public bool Active { get; }
public virtual string ProviderName => "Voltage";
public virtual string ProviderName => "Abstract Flow 2.0 Provider";
protected virtual LightMoney NonChannelOpenFee => LightMoney.Zero;
private FlowInfoResponse? _info;
public VoltageFlow2Jit(bool active)
{
Active = active;
}
private readonly SemaphoreSlim _semaphore = new(1, 1);
protected virtual Uri? BaseAddress(Network network)
{
return network switch
{
not null when network == Network.Main => new Uri("https://lsp.voltageapi.com"),
not null when network == Network.TestNet => new Uri("https://testnet-lsp.voltageapi.com"),
// not null when network == Network.RegTest => new Uri("https://localhost:5001/jit-lsp"),
_ => null
};
}
public VoltageFlow2Jit(IHttpClientFactory httpClientFactory, Network network, LDKNode node,
ChannelManager channelManager, ILogger<VoltageFlow2Jit> logger,
protected Flow2Jit(IHttpClientFactory httpClientFactory, Network network, LDKNode node,
ChannelManager channelManager, ILogger<Flow2Jit> logger,
LDKOpenChannelRequestEventHandler openChannelRequestEventHandler)
{
var httpClientInstance = httpClientFactory.CreateClient("VoltageFlow2JIT");
@ -71,6 +55,17 @@ public class VoltageFlow2Jit : IJITService, IScopedHostedService, ILDKEventHandl
_openChannelRequestEventHandler = openChannelRequestEventHandler;
}
protected virtual Uri? BaseAddress(Network network)
{
return network switch
{
not null when network == Network.Main => new Uri("https://lsp.voltageapi.com"),
not null when network == Network.TestNet => new Uri("https://testnet-lsp.voltageapi.com"),
// not null when network == Network.RegTest => new Uri("https://localhost:5001/jit-lsp"),
_ => null
};
}
private async Task<FlowInfoResponse> GetInfo(CancellationToken cancellationToken = default)
{
const string path = "/api/v1/info";

View File

@ -6,14 +6,17 @@ using org.ldk.structs;
namespace BTCPayApp.Core.LSP.JIT;
/// <summary>
/// https://docs.zeusln.app/lsp/services/flow
/// </summary>
public class OlympusFlow2Jit(
IHttpClientFactory httpClientFactory,
Network network,
LDKNode node,
ChannelManager channelManager,
ILogger<VoltageFlow2Jit> logger,
ILogger<OlympusFlow2Jit> logger,
LDKOpenChannelRequestEventHandler openChannelRequestEventHandler)
: VoltageFlow2Jit(httpClientFactory, network, node, channelManager, logger, openChannelRequestEventHandler)
: Flow2Jit(httpClientFactory, network, node, channelManager, logger, openChannelRequestEventHandler)
{
protected override Uri? BaseAddress(Network network)
{