Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jit #56

Closed
wants to merge 3 commits into from
Closed

Jit #56

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions BTCPayApp.Core/Attempt2/LDKNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BTCPayApp.Core.Data;
using BTCPayApp.Core.Helpers;
using BTCPayApp.Core.LDK;
using BTCPayApp.Core.LSP.JIT;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -98,6 +99,18 @@ public async Task<Result_ChannelIdAPIErrorZ> OpenChannel(Money amount, PubKey no
}

}

public async Task<IJITService?> GetJITLSPService()
{
var config = await GetConfig();
var lsp = config.JITLSP;
if(lsp is null)
{
return null;
}
var jits = ServiceProvider.GetServices<IJITService>();
return jits.FirstOrDefault(jit => jit.ProviderName == lsp);
}
}

public partial class LDKNode : IAsyncDisposable, IHostedService, IDisposable
Expand Down Expand Up @@ -181,12 +194,17 @@ public async Task<LightningConfig> GetConfig()
await _configLoaded.Task;
return _config!;
}

private async Task UpdateConfig(LightningConfig config)
public async Task<string[]> GetJITLSPs()
{
return ServiceProvider.GetServices<IJITService>().Select(jit => jit.ProviderName).ToArray();
}

public async Task UpdateConfig(LightningConfig config)
{
await _started.Task;
await _configProvider.Set(LightningConfig.Key, config);
_config = config;

ConfigUpdated?.Invoke(this, config);
}

Expand Down Expand Up @@ -366,9 +384,9 @@ await context.LightningChannels.AddAsync(new Channel()
}


public async Task Peer(string toString, PeerInfo? value)
public async Task Peer(PubKey key, PeerInfo? value)
{
toString = toString.ToLowerInvariant();
var toString = key.ToString().ToLowerInvariant();
var config = await GetConfig();
if (value is null)
{
Expand Down
12 changes: 6 additions & 6 deletions BTCPayApp.Core/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}
}

public class SpendableCoin
{
public string Script { get; set; }
[Key] public string Outpoint { get; set; }
public byte[] Data { get; set; }
}
// public class SpendableCoin
// {
// public string Script { get; set; }
// [Key] public string Outpoint { get; set; }
// public byte[] Data { get; set; }
// }
7 changes: 7 additions & 0 deletions BTCPayApp.Core/LDK/LDKExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BTCPayApp.Core.Attempt2;
using BTCPayApp.Core.Contracts;
using BTCPayApp.Core.Helpers;
using BTCPayApp.Core.LSP.JIT;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using NBitcoin;
Expand Down Expand Up @@ -213,6 +214,7 @@ public static IServiceCollection AddLDK(this IServiceCollection services)
// services.AddScoped<IScopedHostedService>(provider =>
// provider.GetRequiredService<LDKSpendableOutputEventHandler>());
services.AddScoped<IScopedHostedService>(provider => provider.GetRequiredService<LDKChannelSync>());
services.AddScoped<IScopedHostedService>(provider => provider.GetRequiredService<PaymentsManager>());
services.AddScoped<IScopedHostedService>(provider => provider.GetRequiredService<LDKBackgroundProcessor>());
services.AddScoped<IScopedHostedService>(provider => provider.GetRequiredService<LDKPeerHandler>());
services.AddScoped<IScopedHostedService>(provider => provider.GetRequiredService<LDKAnnouncementBroadcaster>());
Expand Down Expand Up @@ -300,6 +302,11 @@ public static IServiceCollection AddLDK(this IServiceCollection services)
ProbabilisticScoringFeeParameters.with_default()));
services.AddScoped<Router>(provider => provider.GetRequiredService<DefaultRouter>().as_Router());


services.AddScoped<VoltageFlow2Jit>();
services.AddScoped<IScopedHostedService>(provider => provider.GetRequiredService<VoltageFlow2Jit>());
services.AddScoped<IJITService, VoltageFlow2Jit>(provider => provider.GetRequiredService<VoltageFlow2Jit>());

return services;
}

Expand Down
5 changes: 5 additions & 0 deletions BTCPayApp.Core/LDK/LDKOpenChannelRequestEventHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BTCPayApp.Core.Attempt2;
using BTCPayApp.Core.Helpers;
using org.ldk.structs;
using UInt128 = org.ldk.util.UInt128;

Expand Down Expand Up @@ -33,6 +34,7 @@ public async Task Handle(Event.Event_OpenChannelRequest eventOpenChannelRequest)
eventOpenChannelRequest.counterparty_node_id,
userChannelId
);
AcceptedChannel?.Invoke(this, eventOpenChannelRequest);
return;
}
}
Expand All @@ -43,8 +45,11 @@ public async Task Handle(Event.Event_OpenChannelRequest eventOpenChannelRequest)
eventOpenChannelRequest.counterparty_node_id,
userChannelId);

AcceptedChannel?.Invoke(this, eventOpenChannelRequest);
//TODO: if we want to reject the channel, we can call reject_channel
//_channelManager.force_close_without_broadcasting_txn(eventOpenChannelRequest.temporary_channel_id, eventOpenChannelRequest.counterparty_node_id);

}

public AsyncEventHandler<Event.Event_OpenChannelRequest>? AcceptedChannel;
}
4 changes: 2 additions & 2 deletions BTCPayApp.Core/LDK/LDKPeerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private async Task BtcPayAppServerClientOnOnServerNodeInfo(object? sender, strin
if (config.Peers.ContainsKey(nodeInfo.NodeId.ToString()))
return;
var endpoint = new IPEndPoint(IPAddress.Parse(nodeInfo.Host), nodeInfo.Port);
await _node.Peer(nodeInfo.NodeId.ToString(), new PeerInfo()
await _node.Peer(nodeInfo.NodeId, new PeerInfo()
{
Endpoint = endpoint.ToString(),
Persistent = true,
Expand Down Expand Up @@ -224,7 +224,7 @@ await listener.AcceptTcpClientAsync(cancellationToken),
if (peer.Endpoint != remote.ToString())
{
peer.Endpoint = remote.ToString()!;
await _node.Peer(theirNodeId.ToString(), peer);
await _node.Peer(theirNodeId, peer);
}
}

Expand Down
Loading
Loading