Using TryGetValue
MODIFY
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
@@ -145,16 +145,16 @@ namespace WalletWasabi.Backend.Controllers
}
}
- var bannedElem = Coordinator.UtxoReferee.BannedUtxos.FirstOrDefault(x => x.Key == inputProof.Input);
- if (bannedElem.Key != default)
+ OutPoint outpoint = inputProof.Input.ToOutPoint();
+ if (Coordinator.UtxoReferee.BannedUtxos.TryGetValue(outpoint, out (int severity, DateTimeOffset timeOfBan) bannedElem))
{
int maxBan = (int)TimeSpan.FromDays(30).TotalMinutes;
- int banLeft = maxBan - (int)((DateTimeOffset.UtcNow - bannedElem.Value.timeOfBan).TotalMinutes);
+ int banLeft = maxBan - (int)((DateTimeOffset.UtcNow - bannedElem.timeOfBan).TotalMinutes);
if (banLeft > 0)
{
return BadRequest($"Input is banned from participation for {banLeft} minutes: {inputProof.Input.Index}:{inputProof.Input.TransactionId}.");
}
- await Coordinator.UtxoReferee.UnbanAsync(bannedElem.Key);
+ await Coordinator.UtxoReferee.UnbanAsync(outpoint);
}
GetTxOutResponse getTxOutResponse = await RpcClient.GetTxOutAsync(inputProof.Input.TransactionId, (int)inputProof.Input.Index, includeMempool: true);

MODIFY
WalletWasabi/Services/CcjCoordinator.cs
WalletWasabi/Services/CcjCoordinator.cs
@@ -129,18 +129,18 @@ namespace WalletWasabi.Services
{
OutPoint prevOut = input.PrevOut;
- var found = UtxoReferee.BannedUtxos.FirstOrDefault(x => x.Key == prevOut);
- if (found.Key == default) continue; // if coin is not banned
+ // if coin is not banned
+ if (!UtxoReferee.BannedUtxos.TryGetValue(prevOut, out (int severity, DateTimeOffset timeOfBan) found)) continue;
if (!AnyRunningRoundContainsInput(prevOut, out _))
{
- int newSeverity = found.Value.severity + 1;
+ int newSeverity = found.severity + 1;
await UtxoReferee.UnbanAsync(prevOut); // since it's not an UTXO anymore
if (RoundConfig.DosSeverity >= newSeverity)
{
var txCoins = tx.Outputs.AsIndexedOutputs().Select(x => x.ToCoin().Outpoint);
- await UtxoReferee.BanUtxosAsync(newSeverity, found.Value.timeOfBan, txCoins.ToArray());
+ await UtxoReferee.BanUtxosAsync(newSeverity, found.timeOfBan, txCoins.ToArray());
}
}
}

Using TryGetValue