put filter committment into IndexStore
MODIFY
WalletWasabi/Services/WasabiSynchronizer.cs
WalletWasabi/Services/WasabiSynchronizer.cs
@@ -250,9 +250,9 @@ namespace WalletWasabi.Services
if (response.FiltersResponseState == FiltersResponseState.NewFilters)
{
- var filters = response.Filters.ToArray(); // performance
+ var filters = response.Filters;
- await BitcoinStore.IndexStore.AddNewFiltersAsync(filters);
+ await BitcoinStore.IndexStore.AddNewFiltersAsync(filters, Cancel.Token);
if (filters.Count() == 1)
{
@@ -262,17 +262,15 @@ namespace WalletWasabi.Services
{
Logger.LogInfo<WasabiSynchronizer>($"Downloaded filters for blocks from {filters.First().BlockHeight} to {filters.Last().BlockHeight}.");
}
- _ = BitcoinStore.IndexStore.TryCommitToFileAsync(TimeSpan.FromSeconds(3), Cancel.Token);
}
else if (response.FiltersResponseState == FiltersResponseState.BestKnownHashNotFound)
{
// Reorg happened
// 1. Rollback index
- FilterModel reorgedFilter = await BitcoinStore.IndexStore.RemoveLastFilterAsync();
+ FilterModel reorgedFilter = await BitcoinStore.IndexStore.RemoveLastFilterAsync(Cancel.Token);
Logger.LogInfo<WasabiSynchronizer>($"REORG Invalid Block: {reorgedFilter.BlockHash}");
ignoreRequestInterval = true;
- _ = BitcoinStore.IndexStore.TryCommitToFileAsync(TimeSpan.FromSeconds(3), Cancel.Token);
}
else if (response.FiltersResponseState == FiltersResponseState.NoNewFilter)
{

MODIFY
WalletWasabi/Stores/IndexStore.cs
WalletWasabi/Stores/IndexStore.cs
@@ -104,7 +104,7 @@ namespace WalletWasabi.Stores
}
}
- public async Task AddNewFiltersAsync(params FilterModel[] filters)
+ public async Task AddNewFiltersAsync(IEnumerable<FilterModel> filters, CancellationToken cancel)
{
foreach (var filter in filters)
{
@@ -116,9 +116,11 @@ namespace WalletWasabi.Stores
NewFilter?.Invoke(this, filter); // Event always outside the lock.
}
+
+ _ = TryCommitToFileAsync(TimeSpan.FromSeconds(3), cancel);
}
- public async Task<FilterModel> RemoveLastFilterAsync()
+ public async Task<FilterModel> RemoveLastFilterAsync(CancellationToken cancel)
{
FilterModel filter = null;
@@ -131,6 +133,8 @@ namespace WalletWasabi.Stores
Reorged?.Invoke(this, filter);
+ _ = TryCommitToFileAsync(TimeSpan.FromSeconds(3), cancel);
+
return filter;
}
@@ -140,7 +144,7 @@ namespace WalletWasabi.Stores
/// It'll LogError the exceptions.
/// If cancelled, it'll LogTrace the exception.
/// </summary>
- public async Task TryCommitToFileAsync(TimeSpan throttle, CancellationToken cancel)
+ private async Task TryCommitToFileAsync(TimeSpan throttle, CancellationToken cancel)
{
try
{

put filter committment into IndexStore