Wait or trigger connection confirmation
MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/AliceTimeoutTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/AliceTimeoutTests.cs
@@ -29,7 +29,9 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
// Register Alices.
var minAliceDeadline = DateTimeOffset.UtcNow + cfg.ConnectionConfirmationTimeout * 0.9;
- var aliceClient = new AliceClient(round.Id, arenaClient, coin, round.FeeRate, key.GetBitcoinSecret(round.Network));
+
+ using RoundStateUpdater roundStateUpdater = new(TimeSpan.FromSeconds(2), new ArenaRequestHandlerAdapter(arena));
+ var aliceClient = new AliceClient(round.Id, arenaClient, coin, round.FeeRate, key.GetBitcoinSecret(round.Network), roundStateUpdater);
await aliceClient.RegisterInputAsync(CancellationToken.None);
var alice = Assert.Single(round.Alices);

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PhaseStepping/StepOutputRegistrationTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PhaseStepping/StepOutputRegistrationTests.cs
@@ -206,9 +206,10 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PhaseStepping
var arenaClient = WabiSabiFactory.CreateArenaClient(arena);
var round = Assert.Single(arena.Rounds);
+ using RoundStateUpdater roundStateUpdater = new(TimeSpan.FromSeconds(2), new ArenaRequestHandlerAdapter(arena));
// Register Alices.
- var aliceClient1 = new AliceClient(round.Id, arenaClient, coin1, round.FeeRate, key1.GetBitcoinSecret(round.Network));
- var aliceClient2 = new AliceClient(round.Id, arenaClient, coin2, round.FeeRate, key2.GetBitcoinSecret(round.Network));
+ var aliceClient1 = new AliceClient(round.Id, arenaClient, coin1, round.FeeRate, key1.GetBitcoinSecret(round.Network), roundStateUpdater);
+ var aliceClient2 = new AliceClient(round.Id, arenaClient, coin2, round.FeeRate, key2.GetBitcoinSecret(round.Network), roundStateUpdater);
await aliceClient1.RegisterInputAsync(CancellationToken.None).ConfigureAwait(false);
await aliceClient2.RegisterInputAsync(CancellationToken.None).ConfigureAwait(false);

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PhaseStepping/StepTransactionSigningTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PhaseStepping/StepTransactionSigningTests.cs
@@ -236,9 +236,11 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PhaseStepping
var round = Assert.Single(arena.Rounds);
var arenaClient = WabiSabiFactory.CreateArenaClient(arena);
+ using RoundStateUpdater roundStateUpdater = new(TimeSpan.FromSeconds(2), new ArenaRequestHandlerAdapter(arena));
+
// Register Alices.
- var aliceClient1 = new AliceClient(round.Id, arenaClient, coin1, round.FeeRate, key1.GetBitcoinSecret(round.Network));
- var aliceClient2 = new AliceClient(round.Id, arenaClient, coin2, round.FeeRate, key2.GetBitcoinSecret(round.Network));
+ var aliceClient1 = new AliceClient(round.Id, arenaClient, coin1, round.FeeRate, key1.GetBitcoinSecret(round.Network), roundStateUpdater);
+ var aliceClient2 = new AliceClient(round.Id, arenaClient, coin2, round.FeeRate, key2.GetBitcoinSecret(round.Network), roundStateUpdater);
await aliceClient1.RegisterInputAsync(CancellationToken.None).ConfigureAwait(false);
await aliceClient2.RegisterInputAsync(CancellationToken.None).ConfigureAwait(false);

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Client/AliceClientTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Client/AliceClientTests.cs
@@ -48,7 +48,8 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Client
var bitcoinSecret = km.GetSecrets("", coin1.ScriptPubKey).Single().PrivateKey.GetBitcoinSecret(Network.Main);
- var aliceClient = new AliceClient(round.Id, arenaClient, coin1.Coin, round.FeeRate, bitcoinSecret);
+ using RoundStateUpdater roundStateUpdater = new(TimeSpan.FromSeconds(2), wabiSabiApi);
+ var aliceClient = new AliceClient(round.Id, arenaClient, coin1.Coin, round.FeeRate, bitcoinSecret, roundStateUpdater);
await aliceClient.RegisterInputAsync(CancellationToken.None);
Task confirmationTask = aliceClient.ConfirmConnectionAsync(

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Client/BobClientTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Client/BobClientTests.cs
@@ -49,7 +49,8 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Client
var bitcoinSecret = km.GetSecrets("", coin1.ScriptPubKey).Single().PrivateKey.GetBitcoinSecret(Network.Main);
- var aliceClient = new AliceClient(round.Id, aliceArenaClient, coin1.Coin, round.FeeRate, bitcoinSecret);
+ using RoundStateUpdater roundStateUpdater = new(TimeSpan.FromSeconds(2), wabiSabiApi);
+ var aliceClient = new AliceClient(round.Id, aliceArenaClient, coin1.Coin, round.FeeRate, bitcoinSecret, roundStateUpdater);
await aliceClient.RegisterInputAsync(CancellationToken.None);
Task confirmationTask = aliceClient.ConfirmConnectionAsync(

MODIFY
WalletWasabi/WabiSabi/Client/AliceClient.cs
WalletWasabi/WabiSabi/Client/AliceClient.cs
@@ -9,12 +9,13 @@ using WalletWasabi.Crypto.ZeroKnowledge;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
using WalletWasabi.WabiSabi.Backend.Models;
+using WalletWasabi.WabiSabi.Backend.Rounds;
namespace WalletWasabi.WabiSabi.Client
{
public class AliceClient
{
- public AliceClient(uint256 roundId, ArenaClient arenaClient, Coin coin, FeeRate feeRate, BitcoinSecret bitcoinSecret)
+ public AliceClient(uint256 roundId, ArenaClient arenaClient, Coin coin, FeeRate feeRate, BitcoinSecret bitcoinSecret, RoundStateUpdater roundStatusUpdater)
{
AliceId = CalculateHash(coin, bitcoinSecret, roundId);
RoundId = roundId;
@@ -22,6 +23,7 @@ namespace WalletWasabi.WabiSabi.Client
Coin = coin;
FeeRate = feeRate;
BitcoinSecret = bitcoinSecret;
+ RoundStatusUpdater = roundStatusUpdater;
IssuedAmountCredentials = Array.Empty<Credential>();
IssuedVsizeCredentials = Array.Empty<Credential>();
}
@@ -32,6 +34,7 @@ namespace WalletWasabi.WabiSabi.Client
public Coin Coin { get; }
private FeeRate FeeRate { get; }
private BitcoinSecret BitcoinSecret { get; }
+ private RoundStateUpdater RoundStatusUpdater { get; }
public IEnumerable<Credential> IssuedAmountCredentials { get; private set; }
public IEnumerable<Credential> IssuedVsizeCredentials { get; private set; }
@@ -50,10 +53,16 @@ namespace WalletWasabi.WabiSabi.Client
public async Task ConfirmConnectionAsync(TimeSpan connectionConfirmationTimeout, IEnumerable<long> amountsToRequest, IEnumerable<long> vsizesToRequest, CancellationToken cancellationToken)
{
- while (!await TryConfirmConnectionAsync(amountsToRequest, vsizesToRequest, cancellationToken).ConfigureAwait(false))
+ do
{
- await Task.Delay(connectionConfirmationTimeout / 2, cancellationToken).ConfigureAwait(false);
+ using CancellationTokenSource timeout = new(connectionConfirmationTimeout / 2);
+ using CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeout.Token);
+
+ await RoundStatusUpdater
+ .CreateRoundAwaiter(RoundId, roundState => roundState.Phase == Phase.ConnectionConfirmation, cts.Token)
+ .ConfigureAwait(false);
}
+ while (!await TryConfirmConnectionAsync(amountsToRequest, vsizesToRequest, cancellationToken).ConfigureAwait(false));
}
private async Task<bool> TryConfirmConnectionAsync(IEnumerable<long> amountsToRequest, IEnumerable<long> vsizesToRequest, CancellationToken cancellationToken)

MODIFY
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
@@ -91,7 +91,6 @@ namespace WalletWasabi.WabiSabi.Client
// Register coins.
await RegisterCoinsAsync(aliceClients, cancellationToken).ConfigureAwait(false);
- roundState = await RoundStatusUpdater.CreateRoundAwaiter(roundState => roundState.Phase == Phase.ConnectionConfirmation, cancellationToken).ConfigureAwait(false);
// Confirm coins.
await scheduler.StartConfirmConnectionsAsync(aliceClients, dependencyGraph, roundState.ConnectionConfirmationTimeout, cancellationToken).ConfigureAwait(false);
@@ -138,7 +137,7 @@ namespace WalletWasabi.WabiSabi.Client
var hdKey = Keymanager.GetSecrets(Kitchen.SaltSoup(), coin.ScriptPubKey).Single();
var secret = hdKey.PrivateKey.GetBitcoinSecret(Keymanager.GetNetwork());
- aliceClients.Add(new AliceClient(roundState.Id, aliceArenaClient, coin, roundState.FeeRate, secret));
+ aliceClients.Add(new AliceClient(roundState.Id, aliceArenaClient, coin, roundState.FeeRate, secret, RoundStatusUpdater));
}
return aliceClients;
}

Wait or trigger connection confirmation