Optimize mempool cleanup
MODIFY
WalletWasabi/Services/MemPoolService.cs
WalletWasabi/Services/MemPoolService.cs
@@ -39,6 +39,8 @@ namespace WalletWasabi.Services
// This function is designed to prevent forever growing mempool.
try
{
+ if (!TransactionHashes.Any()) return true; // There's nothing to cleanup.
+
Logger.LogInfo<MemPoolService>("Start cleaning out mempool...");
using (var client = new WasabiClient(destAction, torSocks))
{
@@ -78,6 +80,8 @@ namespace WalletWasabi.Services
// This function is designed to prevent forever growing mempool.
try
{
+ if (!TransactionHashes.Any()) return true; // There's nothing to cleanup.
+
var delay = TimeSpan.FromMinutes(1);
if (nodes?.ConnectedNodes is null) return false;
while (nodes.ConnectedNodes.Count != nodes.MaximumNodeConnection && nodes.ConnectedNodes.All(x => x.IsConnected))

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -224,14 +224,15 @@ namespace WalletWasabi.Services
}
NewFilterProcessed?.Invoke(this, filterModel);
- // If Synchronizer is null then go try cleanup mempool (it won't succeed.)
- // If requests are blocked, delay mempool cleanup, because coinjoin answers are always priority.
- while (Synchronizer != null && Synchronizer.AreRequestsBlocked())
+ do
{
await Task.Delay(100);
- }
+ if (Synchronizer is null) return;
+ // Make sure fully synced and this filter is the lastest filter.
+ if (Synchronizer.GetFiltersLeft() != 0 || Synchronizer.BestKnownFilter.BlockHash != filterModel.BlockHash) return;
+ } while (Synchronizer.AreRequestsBlocked()); // If requests are blocked, delay mempool cleanup, because coinjoin answers are always priority.
- await TryCleanupMempoolAsync();
+ await MemPool?.TryPerformMempoolCleanupAsync(Synchronizer.WasabiClient.TorClient.DestinationUriAction, Synchronizer.WasabiClient.TorClient.TorSocks5EndPoint);
}
catch (Exception ex)
{
@@ -239,15 +240,6 @@ namespace WalletWasabi.Services
}
}
- private async Task TryCleanupMempoolAsync()
- {
- // Try perform mempool cleanup based on connected nodes' mempools.
- if (Synchronizer != null && Synchronizer.GetFiltersLeft() == 0)
- {
- await MemPool?.TryPerformMempoolCleanupAsync(Synchronizer.WasabiClient.TorClient.DestinationUriAction, Synchronizer.WasabiClient.TorClient.TorSocks5EndPoint);
- }
- }
-
public async Task InitializeAsync(CancellationToken cancel)
{
if (!Synchronizer.IsRunning)

Optimize mempool cleanup