Skip to content

Commit

Permalink
Merge pull request #262 from Elenpay/inactive-channels
Browse files Browse the repository at this point in the history
Revive inactive channels
  • Loading branch information
RodriFS authored Aug 1, 2023
2 parents 0df90a8 + 89e8a18 commit c09324a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Data/Repositories/NodeRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ public async Task<Node> GetOrCreateByPubKey(string pubKey, ILightningService lig
var foundNode = await lightningService.GetNodeInfo(pubKey);
if (foundNode == null)
{
throw new Exception("Node info not found");
_logger.LogWarning("Peer with PubKey {pubKey} not found", pubKey);
}

node = new Node()
{
Name = foundNode.Alias,
PubKey = foundNode.PubKey,
Name = foundNode?.Alias ?? "",
PubKey = pubKey
};
var addNode = await AddAsync(node);
if (!addNode.Item1)
Expand Down
3 changes: 1 addition & 2 deletions src/Jobs/ChannelMonitorJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public async Task Execute(IJobExecutionContext context)

foreach (var channel in result?.Channels)
{
if (!channel.Active) continue;
var node2 = await _nodeRepository.GetOrCreateByPubKey(channel.RemotePubkey, _lightningService);

// Recover Operations on channels
Expand All @@ -94,7 +93,7 @@ public async Task Execute(IJobExecutionContext context)
_logger.LogInformation("{JobName} ended", nameof(ChannelMonitorJob));
}

public async Task RecoverGhostChannels(Node source, Node destination, Channel? channel)
public async Task RecoverGhostChannels(Node source, Node destination, Channel channel)
{
if (!channel.Initiator && destination.IsManaged) return;
try
Expand Down
5 changes: 3 additions & 2 deletions test/NodeGuard.Tests/Data/Repositories/NodeRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ public async Task AddsNewNode_WhenRemoteNodeNotFound()
var lightningServiceMock = new Mock<ILightningService>();
var repositoryMock = new Mock<IRepository<Node>>();

var node = new LightningNode() { Alias = "TestAlias", PubKey = "TestPubKey" };
lightningServiceMock.Setup(service => service.GetNodeInfo(It.IsAny<string>()))
.ReturnsAsync(new LightningNode() { Alias = "TestAlias", PubKey = "TestPubKey" });
.ReturnsAsync(node);

repositoryMock.Setup(repository => repository.AddAsync(It.IsAny<Node>(), It.IsAny<ApplicationDbContext>()))
.ReturnsAsync((true, null));

var nodeRepository = new NodeRepository(repositoryMock.Object, null, dbContextFactory.Object, null);

// Act
var result = await nodeRepository.GetOrCreateByPubKey("abc", lightningServiceMock.Object);
var result = await nodeRepository.GetOrCreateByPubKey(node.PubKey, lightningServiceMock.Object);

// Assert
result.Name.Should().Be("TestAlias");
Expand Down

0 comments on commit c09324a

Please sign in to comment.