Remove buried AsyncLock and rename classes
MODIFY
WalletWasabi.Tests/UnitTests/IoTests.cs
WalletWasabi.Tests/UnitTests/IoTests.cs
+using Nito.AsyncEx;
using System;
using System.Collections.Generic;
using System.IO;
@@ -30,7 +31,7 @@ namespace WalletWasabi.Tests.UnitTests
// Single thread file operations.
- DigestableSafeAsyncLockIoManager ioman1 = new DigestableSafeAsyncLockIoManager(file1);
+ DigestableIoManager ioman1 = new DigestableIoManager(file1);
// Delete the file if Exist.
@@ -149,14 +150,17 @@ namespace WalletWasabi.Tests.UnitTests
// Check Mutex usage on simultaneous file writes.
- DigestableSafeAsyncLockIoManager ioman2 = new DigestableSafeAsyncLockIoManager(file2);
+ DigestableIoManager ioman2 = new DigestableIoManager(file2);
+
+ AsyncLock asyncLock1 = new AsyncLock();
+ AsyncLock asyncLock2 = new AsyncLock();
await Task.Run(async () =>
{
- using (await ioman1.AsyncLock.LockAsync())
+ using (await asyncLock1.LockAsync())
{
// Should not be a problem because they use different Mutexes.
- using (await ioman2.AsyncLock.LockAsync())
+ using (await asyncLock2.LockAsync())
{
await ioman1.WriteAllLinesAsync(lines);
await ioman2.WriteAllLinesAsync(lines);
@@ -193,7 +197,8 @@ namespace WalletWasabi.Tests.UnitTests
{
var file = Path.Combine(Common.GetWorkDir(), $"file.dat");
- DigestableSafeAsyncLockIoManager ioman = new DigestableSafeAsyncLockIoManager(file);
+ AsyncLock asyncLock = new AsyncLock();
+ DigestableIoManager ioman = new DigestableIoManager(file);
ioman.DeleteMe();
await ioman.WriteAllLinesAsync(Array.Empty<string>());
Assert.False(File.Exists(ioman.FilePath));
@@ -221,7 +226,8 @@ namespace WalletWasabi.Tests.UnitTests
{
list.Add(next);
}
- using (await ioman.AsyncLock.LockAsync())
+
+ using (await asyncLock.LockAsync())
{
var lines = (await ioman.ReadAllLinesAsync()).ToList();
lines.Add(next);

MODIFY
WalletWasabi/Blockchain/Transactions/TransactionStore.cs
WalletWasabi/Blockchain/Transactions/TransactionStore.cs
using NBitcoin;
+using Nito.AsyncEx;
using System;
using System.Collections.Generic;
using System.IO;
@@ -18,8 +19,8 @@ namespace WalletWasabi.Blockchain.Transactions
private Dictionary<uint256, SmartTransaction> Transactions { get; set; }
private object TransactionsLock { get; set; }
- private DigestableSafeAsyncLockIoManager TransactionsFileManager { get; set; }
-
+ private DigestableIoManager TransactionsFileManager { get; set; }
+ private AsyncLock TransactionsAsyncLock { get; set; } = new AsyncLock();
private List<ITxStoreOperation> Operations { get; } = new List<ITxStoreOperation>();
private object OperationsLock { get; } = new object();
@@ -35,9 +36,9 @@ namespace WalletWasabi.Blockchain.Transactions
var fileName = Path.Combine(WorkFolderPath, "Transactions.dat");
var transactionsFilePath = Path.Combine(WorkFolderPath, fileName);
- TransactionsFileManager = new DigestableSafeAsyncLockIoManager(transactionsFilePath, -1);
+ TransactionsFileManager = new DigestableIoManager(transactionsFilePath, -1);
- using (await TransactionsFileManager.AsyncLock.LockAsync().ConfigureAwait(false))
+ using (await TransactionsAsyncLock.LockAsync().ConfigureAwait(false))
{
IoHelpers.EnsureDirectoryExists(WorkFolderPath);
@@ -305,7 +306,7 @@ namespace WalletWasabi.Blockchain.Transactions
}
}
- using (await TransactionsFileManager.AsyncLock.LockAsync().ConfigureAwait(false))
+ using (await TransactionsAsyncLock.LockAsync().ConfigureAwait(false))
{
foreach (ITxStoreOperation op in operationsToExecute)
{

MODIFY
WalletWasabi/Io/DigestableSafeMutexIoManager.cs
WalletWasabi/Io/DigestableSafeMutexIoManager.cs
@@ -14,12 +14,12 @@ namespace WalletWasabi.Io
/// <summary>
/// Safely manager file operations.
/// </summary>
- public class DigestableSafeAsyncLockIoManager : SafeAsyncLockIoManager
+ public class DigestableIoManager : SafeIoManager
{
private const string DigestExtension = ".dig";
/// <param name="digestRandomIndex">Use the random index of the line to create digest faster. -1 is special value, it means the last character. If null then hash whole file.</param>
- public DigestableSafeAsyncLockIoManager(string filePath, int? digestRandomIndex = null) : base(filePath)
+ public DigestableIoManager(string filePath, int? digestRandomIndex = null) : base(filePath)
{
DigestRandomIndex = digestRandomIndex;

DELETE
WalletWasabi/Io/MutexIoManager.cs
-using Nito.AsyncEx;
-using WalletWasabi.Crypto;
-
-namespace WalletWasabi.Io
-{
- public abstract class AsyncLockIoManager : IoManager
- {
- public AsyncLockIoManager(string filePath) : base(filePath)
- {
- AsyncLock = new AsyncLock();
- }
-
- public AsyncLock AsyncLock { get; }
- }
-}

MODIFY
WalletWasabi/Io/SafeMutexIoManager.cs
WalletWasabi/Io/SafeMutexIoManager.cs
@@ -7,12 +7,12 @@ using WalletWasabi.Helpers;
namespace WalletWasabi.Io
{
- public abstract class SafeAsyncLockIoManager : AsyncLockIoManager
+ public abstract class SafeIoManager : IoManager
{
private const string OldExtension = ".old";
private const string NewExtension = ".new";
- public SafeAsyncLockIoManager(string filePath) : base(filePath)
+ public SafeIoManager(string filePath) : base(filePath)
{
OldFilePath = $"{FilePath}{OldExtension}";

MODIFY
WalletWasabi/Stores/IndexStore.cs
WalletWasabi/Stores/IndexStore.cs
@@ -38,8 +38,10 @@ namespace WalletWasabi.Stores
private string WorkFolderPath { get; set; }
private Network Network { get; }
- private DigestableSafeAsyncLockIoManager MatureIndexFileManager { get; set; }
- private DigestableSafeAsyncLockIoManager ImmatureIndexFileManager { get; set; }
+ private DigestableIoManager MatureIndexFileManager { get; set; }
+ private DigestableIoManager ImmatureIndexFileManager { get; set; }
+ private AsyncLock MatureIndexAsyncLock { get; set; } = new AsyncLock();
+ private AsyncLock ImmatureIndexAsyncLock { get; set; } = new AsyncLock();
public SmartHeaderChain SmartHeaderChain { get; }
private FilterModel StartingFilter { get; set; }
@@ -52,9 +54,9 @@ namespace WalletWasabi.Stores
using (BenchmarkLogger.Measure())
{
var indexFilePath = Path.Combine(WorkFolderPath, "MatureIndex.dat");
- MatureIndexFileManager = new DigestableSafeAsyncLockIoManager(indexFilePath, digestRandomIndex: -1);
+ MatureIndexFileManager = new DigestableIoManager(indexFilePath, digestRandomIndex: -1);
var immatureIndexFilePath = Path.Combine(WorkFolderPath, "ImmatureIndex.dat");
- ImmatureIndexFileManager = new DigestableSafeAsyncLockIoManager(immatureIndexFilePath, digestRandomIndex: -1);
+ ImmatureIndexFileManager = new DigestableIoManager(immatureIndexFilePath, digestRandomIndex: -1);
StartingFilter = StartingFilters.GetStartingFilter(Network);
StartingHeight = StartingFilter.Header.Height;
@@ -64,8 +66,8 @@ namespace WalletWasabi.Stores
IndexLock = new AsyncLock();
using (await IndexLock.LockAsync().ConfigureAwait(false))
- using (await MatureIndexFileManager.AsyncLock.LockAsync().ConfigureAwait(false))
- using (await ImmatureIndexFileManager.AsyncLock.LockAsync().ConfigureAwait(false))
+ using (await MatureIndexAsyncLock.LockAsync().ConfigureAwait(false))
+ using (await ImmatureIndexAsyncLock.LockAsync().ConfigureAwait(false))
{
IoHelpers.EnsureDirectoryExists(WorkFolderPath);
@@ -100,7 +102,7 @@ namespace WalletWasabi.Stores
}
}
- private async Task DeleteIfDeprecatedAsync(DigestableSafeAsyncLockIoManager ioManager)
+ private async Task DeleteIfDeprecatedAsync(DigestableIoManager ioManager)
{
string firstLine;
using (var content = ioManager.OpenText())
@@ -332,8 +334,8 @@ namespace WalletWasabi.Stores
{
Logger.LogCritical($"Deleting all filters and crashing the software...");
- using (await MatureIndexFileManager.AsyncLock.LockAsync(cancel).ConfigureAwait(false))
- using (await ImmatureIndexFileManager.AsyncLock.LockAsync(cancel).ConfigureAwait(false))
+ using (await MatureIndexAsyncLock.LockAsync(cancel).ConfigureAwait(false))
+ using (await ImmatureIndexAsyncLock.LockAsync(cancel).ConfigureAwait(false))
{
ImmatureIndexFileManager.DeleteMe();
MatureIndexFileManager.DeleteMe();
@@ -384,8 +386,8 @@ namespace WalletWasabi.Stores
Interlocked.Exchange(ref _throttleId, 0); // So to notify the currently throttled threads that they do not have to run.
}
- using (await MatureIndexFileManager.AsyncLock.LockAsync(cancel).ConfigureAwait(false))
- using (await ImmatureIndexFileManager.AsyncLock.LockAsync(cancel).ConfigureAwait(false))
+ using (await MatureIndexAsyncLock.LockAsync(cancel).ConfigureAwait(false))
+ using (await ImmatureIndexAsyncLock.LockAsync(cancel).ConfigureAwait(false))
using (await IndexLock.LockAsync(cancel).ConfigureAwait(false))
{
// Do not feed the cancellationToken here I always want this to finish running for safety.
@@ -412,7 +414,7 @@ namespace WalletWasabi.Stores
public async Task ForeachFiltersAsync(Func<FilterModel, Task> todo, Height fromHeight, CancellationToken cancel = default)
{
- using (await MatureIndexFileManager.AsyncLock.LockAsync(cancel).ConfigureAwait(false))
+ using (await MatureIndexAsyncLock.LockAsync(cancel).ConfigureAwait(false))
using (await IndexLock.LockAsync(cancel).ConfigureAwait(false))
{
var firstImmatureHeight = ImmatureFilters.FirstOrDefault()?.Header?.Height;

Remove buried AsyncLock and rename classes