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 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;
}

View File

@@ -13,7 +13,7 @@
<PropertyGroup>
<Product>Wabisabi Coinjoin</Product>
<Description>Allows you to integrate your btcpayserver store with coinjoins.</Description>
<Version>1.0.30</Version>
<Version>1.0.31</Version>
</PropertyGroup>
<!-- Plugin development properties -->

View File

@@ -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)

View File

@@ -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);

View File

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

View File

@@ -16,21 +16,17 @@ 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,
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<WabisabiStoreSettings> GetWabisabiForStore(string storeId)

View File

@@ -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))
{
@@ -25,15 +26,23 @@ public class WasabiCoordinatorStatusFetcher : PeriodicRunner, IWasabiBackendStat
protected override async Task ActionAsync(CancellationToken cancel)
{
try
{
if (OverrideConnected is { })
{
Connected = OverrideConnected.Value;
}
else
{
await _wasabiClient.GetStatusAsync(new RoundStateRequest(ImmutableList<RoundStateCheckpoint>.Empty), cancel);
if (!Connected)
{
_logger.LogInformation("Connected to coordinator" );
}
Connected = true;
}
}
catch (Exception e)
{
Connected = false;