Move FilterProcessor inside the synchronizer
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -173,7 +173,6 @@ namespace WalletWasabi.Gui
}
HostedServices.Register<P2pNetwork>(new P2pNetwork(Network, Config.GetBitcoinP2pEndPoint(), Config.UseTor ? Config.TorSocks5EndPoint : null, Path.Combine(DataDir, "BitcoinP2pNetwork"), BitcoinStore), "Bitcoin P2P Network");
- HostedServices.Register<FilterProcessor>(new FilterProcessor(Synchronizer, BitcoinStore), "Filter Processor");
try
{

MODIFY
WalletWasabi/Blockchain/BlockFilters/FilterProcessor.cs
WalletWasabi/Blockchain/BlockFilters/FilterProcessor.cs
@@ -15,46 +15,17 @@ using WalletWasabi.Stores;
namespace WalletWasabi.Blockchain.BlockFilters
{
- public class FilterProcessor : IHostedService
+ public class FilterProcessor
{
- public FilterProcessor(WasabiSynchronizer synchronizer, BitcoinStore bitcoinStore)
+ public FilterProcessor(BitcoinStore bitcoinStore)
{
- Synchronizer = synchronizer;
BitcoinStore = bitcoinStore;
}
- public WasabiSynchronizer Synchronizer { get; }
public BitcoinStore BitcoinStore { get; }
public AsyncLock AsyncLock { get; } = new();
- private AbandonedTasks ProcessingEvents { get; } = new();
- public Task StartAsync(CancellationToken cancellationToken)
- {
- Synchronizer.ResponseArrived += Synchronizer_ResponseArrivedAsync;
-
- return Task.CompletedTask;
- }
-
- public async Task StopAsync(CancellationToken cancellationToken)
- {
- Synchronizer.ResponseArrived -= Synchronizer_ResponseArrivedAsync;
-
- await ProcessingEvents.WhenAllAsync().ConfigureAwait(false);
- }
-
- private async void Synchronizer_ResponseArrivedAsync(object? sender, SynchronizeResponse response)
- {
- using (RunningTasks.RememberWith(ProcessingEvents))
- {
- uint serverBestHeight = (uint)response.BestHeight;
- var filters = response.Filters;
- FiltersResponseState filtersResponseState = response.FiltersResponseState;
-
- await ProcessAsync(serverBestHeight, filtersResponseState, filters).ConfigureAwait(false);
- }
- }
-
- private async Task ProcessAsync(uint serverBestHeight, FiltersResponseState filtersResponseState, IEnumerable<FilterModel> filters)
+ public async Task ProcessAsync(uint serverBestHeight, FiltersResponseState filtersResponseState, IEnumerable<FilterModel> filters)
{
try
{

MODIFY
WalletWasabi/Services/WasabiSynchronizer.cs
WalletWasabi/Services/WasabiSynchronizer.cs
@@ -9,6 +9,7 @@ using WalletWasabi.Backend.Models;
using WalletWasabi.Backend.Models.Responses;
using WalletWasabi.Bases;
using WalletWasabi.Blockchain.Analysis.FeesEstimation;
+using WalletWasabi.Blockchain.BlockFilters;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
using WalletWasabi.Models;
@@ -47,6 +48,7 @@ namespace WalletWasabi.Services
LastResponse = null;
_running = StateNotStarted;
BitcoinStore = bitcoinStore;
+ FilterProcessor = new FilterProcessor(BitcoinStore);
HttpClientFactory = httpClientFactory;
WasabiClient = httpClientFactory.SharedWasabiClient;
@@ -101,6 +103,7 @@ namespace WalletWasabi.Services
public TimeSpan MaxRequestIntervalForMixing { get; set; }
public BitcoinStore BitcoinStore { get; }
+ public FilterProcessor FilterProcessor { get; }
public bool IsRunning => Interlocked.Read(ref _running) == StateRunning;
@@ -232,6 +235,8 @@ namespace WalletWasabi.Services
UsdExchangeRate = exchangeRate.Rate;
}
+ await FilterProcessor.ProcessAsync((uint)response.BestHeight, response.FiltersResponseState, response.Filters).ConfigureAwait(false);
+
LastResponse = response;
ResponseArrived?.Invoke(this, response);
if (response.AllFeeEstimate is { } allFeeEstimate)

Move FilterProcessor inside the synchronizer