MarkDestinationsUsed according to the result directly
MODIFY
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
@@ -152,7 +152,8 @@ public class CoinJoinClient
return new CoinJoinResult(
GoForBlameRound: false,
SuccessfulBroadcast: false,
- RegisteredCoins: Enumerable.Empty<SmartCoin>());
+ RegisteredCoins: ImmutableList<SmartCoin>.Empty,
+ RegisteredOutputs: ImmutableList<Script>.Empty);
}
if (!registeredAliceClients.Any())
@@ -162,7 +163,8 @@ public class CoinJoinClient
return new CoinJoinResult(
GoForBlameRound: false,
SuccessfulBroadcast: false,
- RegisteredCoins: Enumerable.Empty<SmartCoin>());
+ RegisteredCoins: ImmutableList<SmartCoin>.Empty,
+ RegisteredOutputs: ImmutableList<Script>.Empty);
}
try
@@ -242,7 +244,8 @@ public class CoinJoinClient
return new CoinJoinResult(
GoForBlameRound: !finalRoundState.WasTransactionBroadcast,
SuccessfulBroadcast: finalRoundState.WasTransactionBroadcast,
- RegisteredCoins: registeredAliceClients.Select(a => a.SmartCoin));
+ RegisteredCoins: registeredAliceClients.Select(a => a.SmartCoin).ToImmutableList(),
+ RegisteredOutputs: outputTxOuts.Select(o => o.ScriptPubKey).ToImmutableList());
}
finally
{

MODIFY
WalletWasabi/WabiSabi/Client/CoinJoinManager.cs
WalletWasabi/WabiSabi/Client/CoinJoinManager.cs
@@ -164,7 +164,7 @@ public class CoinJoinManager : BackgroundService
if (result.SuccessfulBroadcast)
{
CoinRefrigerator.Freeze(result.RegisteredCoins);
- MarkDestinationsUsed(finishedCoinJoin);
+ MarkDestinationsUsed(finishedCoinJoin.Wallet, result.RegisteredOutputs);
Logger.LogInfo($"{logPrefix} finished!");
}
else
@@ -199,16 +199,11 @@ public class CoinJoinManager : BackgroundService
/// <summary>
/// Mark all the outputs we had in any of our wallets used.
/// </summary>
- private void MarkDestinationsUsed(CoinJoinTracker finishedCoinJoin)
- {
- foreach (var k in WalletManager
- .GetWallets(false)
- .SelectMany(w => w
- .KeyManager
- .GetKeys(k => finishedCoinJoin
- .Destinations
- .Select(d => d.ScriptPubKey)
- .Contains(k.P2wpkhScript))))
+ private void MarkDestinationsUsed(Wallet wallet, ImmutableList<Script> outputs)
+ {
+ var hashSet = outputs.ToHashSet();
+
+ foreach (var k in wallet.KeyManager.GetKeys(k => hashSet.Contains(k.P2wpkhScript)))
{
k.SetKeyState(KeyState.Used);
}

MODIFY
WalletWasabi/WabiSabi/Client/CoinJoinResult.cs
WalletWasabi/WabiSabi/Client/CoinJoinResult.cs
+using NBitcoin;
using System.Collections.Generic;
+using System.Collections.Immutable;
using WalletWasabi.Blockchain.TransactionOutputs;
namespace WalletWasabi.WabiSabi.Client;
@@ -6,6 +8,7 @@ namespace WalletWasabi.WabiSabi.Client;
public record CoinJoinResult(
bool GoForBlameRound,
bool SuccessfulBroadcast,
- IEnumerable<SmartCoin> RegisteredCoins)
+ ImmutableList<SmartCoin> RegisteredCoins,
+ ImmutableList<Script> RegisteredOutputs)
{
}

MarkDestinationsUsed according to the result directly