From 5aa26589f306d1c1ad6d03b1a9f7c8d748e10790 Mon Sep 17 00:00:00 2001 From: Marcos <33052423+markettes@users.noreply.github.com> Date: Tue, 5 Sep 2023 10:36:14 +0200 Subject: [PATCH] Fixed duplication error (#288) * fix(ChannelMonitorJob.cs): fix channelExists check to correctly compare fundingTx and outputIndex values fix(ChannelMonitorJob.cs): fix parsing of outputIndex to correctly convert it to UInt32 * fix: fix tests --- src/Jobs/ChannelMonitorJob.cs | 12 ++++++------ test/NodeGuard.Tests/Jobs/ChannelMonitorJobTests.cs | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Jobs/ChannelMonitorJob.cs b/src/Jobs/ChannelMonitorJob.cs index 96e7c550..e7bd4a6b 100644 --- a/src/Jobs/ChannelMonitorJob.cs +++ b/src/Jobs/ChannelMonitorJob.cs @@ -139,18 +139,18 @@ public async Task RecoverGhostChannels(Node source, Node destination, Channel ch try { await using var dbContext = await _dbContextFactory.CreateDbContextAsync(); - - var channelExists = await dbContext.Channels.AnyAsync(c => c.ChanId == channel.ChanId); - if (channelExists) return; - + var channelPoint = channel.ChannelPoint.Split(":"); var fundingTx = channelPoint[0]; - var outputIndex = channelPoint[1]; + var outputIndex = Convert.ToUInt32(channelPoint[1]); + + var channelExists = await dbContext.Channels.AnyAsync(c => c.FundingTx.Equals(fundingTx) && c.FundingTxOutputIndex == outputIndex); + if (channelExists) return; var parsedChannelPoint = new ChannelPoint { FundingTxidStr = fundingTx, FundingTxidBytes = ByteString.CopyFrom(Convert.FromHexString(fundingTx).Reverse().ToArray()), - OutputIndex = Convert.ToUInt32(outputIndex) + OutputIndex = outputIndex }; var createdChannel = await _lightningService.CreateChannel(source, destination.Id, parsedChannelPoint, channel.Capacity, channel.CloseAddress); diff --git a/test/NodeGuard.Tests/Jobs/ChannelMonitorJobTests.cs b/test/NodeGuard.Tests/Jobs/ChannelMonitorJobTests.cs index a5ec10da..2cac3cfe 100644 --- a/test/NodeGuard.Tests/Jobs/ChannelMonitorJobTests.cs +++ b/test/NodeGuard.Tests/Jobs/ChannelMonitorJobTests.cs @@ -77,7 +77,8 @@ public async Task RecoverGhostChannels_ChannelAlreadyExists() var request1 = new Channel() { ChanId = 1, - FundingTx = "abc:0" + FundingTx = "abc", + FundingTxOutputIndex = 0 }; await context.Channels.AddAsync(request1); await context.SaveChangesAsync(); @@ -86,7 +87,8 @@ public async Task RecoverGhostChannels_ChannelAlreadyExists() var channel = new Lnrpc.Channel() { - ChanId = 1, + ChanId = 2, + ChannelPoint = "abc:0", Initiator = true }; // Act