This commit is contained in:
Kukks
2023-04-20 14:04:50 +02:00
parent 715bb32ed4
commit 75cc4feafb
8 changed files with 41 additions and 23 deletions

View File

@@ -100,9 +100,9 @@ public class BTCPayCoinjoinCoinSelector : IRoundCoinSelector
var remainingPendingPayments = new List<PendingPayment>(pendingPayments); var remainingPendingPayments = new List<PendingPayment>(pendingPayments);
var solution = new SubsetSolution(remainingPendingPayments.Count, _wallet.AnonScoreTarget, var solution = new SubsetSolution(remainingPendingPayments.Count, _wallet.AnonScoreTarget,
utxoSelectionParameters); utxoSelectionParameters);
var fullyPrivate = remainingCoins.All(coin => coin.CoinColor(_wallet.AnonScoreTarget) == AnonsetType.Green);
if (remainingCoins.All(coin => coin.CoinColor(_wallet.AnonScoreTarget) == AnonsetType.Green) && var coinjoiningOnlyForPayments = fullyPrivate && remainingPendingPayments.Any();
!remainingPendingPayments.Any()) if (fullyPrivate && !coinjoiningOnlyForPayments)
{ {
var rand = Random.Shared.Next(1, 1001); var rand = Random.Shared.Next(1, 1001);
if (rand > _wallet.WabisabiStoreSettings.ExtraJoinProbability) if (rand > _wallet.WabisabiStoreSettings.ExtraJoinProbability)
@@ -200,6 +200,14 @@ public class BTCPayCoinjoinCoinSelector : IRoundCoinSelector
} }
} }
} }
if (coinjoiningOnlyForPayments && solution.HandledPayments?.Any() is not true)
{
_logger.LogInformation(
"Attempted to coinjoin only to fulfill payments but the coin selection results yieleded no handled payment.");
return new SubsetSolution(remainingPendingPayments.Count, _wallet.AnonScoreTarget,
utxoSelectionParameters);
}
return solution; return solution;
} }

View File

@@ -13,7 +13,7 @@
<PropertyGroup> <PropertyGroup>
<Product>Wabisabi Coinjoin</Product> <Product>Wabisabi 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.30</Version> <Version>1.0.31</Version>
</PropertyGroup> </PropertyGroup>
<!-- Plugin development properties --> <!-- Plugin development properties -->

View File

@@ -185,12 +185,21 @@ public class WabisabiCoordinatorService : PeriodicRunner
public async Task StartCoordinator(CancellationToken cancellationToken) public async Task StartCoordinator(CancellationToken cancellationToken)
{ {
await HostedServices.StartAllAsync(cancellationToken); await HostedServices.StartAllAsync(cancellationToken);
if (_instanceManager.HostedServices.TryGetValue("local", out var instance))
{
instance.WasabiCoordinatorStatusFetcher.OverrideConnected = null;
}
_instanceManager.AddCoordinator("Local Coordinator", "local", _ => null, cachedSettings.TermsConditions); _instanceManager.AddCoordinator("Local Coordinator", "local", _ => null, cachedSettings.TermsConditions);
} }
public async Task StopAsync(CancellationToken cancellationToken) public async Task StopAsync(CancellationToken cancellationToken)
{ {
if (_instanceManager.HostedServices.TryGetValue("local", out var instance))
{
instance.WasabiCoordinatorStatusFetcher.OverrideConnected = false;
}
await HostedServices.StopAllAsync(cancellationToken); await HostedServices.StopAllAsync(cancellationToken);
} }
protected override async Task ActionAsync(CancellationToken cancel) protected override async Task ActionAsync(CancellationToken cancel)

View File

@@ -200,7 +200,7 @@ public class WabisabiCoordinatorClientInstance
switch (e) switch (e)
{ {
case CoinJoinStatusEventArgs coinJoinStatusEventArgs: case CoinJoinStatusEventArgs coinJoinStatusEventArgs:
_logger.LogTrace(coinJoinStatusEventArgs.CoinJoinProgressEventArgs.GetType() + " :" + _logger.LogInformation(coinJoinStatusEventArgs.CoinJoinProgressEventArgs.GetType() + " :" +
e.Wallet.WalletName); e.Wallet.WalletName);
break; break;
case CompletedEventArgs completedEventArgs: case CompletedEventArgs completedEventArgs:
@@ -234,10 +234,7 @@ public class WabisabiCoordinatorClientInstance
_ = CoinJoinManager.StartAsync(loadedEventArgs.Wallet, stopWhenAllMixed, false, CancellationToken.None); _ = CoinJoinManager.StartAsync(loadedEventArgs.Wallet, stopWhenAllMixed, false, CancellationToken.None);
break; break;
case StartErrorEventArgs errorArgs: case StartErrorEventArgs errorArgs:
stopWhenAllMixed = !((BTCPayWallet)errorArgs.Wallet).BatchPayments; _logger.LogInformation("Could not start wallet for coinjoin:" + errorArgs.Error.ToString() + " :" + e.Wallet.WalletName);
_ = CoinJoinManager.StartAsync(errorArgs.Wallet, stopWhenAllMixed, false, CancellationToken.None);
// _logger.LogInformation("Could not start wallet for coinjoin:" + errorArgs.Error.ToString() + " :" + e.Wallet.WalletName);
break; break;
case StoppedEventArgs stoppedEventArgs: case StoppedEventArgs stoppedEventArgs:
_logger.LogInformation("Stopped wallet for coinjoin: " + stoppedEventArgs.Reason + " :" + e.Wallet.WalletName); _logger.LogInformation("Stopped wallet for coinjoin: " + stoppedEventArgs.Reason + " :" + e.Wallet.WalletName);
@@ -250,7 +247,6 @@ public class WabisabiCoordinatorClientInstance
public Task StartAsync(CancellationToken cancellationToken) public Task StartAsync(CancellationToken cancellationToken)
{ {
RoundStateUpdater.StartAsync(cancellationToken); RoundStateUpdater.StartAsync(cancellationToken);
WasabiCoordinatorStatusFetcher.StartAsync(cancellationToken); WasabiCoordinatorStatusFetcher.StartAsync(cancellationToken);
CoinJoinManager.StartAsync(cancellationToken); CoinJoinManager.StartAsync(cancellationToken);

View File

@@ -75,7 +75,7 @@ public class WabisabiPlugin : BaseBTCPayServerPlugin
"onchain-wallet-send")); "onchain-wallet-send"));
// applicationBuilder.AddSingleton<IPayoutProcessorFactory, WabisabiPayoutProcessor>(); // applicationBuilder.AddSingleton<IPayoutProcessorFactory, WabisabiPayoutProcessor>();
Logger.SetMinimumLevel(LogLevel.Debug); Logger.SetMinimumLevel(LogLevel.Warning);
Logger.SetModes(LogMode.DotNetLoggers); Logger.SetModes(LogMode.DotNetLoggers);

