Fix Alice delays
MODIFY
WalletWasabi/Extensions/TaskExtensions.cs
WalletWasabi/Extensions/TaskExtensions.cs
@@ -76,26 +76,5 @@ namespace System.Threading.Tasks
public static async Task WithAwaitCancellationAsync(this Task me, TimeSpan timeout)
=> await me.WithAwaitCancellationAsync(ThreadingHelpers.Cancelled, (int)timeout.TotalMilliseconds).ConfigureAwait(false);
-
- public static async Task<TResult> RunAsScheduledAsync<TResult>(this Task<TResult> task, DateTimeOffset when, CancellationToken cancellationToken)
- {
- await WaitUntilAsync(when, cancellationToken).ConfigureAwait(false);
- return await task.ConfigureAwait(false);
- }
-
- public static async Task RunAsScheduledAsync(this Task task, DateTimeOffset when, CancellationToken cancellationToken)
- {
- await WaitUntilAsync(when, cancellationToken).ConfigureAwait(false);
- await task.ConfigureAwait(false);
- }
-
- private static async Task WaitUntilAsync(DateTimeOffset when, CancellationToken cancellationToken)
- {
- var timeToWait = when - DateTimeOffset.UtcNow;
- if (timeToWait > TimeSpan.Zero)
- {
- await Task.Delay(timeToWait, cancellationToken).ConfigureAwait(false);
- }
- }
}
}

MODIFY
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
@@ -193,7 +193,16 @@ namespace WalletWasabi.WabiSabi.Client
}
}
- var aliceClients = smartCoins.Select(coin => RegisterInputAsync(coin, cancellationToken)).ToImmutableArray();
+ // Gets the list of scheduled dates/time in the remaining available time frame when each alice has to be registered.
+ var remainingTimeForRegistration = roundState.InputRegistrationEnd - DateTimeOffset.UtcNow;
+ var scheduledDates = remainingTimeForRegistration.SamplePoisson(smartCoins.Count());
+
+ // Creates scheduled tasks (tasks that wait until the specified date/time and then perform the real registration)
+ var aliceClients = smartCoins.Zip(scheduledDates, async (coin, date) =>
+ {
+ await Task.Delay(date - DateTimeOffset.UtcNow, cancellationToken).ConfigureAwait(false);
+ return await RegisterInputAsync(coin, cancellationToken).ConfigureAwait(false);
+ }).ToImmutableArray();
await Task.WhenAll(aliceClients).ConfigureAwait(false);
@@ -243,7 +252,11 @@ namespace WalletWasabi.WabiSabi.Client
var scheduledDates = transactionSigningTimeFrame.SamplePoisson(aliceClients.Count());
// Creates scheduled tasks (tasks that wait until the specified date/time and then perform the real registration)
- var signingRequests = aliceClients.Zip(scheduledDates, (alice, date) => SignTransactionAsync(alice, cancellationToken).RunAsScheduledAsync(date, cancellationToken)).ToImmutableArray();
+ var signingRequests = aliceClients.Zip(scheduledDates, async (alice, date) =>
+ {
+ await Task.Delay(date - DateTimeOffset.UtcNow, cancellationToken).ConfigureAwait(false);
+ return await SignTransactionAsync(alice, cancellationToken).ConfigureAwait(false);
+ }).ToImmutableArray();
await Task.WhenAll(signingRequests).ConfigureAwait(false);
}
@@ -256,6 +269,7 @@ namespace WalletWasabi.WabiSabi.Client
}
var readyRequests = aliceClients.Select(ReadyToSignTask);
+
await Task.WhenAll(readyRequests).ConfigureAwait(false);
}

Fix Alice delays