[WabiSabi] Reduce ReadyToSignAsync lock-contention
MODIFY
WalletWasabi/WabiSabi/Backend/Rounds/Arena.cs
WalletWasabi/WabiSabi/Backend/Rounds/Arena.cs
@@ -326,17 +326,22 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
public async Task ReadyToSignAsync(ReadyToSignRequestRequest request, CancellationToken cancellationToken)
{
+ Alice? alice;
+
using (await AsyncLock.LockAsync(cancellationToken).ConfigureAwait(false))
{
- if (Rounds.FirstOrDefault(r => r.Id == request.RoundId) is not Round round)
+ var round = Rounds.FirstOrDefault(r => r.Id == request.RoundId);
+ if (round is null)
{
throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.RoundNotFound, $"Round ({request.RoundId}) not found.");
}
- if (round.Alices.FirstOrDefault(a => a.Id == request.AliceId) is not Alice alice)
+ alice = round.Alices.FirstOrDefault(a => a.Id == request.AliceId);
+ if (alice is null)
{
throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.AliceNotFound, $"Round ({request.RoundId}): Alice id ({request.AliceId}).");
}
+ }
var coinJoinInputCommitmentData = new CoinJoinInputCommitmentData("CoinJoinCoordinatorIdentifier", request.RoundId);
if (!OwnershipProof.VerifyCoinJoinInputProof(request.OwnershipProof, alice.Coin.TxOut.ScriptPubKey, coinJoinInputCommitmentData))
@@ -346,7 +351,6 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
alice.ReadyToSign = true;
}
- }
public async Task RemoveInputAsync(InputsRemovalRequest request, CancellationToken cancellationToken)
{

[WabiSabi] Reduce ReadyToSignAsync lock-contention