diff --git a/src/Data/Repositories/Interfaces/INodeRepository.cs b/src/Data/Repositories/Interfaces/INodeRepository.cs index 15c24c23..e75cac99 100644 --- a/src/Data/Repositories/Interfaces/INodeRepository.cs +++ b/src/Data/Repositories/Interfaces/INodeRepository.cs @@ -34,7 +34,7 @@ public interface INodeRepository Task> GetAllManagedByUser(string userId); - Task> GetAllManagedByNodeGuard(); + Task> GetAllManagedByNodeGuard(bool withDisabled = true); Task<(bool, string?)> AddAsync(Node type); @@ -45,4 +45,4 @@ public interface INodeRepository (bool, string?) RemoveRange(List types); (bool, string?) Update(Node type); -} \ No newline at end of file +} diff --git a/src/Data/Repositories/NodeRepository.cs b/src/Data/Repositories/NodeRepository.cs index 66b24c45..671332ad 100644 --- a/src/Data/Repositories/NodeRepository.cs +++ b/src/Data/Repositories/NodeRepository.cs @@ -110,7 +110,7 @@ public async Task> GetAll() .ToListAsync(); } - public async Task> GetAllManagedByNodeGuard() + public async Task> GetAllManagedByNodeGuard(bool withDisabled = true) { await using var applicationDbContext = await _dbContextFactory.CreateDbContextAsync(); @@ -119,6 +119,11 @@ public async Task> GetAllManagedByNodeGuard() .ThenInclude(x => x.Keys) .Include(x => x.ReturningFundsWallet) .Where(node => node.Endpoint != null); + if (!withDisabled) + { + query = query.Where(node => !node.IsNodeDisabled); + + } var resultAsync = await query.ToListAsync(); @@ -182,4 +187,4 @@ public async Task> GetAllManagedByUser(string userId) return _repository.Update(type, applicationDbContext); } } -} \ No newline at end of file +} diff --git a/src/Jobs/ChannelAcceptorJob.cs b/src/Jobs/ChannelAcceptorJob.cs index 182cf3e5..5a2c9031 100644 --- a/src/Jobs/ChannelAcceptorJob.cs +++ b/src/Jobs/ChannelAcceptorJob.cs @@ -48,7 +48,7 @@ public async Task Execute(IJobExecutionContext context) _logger.LogInformation("Starting {JobName}... ", nameof(ChannelAcceptorJob)); try { - var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard(); + var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard(false); var scheduler = await _schedulerFactory.GetScheduler(); foreach (var managedNode in managedNodes) @@ -70,4 +70,4 @@ public async Task Execute(IJobExecutionContext context) _logger.LogInformation("{JobName} ended", nameof(ChannelAcceptorJob)); } -} \ No newline at end of file +} diff --git a/src/Jobs/MonitorChannelsJob.cs b/src/Jobs/MonitorChannelsJob.cs index 86906610..72dd7e16 100644 --- a/src/Jobs/MonitorChannelsJob.cs +++ b/src/Jobs/MonitorChannelsJob.cs @@ -22,7 +22,7 @@ public async Task Execute(IJobExecutionContext context) _logger.LogInformation("Starting {JobName}... ", nameof(MonitorChannelsJob)); try { - var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard(); + var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard(false); var scheduler = await _schedulerFactory.GetScheduler(); @@ -51,4 +51,4 @@ public async Task Execute(IJobExecutionContext context) _logger.LogInformation("{JobName} ended", nameof(MonitorChannelsJob)); } -} \ No newline at end of file +} diff --git a/src/Jobs/NodeChannelSubscribeJob.cs b/src/Jobs/NodeChannelSubscribeJob.cs index 2ff8c687..146a7981 100644 --- a/src/Jobs/NodeChannelSubscribeJob.cs +++ b/src/Jobs/NodeChannelSubscribeJob.cs @@ -97,7 +97,7 @@ public async Task Execute(IJobExecutionContext context) { _logger.LogError(e, "Error while subscribing for the channel updates of node {NodeId}", nodeId); //Sleep to avoid massive requests - await Task.Delay(1000); + await Task.Delay(5000); throw new JobExecutionException(e, true); } @@ -176,4 +176,4 @@ public async Task NodeUpdateManagement(ChannelEventUpdate channelEventUpdate, No break; } } -} \ No newline at end of file +} diff --git a/src/Jobs/NodeSubscriptorJob.cs b/src/Jobs/NodeSubscriptorJob.cs index 0e96c9e0..4a030f1b 100644 --- a/src/Jobs/NodeSubscriptorJob.cs +++ b/src/Jobs/NodeSubscriptorJob.cs @@ -23,7 +23,7 @@ public async Task Execute(IJobExecutionContext context) _logger.LogInformation("Starting {JobName}... ", nameof(NodeSubscriptorJob)); try { - var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard(); + var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard(false); var scheduler = await _schedulerFactory.GetScheduler(); @@ -48,4 +48,4 @@ public async Task Execute(IJobExecutionContext context) _logger.LogInformation("{JobName} ended", nameof(NodeSubscriptorJob)); } -} \ No newline at end of file +} diff --git a/src/Jobs/ProcessNodeChannelAcceptorJob.cs b/src/Jobs/ProcessNodeChannelAcceptorJob.cs index 4c7600cd..25f32e7e 100644 --- a/src/Jobs/ProcessNodeChannelAcceptorJob.cs +++ b/src/Jobs/ProcessNodeChannelAcceptorJob.cs @@ -240,10 +240,10 @@ await AcceptChannelOpeningRequestWithUpfrontShutdown(_nBXplorerService, _logger.LogError(e, "Error on {JobName}", nameof(ProcessNodeChannelAcceptorJob)); //Sleep to avoid massive requests - await Task.Delay(1000); + await Task.Delay(5000); throw new JobExecutionException(e, true); } } -} \ No newline at end of file +} diff --git a/src/Jobs/SweepAllNodesWalletsJob.cs b/src/Jobs/SweepAllNodesWalletsJob.cs index 13a19fd8..a69f0dcc 100644 --- a/src/Jobs/SweepAllNodesWalletsJob.cs +++ b/src/Jobs/SweepAllNodesWalletsJob.cs @@ -46,7 +46,7 @@ public async Task Execute(IJobExecutionContext context) _logger.LogInformation("Starting {JobName}... ", nameof(SweepAllNodesWalletsJob)); try { - var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard(); + var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard(false); var scheduler = await _schedulerFactory.GetScheduler(); foreach (var managedNode in managedNodes.Where(managedNode => managedNode.ChannelAdminMacaroon != null && managedNode.AutosweepEnabled)) @@ -72,4 +72,4 @@ public async Task Execute(IJobExecutionContext context) _logger.LogInformation("{JobName} ended", nameof(SweepAllNodesWalletsJob)); } } -} \ No newline at end of file +} diff --git a/src/Pages/Wallets.razor b/src/Pages/Wallets.razor index 149e3a84..ee0aba80 100644 --- a/src/Pages/Wallets.razor +++ b/src/Pages/Wallets.razor @@ -1411,7 +1411,7 @@ var withdrawalRequest = new WalletWithdrawalRequest { UserRequestorId = LoggedUser != null ? LoggedUser.Id : string.Empty, - Description = @$"Funds transferred from {_sourceWalletName} to {_targetWalletName}", + Description = $"Funds transferred from {_sourceWalletName} to {_targetWalletName}", WithdrawAllFunds = _transferAllFunds, DestinationAddress = targetBitcoinAddress.ToString(), MempoolRecommendedFeesType = MempoolRecommendedFeesType.HourFee, diff --git a/test/NodeGuard.Tests/Rpc/NodeGuardServiceTests.cs b/test/NodeGuard.Tests/Rpc/NodeGuardServiceTests.cs index 29677fc5..68e5f624 100644 --- a/test/NodeGuard.Tests/Rpc/NodeGuardServiceTests.cs +++ b/test/NodeGuard.Tests/Rpc/NodeGuardServiceTests.cs @@ -1107,7 +1107,7 @@ public async Task GetNodes_RequestIncludeUnmanaged_ReturnsUnmanagedNodes() }; nodeRepositoryMock.Setup(repo => repo.GetAll()).ReturnsAsync(sampleNodes); - nodeRepositoryMock.Setup(repo => repo.GetAllManagedByNodeGuard()).ReturnsAsync(new List()); + nodeRepositoryMock.Setup(repo => repo.GetAllManagedByNodeGuard(It.IsAny())).ReturnsAsync(new List()); var service = new NodeGuardService( _logger.Object, new Mock().Object, @@ -1135,7 +1135,7 @@ public async Task GetNodes_RequestIncludeUnmanaged_ReturnsUnmanagedNodes() // Assert response.Nodes.Count.Should().Be(sampleNodes.Count); nodeRepositoryMock.Verify(repo => repo.GetAll(), Times.Once); - nodeRepositoryMock.Verify(repo => repo.GetAllManagedByNodeGuard(), Times.Never); + nodeRepositoryMock.Verify(repo => repo.GetAllManagedByNodeGuard(It.IsAny()), Times.Never); } [Fact] @@ -1150,7 +1150,7 @@ public async Task GetNodes_RequestNotIncludeUnmanaged_ReturnsManagedNodes() }; nodeRepositoryMock.Setup(repo => repo.GetAll()).ReturnsAsync(new List()); - nodeRepositoryMock.Setup(repo => repo.GetAllManagedByNodeGuard()).ReturnsAsync(sampleNodes); + nodeRepositoryMock.Setup(repo => repo.GetAllManagedByNodeGuard(It.IsAny())).ReturnsAsync(sampleNodes); var service = new NodeGuardService( _logger.Object, new Mock().Object, @@ -1178,7 +1178,7 @@ public async Task GetNodes_RequestNotIncludeUnmanaged_ReturnsManagedNodes() // Assert response.Nodes.Count.Should().Be(sampleNodes.Count); nodeRepositoryMock.Verify(repo => repo.GetAll(), Times.Never); - nodeRepositoryMock.Verify(repo => repo.GetAllManagedByNodeGuard(), Times.Once); + nodeRepositoryMock.Verify(repo => repo.GetAllManagedByNodeGuard(It.IsAny()), Times.Once); } @@ -1307,4 +1307,4 @@ await act "Status(StatusCode=\"Internal\", Detail=\"You can't select wallets by type and id at the same time\")"); } } -} \ No newline at end of file +} diff --git a/test/NodeGuard.Tests/Services/BitcoinServiceTests.cs b/test/NodeGuard.Tests/Services/BitcoinServiceTests.cs index 9766a404..10f73d72 100644 --- a/test/NodeGuard.Tests/Services/BitcoinServiceTests.cs +++ b/test/NodeGuard.Tests/Services/BitcoinServiceTests.cs @@ -571,7 +571,7 @@ async Task PerformWithdrawal_SingleSigSucceeds() .Setup(x => x.BroadcastAsync(It.IsAny(), default, default)) .ReturnsAsync(new BroadcastResult() { Success = true }); nodeRepository - .Setup(x => x.GetAllManagedByNodeGuard()) + .Setup(x => x.GetAllManagedByNodeGuard(It.IsAny())) .Returns(Task.FromResult(new List() {node})); var bitcoinService = new BitcoinService(_logger, null, walletWithdrawalRequestRepository.Object, null, nodeRepository.Object, null, nbXplorerService.Object, null); @@ -651,7 +651,7 @@ async Task PerformWithdrawal_MultiSigSucceeds() .Setup(x => x.BroadcastAsync(It.IsAny(), default, default)) .ReturnsAsync(new BroadcastResult() { Success = true }); nodeRepository - .Setup(x => x.GetAllManagedByNodeGuard()) + .Setup(x => x.GetAllManagedByNodeGuard(It.IsAny())) .Returns(Task.FromResult(new List() {node})); var bitcoinService = new BitcoinService(_logger, null, walletWithdrawalRequestRepository.Object, null, nodeRepository.Object, null, nbXplorerService.Object, null); @@ -731,7 +731,7 @@ async Task PerformWithdrawal_LegacyMultiSigSucceeds() .Setup(x => x.BroadcastAsync(It.IsAny(), default, default)) .ReturnsAsync(new BroadcastResult() { Success = true }); nodeRepository - .Setup(x => x.GetAllManagedByNodeGuard()) + .Setup(x => x.GetAllManagedByNodeGuard(It.IsAny())) .Returns(Task.FromResult(new List() {node})); var bitcoinService = new BitcoinService(_logger, null, walletWithdrawalRequestRepository.Object, null, nodeRepository.Object, null, nbXplorerService.Object, null); @@ -741,4 +741,4 @@ async Task PerformWithdrawal_LegacyMultiSigSucceeds() // Assert await act.Should().NotThrowAsync(); } -} \ No newline at end of file +} diff --git a/test/NodeGuard.Tests/Services/LightningServiceTests.cs b/test/NodeGuard.Tests/Services/LightningServiceTests.cs index 5e95b447..9cf8fce6 100644 --- a/test/NodeGuard.Tests/Services/LightningServiceTests.cs +++ b/test/NodeGuard.Tests/Services/LightningServiceTests.cs @@ -406,7 +406,7 @@ public async Task OpenChannel_SuccessLegacyMultiSig() var nodes = new List { destinationNode }; nodeRepository - .Setup(x => x.GetAllManagedByNodeGuard()) + .Setup(x => x.GetAllManagedByNodeGuard(It.IsAny())) .Returns(Task.FromResult(nodes)); var lightningClientService = new Mock(); @@ -597,7 +597,7 @@ public async Task OpenChannel_SuccessMultiSig() var nodes = new List { destinationNode }; nodeRepository - .Setup(x => x.GetAllManagedByNodeGuard()) + .Setup(x => x.GetAllManagedByNodeGuard(It.IsAny())) .Returns(Task.FromResult(nodes)); var lightningClient = new Mock(); @@ -810,7 +810,7 @@ public async Task OpenChannel_SuccessSingleSigBip39() var nodes = new List { destinationNode }; nodeRepository - .Setup(x => x.GetAllManagedByNodeGuard()) + .Setup(x => x.GetAllManagedByNodeGuard(It.IsAny())) .Returns(Task.FromResult(nodes)); var lightningClient = new Mock(); @@ -1029,7 +1029,7 @@ public async Task OpenChannel_FailedIncorrectNumberOfHumanSigs() var nodes = new List { destinationNode }; nodeRepository - .Setup(x => x.GetAllManagedByNodeGuard()) + .Setup(x => x.GetAllManagedByNodeGuard(It.IsAny())) .Returns(Task.FromResult(nodes)); var lightningClient = new Mock(); @@ -1242,7 +1242,7 @@ public async Task OpenChannel_SuccessSingleSig() var nodes = new List { destinationNode }; nodeRepository - .Setup(x => x.GetAllManagedByNodeGuard()) + .Setup(x => x.GetAllManagedByNodeGuard(It.IsAny())) .Returns(Task.FromResult(nodes)); var lightningClient = new Mock(); @@ -1588,7 +1588,7 @@ public async Task GetChannelsStatus_SourceNodeIsManaged_SourceIsInitiator() var nodeRepository = new Mock(); var lightningClientService = new Mock(); - nodeRepository.Setup(x => x.GetAllManagedByNodeGuard()).ReturnsAsync( + nodeRepository.Setup(x => x.GetAllManagedByNodeGuard(It.IsAny())).ReturnsAsync( new List() { new() @@ -1632,7 +1632,7 @@ public async Task GetChannelsStatus_SourceNodeIsManaged_SourceIsNotInitiator() var nodeRepository = new Mock(); var lightningClientService = new Mock(); - nodeRepository.Setup(x => x.GetAllManagedByNodeGuard()).ReturnsAsync( + nodeRepository.Setup(x => x.GetAllManagedByNodeGuard(It.IsAny())).ReturnsAsync( new List() { new() @@ -1676,7 +1676,7 @@ public async Task GetChannelsStatus_BothNodesAreManaged_SourceIsInitiator() var nodeRepository = new Mock(); var lightningClientService = new Mock(); - nodeRepository.Setup(x => x.GetAllManagedByNodeGuard()).ReturnsAsync( + nodeRepository.Setup(x => x.GetAllManagedByNodeGuard(It.IsAny())).ReturnsAsync( new List() { new() @@ -1743,7 +1743,7 @@ public async Task GetChannelsStatus_BothNodesAreManaged_SourceIsNotInitiator() var nodeRepository = new Mock(); var lightningClientService = new Mock(); - nodeRepository.Setup(x => x.GetAllManagedByNodeGuard()).ReturnsAsync( + nodeRepository.Setup(x => x.GetAllManagedByNodeGuard(It.IsAny())).ReturnsAsync( new List() { new() @@ -1803,4 +1803,4 @@ public async Task GetChannelsStatus_BothNodesAreManaged_SourceIsNotInitiator() channelStatus[0].RemoteBalance.Should().Be(0); } } -} \ No newline at end of file +}