Reduce ReissuanceAsync lock-contention
MODIFY
WalletWasabi/WabiSabi/Backend/Rounds/Arena.cs
WalletWasabi/WabiSabi/Backend/Rounds/Arena.cs
@@ -498,9 +498,11 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
public async Task<ReissueCredentialResponse> ReissuanceAsync(ReissueCredentialRequest request, CancellationToken cancellationToken)
{
+ Round? round;
using (await AsyncLock.LockAsync(cancellationToken).ConfigureAwait(false))
{
- if (Rounds.FirstOrDefault(x => x.Id == request.RoundId) is not Round round)
+ round = Rounds.FirstOrDefault(x => x.Id == request.RoundId);
+ if (round is null)
{
throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.RoundNotFound, $"Round ({request.RoundId}) not found.");
}
@@ -509,6 +511,7 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
{
throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.WrongPhase, $"Round ({round.Id}): Wrong phase ({round.Phase}).");
}
+ }
if (request.RealAmountCredentialRequests.Delta != 0)
{
@@ -525,10 +528,15 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.WrongNumberOfCreds, $"Round ({round.Id}): Incorrect requested number of weight credentials.");
}
- var commitRealAmountCredentialResponse = round.AmountCredentialIssuer.PrepareResponse(request.RealAmountCredentialRequests);
- var commitRealVsizeCredentialResponse = round.VsizeCredentialIssuer.PrepareResponse(request.RealVsizeCredentialRequests);
- var commitZeroAmountCredentialResponse = round.AmountCredentialIssuer.PrepareResponse(request.ZeroAmountCredentialRequests);
- var commitZeroVsizeCredentialResponse = round.VsizeCredentialIssuer.PrepareResponse(request.ZeroVsizeCredentialsRequests);
+ var realAmountTask = Task.Run(() => round.AmountCredentialIssuer.PrepareResponse(request.RealAmountCredentialRequests), cancellationToken);
+ var realVsizeTask = Task.Run(() => round.VsizeCredentialIssuer.PrepareResponse(request.RealVsizeCredentialRequests), cancellationToken);
+ var zeroAmountTask = Task.Run(() => round.AmountCredentialIssuer.PrepareResponse(request.ZeroAmountCredentialRequests), cancellationToken);
+ var zeroVsizeTask = Task.Run(() => round.VsizeCredentialIssuer.PrepareResponse(request.ZeroVsizeCredentialsRequests), cancellationToken);
+
+ var commitRealAmountCredentialResponse = await realAmountTask.ConfigureAwait(false);
+ var commitRealVsizeCredentialResponse = await realVsizeTask.ConfigureAwait(false);
+ var commitZeroAmountCredentialResponse = await zeroAmountTask.ConfigureAwait(false);
+ var commitZeroVsizeCredentialResponse = await zeroVsizeTask.ConfigureAwait(false);
return new(
commitRealAmountCredentialResponse.Commit(),
@@ -537,7 +545,6 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
commitZeroVsizeCredentialResponse.Commit()
);
}
- }
public override void Dispose()
{

Reduce ReissuanceAsync lock-contention