Skip to content

Commit

Permalink
Fixed duplication error (#288)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
markettes authored Sep 5, 2023
1 parent a3b4615 commit 5aa2658
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/Jobs/ChannelMonitorJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions test/NodeGuard.Tests/Jobs/ChannelMonitorJobTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -86,7 +87,8 @@ public async Task RecoverGhostChannels_ChannelAlreadyExists()

var channel = new Lnrpc.Channel()
{
ChanId = 1,
ChanId = 2,
ChannelPoint = "abc:0",
Initiator = true
};
// Act
Expand Down

0 comments on commit 5aa2658

Please sign in to comment.