Add parallelization and timing to SignTransactionAsync
MODIFY
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
@@ -211,6 +211,7 @@ public class CoinJoinClient
// Signing.
roundState = await RoundStatusUpdater.CreateRoundAwaiter(roundState.Id, Phase.TransactionSigning, cancellationToken).ConfigureAwait(false);
+ var signingEndTime = DateTimeOffset.UtcNow + roundState.TransactionSigningTimeout - RoundStatusUpdater.Period;
Logger.LogDebug($"Round ({roundState.Id}): Transaction signing phase started.");
var signingState = roundState.Assert<SigningState>();
@@ -223,8 +224,7 @@ public class CoinJoinClient
}
// Send signature.
- await SignTransactionAsync(registeredAliceClients, unsignedCoinJoin, roundState, cancellationToken).ConfigureAwait(false);
- Logger.LogDebug($"Round ({roundState.Id}): Alices({registeredAliceClients.Length}) successfully signed the coinjoin tx.");
+ await SignTransactionAsync(registeredAliceClients, unsignedCoinJoin, signingEndTime, cancellationToken).ConfigureAwait(false); Logger.LogDebug($"Round ({roundState.Id}): Alices({registeredAliceClients.Length}) successfully signed the coinjoin tx.");
var finalRoundState = await RoundStatusUpdater.CreateRoundAwaiter(s => s.Id == roundState.Id && s.Phase == Phase.Ended, cancellationToken).ConfigureAwait(false);
Logger.LogDebug($"Round ({roundState.Id}): Round Ended - WasTransactionBroadcast: '{finalRoundState.WasTransactionBroadcast}'.");
@@ -315,12 +315,19 @@ public class CoinJoinClient
return coinJoinOutputs.IsSuperSetOf(expectedOutputTuples);
}
- private async Task SignTransactionAsync(IEnumerable<AliceClient> aliceClients, Transaction unsignedCoinJoinTransaction, RoundState roundState, CancellationToken cancellationToken)
+ private async Task SignTransactionAsync(IEnumerable<AliceClient> aliceClients, Transaction unsignedCoinJoinTransaction, DateTimeOffset signingEndTime, CancellationToken cancellationToken)
{
- foreach (var aliceClient in aliceClients)
+ var remainingTime = signingEndTime - DateTimeOffset.UtcNow;
+ var delays = remainingTime.SamplePoissonDelays(aliceClients.Count());
+
+ var tasks = Enumerable.Zip(aliceClients, delays,
+ async (aliceClient, delay) =>
{
await aliceClient.SignTransactionAsync(unsignedCoinJoinTransaction, KeyChain, cancellationToken).ConfigureAwait(false);
}
+ ).ToImmutableArray();
+
+ await Task.WhenAll(tasks).ConfigureAwait(false);
}
private async Task ReadyToSignAsync(IEnumerable<AliceClient> aliceClients, DateTimeOffset readyToSignEndTime, CancellationToken cancellationToken)

Add parallelization and timing to SignTransactionAsync