Speed up filter download.
MODIFY
WalletWasabi/Services/WasabiSynchronizer.cs
WalletWasabi/Services/WasabiSynchronizer.cs
@@ -272,9 +272,11 @@ namespace WalletWasabi.Services
foreach (var filter in filters)
{
- await BitcoinStore.IndexStore.AddNewFilterAsync(filter);
+ await BitcoinStore.IndexStore.AddNewFilterAsync(filter, toFile: false);
}
+ await BitcoinStore.IndexStore.ToFileAsync();
+
if (filters.Count() == 1)
{
Logger.LogInfo<WasabiSynchronizer>($"Downloaded filter for block {filters.First().BlockHeight}.");
@@ -288,7 +290,7 @@ namespace WalletWasabi.Services
{
// Reorg happened
// 1. Rollback index
- FilterModel reorgedFilter = await BitcoinStore.IndexStore.RemoveLastFilterAsync();
+ FilterModel reorgedFilter = await BitcoinStore.IndexStore.RemoveLastFilterAsync(toFile: true);
Logger.LogInfo<WasabiSynchronizer>($"REORG Invalid Block: {reorgedFilter.BlockHash}");
ignoreRequestInterval = true;

MODIFY
WalletWasabi/Stores/IndexStore.cs
WalletWasabi/Stores/IndexStore.cs
@@ -97,17 +97,17 @@ namespace WalletWasabi.Stores
}
}
- public async Task AddNewFilterAsync(FilterModel filter)
+ public async Task AddNewFilterAsync(FilterModel filter, bool toFile)
{
try
{
await Semaphore.WaitAsync();
Index.Add(filter);
- await IndexFileManager.WrapInMutexAsync(async () =>
+ if (toFile)
{
- await IndexFileManager.WriteAllLinesAsync(Index.Select(x => x.ToHeightlessLine()));
- });
+ await ToFileNoSemaphoreAsync();
+ }
}
finally
{
@@ -117,7 +117,7 @@ namespace WalletWasabi.Stores
NewFilter?.Invoke(this, filter);
}
- public async Task<FilterModel> RemoveLastFilterAsync()
+ public async Task<FilterModel> RemoveLastFilterAsync(bool toFile)
{
FilterModel filter = null;
try
@@ -126,10 +126,10 @@ namespace WalletWasabi.Stores
filter = Index.Last();
Index.RemoveLast();
- await IndexFileManager.WrapInMutexAsync(async () =>
+ if (toFile)
{
- await IndexFileManager.WriteAllLinesAsync(Index.Select(x => x.ToHeightlessLine()));
- });
+ await ToFileNoSemaphoreAsync();
+ }
}
finally
{
@@ -141,6 +141,28 @@ namespace WalletWasabi.Stores
return filter;
}
+ private async Task ToFileNoSemaphoreAsync()
+ {
+ await IndexFileManager.WrapInMutexAsync(async () =>
+ {
+ await IndexFileManager.WriteAllLinesAsync(Index.Select(x => x.ToHeightlessLine()));
+ });
+ }
+
+ public async Task ToFileAsync()
+ {
+ try
+ {
+ await Semaphore.WaitAsync();
+
+ await ToFileNoSemaphoreAsync();
+ }
+ finally
+ {
+ Semaphore.Release();
+ }
+ }
+
public async Task<FilterModel> GetBestKnownFilterAsync()
{
FilterModel ret = null;

Speed up filter download.