Final refactors
MODIFY
WalletWasabi/WabiSabi/Backend/Banning/CoinVerifier.cs
WalletWasabi/WabiSabi/Backend/Banning/CoinVerifier.cs
@@ -5,6 +5,7 @@ using System.Runtime.CompilerServices;
using System.Threading;
using WalletWasabi.Logging;
using WalletWasabi.WabiSabi.Backend.Rounds.CoinJoinStorage;
+using WalletWasabi.WabiSabi.Backend.Statistics;
namespace WalletWasabi.WabiSabi.Backend.Banning;
@@ -75,13 +76,19 @@ public class CoinVerifier
public async IAsyncEnumerable<CoinVerifyInfo> VerifyCoinsAsync(IEnumerable<Coin> coinsToCheck, [EnumeratorCancellation] CancellationToken cancellationToken, string roundId = "")
{
+ var before = DateTimeOffset.UtcNow;
+
var coinDictionary = coinsToCheck.ToDictionary(c => c.ScriptPubKey);
- using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(90));
+
+ using CancellationTokenSource cancellationTokenSource = new(TimeSpan.FromSeconds(90));
using CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationTokenSource.Token, cancellationToken);
+
var lastChangeId = Whitelist.ChangeId;
Whitelist.RemoveAllExpired(WabiSabiConfig.ReleaseFromWhitelistAfter);
+
var scriptsToCheck = new HashSet<Script>();
var innocentsCounter = 0;
+
foreach (var coin in coinsToCheck)
{
if (CheckIfAlreadyVerified(coin))
@@ -94,6 +101,7 @@ public class CoinVerifier
scriptsToCheck.Add(coin.ScriptPubKey);
}
}
+
Logger.LogInfo($"{innocentsCounter} out of {coinsToCheck.Count()} utxo is already verified in Round({roundId}).");
await foreach (var response in CoinVerifierApiClient.VerifyScriptsAsync(scriptsToCheck, linkedCts.Token))
{
@@ -112,6 +120,9 @@ public class CoinVerifier
{
Whitelist.WriteToFile();
}
+
+ var duration = DateTimeOffset.UtcNow - before;
+ RequestTimeStatista.Instance.Add("verifier-period", duration);
}
private bool CheckForFlags(ApiResponseItem response)

MODIFY
WalletWasabi/WabiSabi/Backend/Banning/CoinVerifierApiClient.cs
WalletWasabi/WabiSabi/Backend/Banning/CoinVerifierApiClient.cs
@@ -40,9 +40,9 @@ public class CoinVerifierApiClient
throw new HttpRequestException($"The connection to the API is not safe. Expected https but was {HttpClient.BaseAddress.Scheme}.");
}
- var address = script.GetDestinationAddress(Network.Main);
+ var address = script.GetDestinationAddress(Network.Main); // API provider don't accept testnet/regtest addresses.
- using CancellationTokenSource timeoutTokenSource = new(TimeSpan.FromSeconds(40));
+ using CancellationTokenSource timeoutTokenSource = new(TimeSpan.FromSeconds(20));
using CancellationTokenSource linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutTokenSource.Token);
using var content = new HttpRequestMessage(HttpMethod.Get, $"{HttpClient.BaseAddress}{address}");
content.Headers.Authorization = new("Bearer", ApiToken);
@@ -82,6 +82,11 @@ public class CoinVerifierApiClient
response = await completedTask.ConfigureAwait(false);
}
+ catch (OperationCanceledException exc)
+ {
+ Logger.LogInfo("API response didn't arrive in time.", exc);
+ continue;
+ }
catch (Exception ex)
{
Logger.LogError(ex);

MODIFY
WalletWasabi/WabiSabi/Backend/Banning/Whitelist.cs
WalletWasabi/WabiSabi/Backend/Banning/Whitelist.cs
@@ -73,11 +73,6 @@ public class Whitelist
{
Logger.LogInfo($"{removedCounter} utxo was expired and removed from Whitelist.");
}
-
- if (removedCounter > 0)
- {
- Logger.LogInfo($"{removedCounter} utxo was expired and removed from Whitelist.");
- }
}
public bool TryGet(OutPoint utxo, [NotNullWhen(true)] out Innocent? innocent)

Final refactors