View File

@@ -16,21 +16,17 @@ namespace BTCPayServer.Plugins.Wabisabi
private readonly WabisabiCoordinatorClientInstanceManager _coordinatorClientInstanceManager; private readonly WabisabiCoordinatorClientInstanceManager _coordinatorClientInstanceManager;
private readonly WalletProvider _walletProvider; private readonly WalletProvider _walletProvider;
private readonly WalletRepository _walletRepository; private readonly WalletRepository _walletRepository;
private readonly PayoutProcessorService _payoutProcessorService;
private readonly EventAggregator _eventAggregator;
private string[] _ids => _coordinatorClientInstanceManager.HostedServices.Keys.ToArray(); private string[] _ids => _coordinatorClientInstanceManager.HostedServices.Keys.ToArray();
public WabisabiService( IStoreRepository storeRepository, public WabisabiService(IStoreRepository storeRepository,
WabisabiCoordinatorClientInstanceManager coordinatorClientInstanceManager, WabisabiCoordinatorClientInstanceManager coordinatorClientInstanceManager,
WalletProvider walletProvider, WalletProvider walletProvider,
WalletRepository walletRepository,PayoutProcessorService payoutProcessorService, EventAggregator eventAggregator) WalletRepository walletRepository)
{ {
_storeRepository = storeRepository; _storeRepository = storeRepository;
_coordinatorClientInstanceManager = coordinatorClientInstanceManager; _coordinatorClientInstanceManager = coordinatorClientInstanceManager;
_walletProvider = walletProvider; _walletProvider = walletProvider;
_walletRepository = walletRepository; _walletRepository = walletRepository;
_payoutProcessorService = payoutProcessorService;
_eventAggregator = eventAggregator;
} }
public async Task<WabisabiStoreSettings> GetWabisabiForStore(string storeId) public async Task<WabisabiStoreSettings> GetWabisabiForStore(string storeId)

View File

@@ -15,6 +15,7 @@ public class WasabiCoordinatorStatusFetcher : PeriodicRunner, IWasabiBackendStat
private readonly IWabiSabiApiRequestHandler _wasabiClient; private readonly IWabiSabiApiRequestHandler _wasabiClient;
private readonly ILogger _logger; private readonly ILogger _logger;
public bool Connected { get; set; } = false; public bool Connected { get; set; } = false;
public bool? OverrideConnected { get; set; }
public WasabiCoordinatorStatusFetcher(IWabiSabiApiRequestHandler wasabiClient, ILogger logger) : public WasabiCoordinatorStatusFetcher(IWabiSabiApiRequestHandler wasabiClient, ILogger logger) :
base(TimeSpan.FromSeconds(30)) base(TimeSpan.FromSeconds(30))
{ {
@@ -25,15 +26,23 @@ public class WasabiCoordinatorStatusFetcher : PeriodicRunner, IWasabiBackendStat
protected override async Task ActionAsync(CancellationToken cancel) protected override async Task ActionAsync(CancellationToken cancel)
{ {
try try
{
if (OverrideConnected is { })
{
Connected = OverrideConnected.Value;
}
else
{ {
await _wasabiClient.GetStatusAsync(new RoundStateRequest(ImmutableList<RoundStateCheckpoint>.Empty), cancel); await _wasabiClient.GetStatusAsync(new RoundStateRequest(ImmutableList<RoundStateCheckpoint>.Empty), cancel);
if (!Connected) if (!Connected)
{ {
_logger.LogInformation("Connected to coordinator" ); _logger.LogInformation("Connected to coordinator" );
} }
Connected = true; Connected = true;
} }
}
catch (Exception e) catch (Exception e)
{ {
Connected = false; Connected = false;