mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-16 23:24:25 +01:00
attempt to remove coordinators when it's obviously down
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Product>Coinjoin</Product>
|
<Product>Coinjoin</Product>
|
||||||
<Description>Allows you to integrate your btcpayserver store with coinjoins.</Description>
|
<Description>Allows you to integrate your btcpayserver store with coinjoins.</Description>
|
||||||
<Version>1.0.104</Version>
|
<Version>1.0.105</Version>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -338,7 +338,8 @@ public class WabisabiCoordinatorClientInstance:IHostedService
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
WasabiCoordinatorStatusFetcher = new WasabiCoordinatorStatusFetcher(sharedWabisabiClient, _logger);
|
WasabiCoordinatorStatusFetcher = new WasabiCoordinatorStatusFetcher(sharedWabisabiClient, _logger, () => serviceProvider.GetService<WabisabiCoordinatorClientInstanceManager>().RemoveCoordinator(this.CoordinatorName) );
|
||||||
|
|
||||||
|
|
||||||
RoundStateUpdater =
|
RoundStateUpdater =
|
||||||
new RoundStateUpdater(TimeSpan.FromSeconds(5), sharedWabisabiClient, WasabiCoordinatorStatusFetcher);
|
new RoundStateUpdater(TimeSpan.FromSeconds(5), sharedWabisabiClient, WasabiCoordinatorStatusFetcher);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using WalletWasabi.Bases;
|
using WalletWasabi.Bases;
|
||||||
using WalletWasabi.WabiSabi.Backend.PostRequests;
|
using WalletWasabi.WabiSabi.Backend.PostRequests;
|
||||||
@@ -14,15 +15,20 @@ public class WasabiCoordinatorStatusFetcher : PeriodicRunner, IWasabiBackendStat
|
|||||||
{
|
{
|
||||||
private readonly IWabiSabiApiRequestHandler _wasabiClient;
|
private readonly IWabiSabiApiRequestHandler _wasabiClient;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
private readonly Action _onRemove;
|
||||||
public bool Connected { get; set; } = false;
|
public bool Connected { get; set; } = false;
|
||||||
public bool? OverrideConnected { get; set; }
|
public bool? OverrideConnected { get; set; }
|
||||||
public WasabiCoordinatorStatusFetcher(IWabiSabiApiRequestHandler wasabiClient, ILogger logger) :
|
|
||||||
|
public WasabiCoordinatorStatusFetcher(IWabiSabiApiRequestHandler wasabiClient, ILogger logger, Action onRemove) :
|
||||||
base(TimeSpan.FromSeconds(30))
|
base(TimeSpan.FromSeconds(30))
|
||||||
{
|
{
|
||||||
_wasabiClient = wasabiClient;
|
_wasabiClient = wasabiClient;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_onRemove = onRemove;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int _retries = 0;
|
||||||
|
|
||||||
protected override async Task ActionAsync(CancellationToken cancel)
|
protected override async Task ActionAsync(CancellationToken cancel)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -33,19 +39,30 @@ public class WasabiCoordinatorStatusFetcher : PeriodicRunner, IWasabiBackendStat
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _wasabiClient.GetStatusAsync(new RoundStateRequest(ImmutableList<RoundStateCheckpoint>.Empty), cancel);
|
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel);
|
||||||
|
cts.CancelAfter(30000);
|
||||||
|
await _wasabiClient.GetStatusAsync(new RoundStateRequest(ImmutableList<RoundStateCheckpoint>.Empty),
|
||||||
|
cts.Token);
|
||||||
if (!Connected)
|
if (!Connected)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Connected to coordinator");
|
_logger.LogInformation("Connected to coordinator");
|
||||||
}
|
}
|
||||||
|
|
||||||
Connected = true;
|
Connected = true;
|
||||||
|
_retries = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Connected = false;
|
Connected = false;
|
||||||
|
_retries++;
|
||||||
|
if (_retries > 5)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "Could not connect to the coordinator after 5 retries, removing from the system");
|
||||||
|
_onRemove.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
await Task.Delay(Period * _retries, cancel);
|
||||||
throw new Exception("Could not connect to the coordinator", e);
|
throw new Exception("Could not connect to the coordinator", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user