Skip to content

Commit

Permalink
fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Kukks committed Sep 18, 2024
1 parent cf5ab8f commit 70e4eb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion BTCPayApp.Core/Attempt2/LightningNodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,24 @@ public LightningNodeManager(

public async Task StartNode()
{
if (_nodeScope is not null || State is LightningNodeState.Loaded or LightningNodeState.NotConfigured || _onChainWalletManager.State is not OnChainWalletState.Loaded)
if (_nodeScope is not null || State is LightningNodeState.Loaded or LightningNodeState.NotConfigured )
{
return;
}


_logger.LogInformation("Starting lightning node");
await _controlSemaphore.WaitAsync();

_logger.LogInformation("Starting lightning node: lock acquired");
try
{
if (_onChainWalletManager.State is not OnChainWalletState.Loaded)
{
State = LightningNodeState.WaitingForConnection;

return;
}
if (_nodeScope is null)
{
_nodeScope = _serviceScopeFactory.CreateScope();
Expand Down
2 changes: 1 addition & 1 deletion BTCPayApp.Tests/CoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ await node2.LNManager.Node.UpdateConfig(async config =>
return (config, true);
});
await TestUtils.EventuallyAsync(async () =>
Assert.True((await node.LNManager.Node.GetConfig()).AcceptInboundConnection));
Assert.True((await node2.LNManager.Node.GetConfig()).AcceptInboundConnection));
TestUtils.Eventually(
async () => Assert.NotNull(node.App.Services.GetRequiredService<LDKPeerHandler>().Endpoint));

Expand Down

0 comments on commit 70e4eb2

Please sign in to comment.