diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs index f3ef9ab..6faf6a8 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs @@ -100,9 +100,9 @@ public class BTCPayCoinjoinCoinSelector : IRoundCoinSelector var remainingPendingPayments = new List(pendingPayments); var solution = new SubsetSolution(remainingPendingPayments.Count, _wallet.AnonScoreTarget, utxoSelectionParameters); - - if (remainingCoins.All(coin => coin.CoinColor(_wallet.AnonScoreTarget) == AnonsetType.Green) && - !remainingPendingPayments.Any()) + var fullyPrivate = remainingCoins.All(coin => coin.CoinColor(_wallet.AnonScoreTarget) == AnonsetType.Green); + var coinjoiningOnlyForPayments = fullyPrivate && remainingPendingPayments.Any(); + if (fullyPrivate && !coinjoiningOnlyForPayments) { var rand = Random.Shared.Next(1, 1001); 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; } diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayServer.Plugins.Wabisabi.csproj b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayServer.Plugins.Wabisabi.csproj index 542fc42..43ae03c 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayServer.Plugins.Wabisabi.csproj +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayServer.Plugins.Wabisabi.csproj @@ -13,7 +13,7 @@ Wabisabi Coinjoin Allows you to integrate your btcpayserver store with coinjoins. - 1.0.30 + 1.0.31 diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorService.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorService.cs index 7c26016..3737bfb 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorService.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorService.cs @@ -185,12 +185,21 @@ public class WabisabiCoordinatorService : PeriodicRunner public async Task StartCoordinator(CancellationToken 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); } public async Task StopAsync(CancellationToken cancellationToken) { + if (_instanceManager.HostedServices.TryGetValue("local", out var instance)) + { + instance.WasabiCoordinatorStatusFetcher.OverrideConnected = false; + } await HostedServices.StopAllAsync(cancellationToken); + } protected override async Task ActionAsync(CancellationToken cancel) diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiCoordinatorClientInstance.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiCoordinatorClientInstance.cs index 5829a27..b0f0857 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiCoordinatorClientInstance.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiCoordinatorClientInstance.cs @@ -200,7 +200,7 @@ public class WabisabiCoordinatorClientInstance switch (e) { case CoinJoinStatusEventArgs coinJoinStatusEventArgs: - _logger.LogTrace(coinJoinStatusEventArgs.CoinJoinProgressEventArgs.GetType() + " :" + + _logger.LogInformation(coinJoinStatusEventArgs.CoinJoinProgressEventArgs.GetType() + " :" + e.Wallet.WalletName); break; case CompletedEventArgs completedEventArgs: @@ -234,10 +234,7 @@ public class WabisabiCoordinatorClientInstance _ = CoinJoinManager.StartAsync(loadedEventArgs.Wallet, stopWhenAllMixed, false, CancellationToken.None); break; case StartErrorEventArgs errorArgs: - stopWhenAllMixed = !((BTCPayWallet)errorArgs.Wallet).BatchPayments; - _ = CoinJoinManager.StartAsync(errorArgs.Wallet, stopWhenAllMixed, false, CancellationToken.None); - - // _logger.LogInformation("Could not start wallet for coinjoin:" + errorArgs.Error.ToString() + " :" + e.Wallet.WalletName); + _logger.LogInformation("Could not start wallet for coinjoin:" + errorArgs.Error.ToString() + " :" + e.Wallet.WalletName); break; case StoppedEventArgs stoppedEventArgs: _logger.LogInformation("Stopped wallet for coinjoin: " + stoppedEventArgs.Reason + " :" + e.Wallet.WalletName); @@ -250,7 +247,6 @@ public class WabisabiCoordinatorClientInstance public Task StartAsync(CancellationToken cancellationToken) { - RoundStateUpdater.StartAsync(cancellationToken); WasabiCoordinatorStatusFetcher.StartAsync(cancellationToken); CoinJoinManager.StartAsync(cancellationToken); diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiPlugin.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiPlugin.cs index 4487830..dd538cd 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiPlugin.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiPlugin.cs @@ -75,7 +75,7 @@ public class WabisabiPlugin : BaseBTCPayServerPlugin "onchain-wallet-send")); // applicationBuilder.AddSingleton(); - Logger.SetMinimumLevel(LogLevel.Debug); + Logger.SetMinimumLevel(LogLevel.Warning); Logger.SetModes(LogMode.DotNetLoggers); diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiService.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiService.cs index e05e6e5..2a44fbf 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiService.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiService.cs @@ -16,23 +16,19 @@ namespace BTCPayServer.Plugins.Wabisabi private readonly WabisabiCoordinatorClientInstanceManager _coordinatorClientInstanceManager; private readonly WalletProvider _walletProvider; private readonly WalletRepository _walletRepository; - private readonly PayoutProcessorService _payoutProcessorService; - private readonly EventAggregator _eventAggregator; private string[] _ids => _coordinatorClientInstanceManager.HostedServices.Keys.ToArray(); - public WabisabiService( IStoreRepository storeRepository, + public WabisabiService(IStoreRepository storeRepository, WabisabiCoordinatorClientInstanceManager coordinatorClientInstanceManager, WalletProvider walletProvider, - WalletRepository walletRepository,PayoutProcessorService payoutProcessorService, EventAggregator eventAggregator) + WalletRepository walletRepository) { _storeRepository = storeRepository; _coordinatorClientInstanceManager = coordinatorClientInstanceManager; _walletProvider = walletProvider; _walletRepository = walletRepository; - _payoutProcessorService = payoutProcessorService; - _eventAggregator = eventAggregator; } - + public async Task GetWabisabiForStore(string storeId) { diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/WasabiCoordinatorStatusFetcher.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/WasabiCoordinatorStatusFetcher.cs index b5db81a..1d4996b 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/WasabiCoordinatorStatusFetcher.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/WasabiCoordinatorStatusFetcher.cs @@ -15,6 +15,7 @@ public class WasabiCoordinatorStatusFetcher : PeriodicRunner, IWasabiBackendStat private readonly IWabiSabiApiRequestHandler _wasabiClient; private readonly ILogger _logger; public bool Connected { get; set; } = false; + public bool? OverrideConnected { get; set; } public WasabiCoordinatorStatusFetcher(IWabiSabiApiRequestHandler wasabiClient, ILogger logger) : base(TimeSpan.FromSeconds(30)) { @@ -26,13 +27,21 @@ public class WasabiCoordinatorStatusFetcher : PeriodicRunner, IWasabiBackendStat { try { - await _wasabiClient.GetStatusAsync(new RoundStateRequest(ImmutableList.Empty), cancel); - if (!Connected) + if (OverrideConnected is { }) { - _logger.LogInformation("Connected to coordinator" ); + Connected = OverrideConnected.Value; } + else + { + await _wasabiClient.GetStatusAsync(new RoundStateRequest(ImmutableList.Empty), cancel); + if (!Connected) + { + _logger.LogInformation("Connected to coordinator" ); + } + Connected = true; + } + - Connected = true; } catch (Exception e) { diff --git a/submodules/walletwasabi b/submodules/walletwasabi index 6c653a0..c133070 160000 --- a/submodules/walletwasabi +++ b/submodules/walletwasabi @@ -1 +1 @@ -Subproject commit 6c653a0e140c8ab50ff6c23d4ba616d128974850 +Subproject commit c133070ecfbdb85f2cced307c48ba73f1ad915b3