Forward the CancellationToken parameter to methods that take one
MODIFY
WalletWasabi/Bases/PeriodicRunner.cs
WalletWasabi/Bases/PeriodicRunner.cs
@@ -91,7 +91,7 @@ namespace WalletWasabi.Bases
}
else
{
- linkedTcs.TrySetCanceled(); // Ensure that the tcs.Task is cleaned up.
+ linkedTcs.TrySetCanceled(stoppingToken); // Ensure that the tcs.Task is cleaned up.
}
}
catch (TaskCanceledException ex)

MODIFY
WalletWasabi/BitcoinCore/CoreNode.cs
WalletWasabi/BitcoinCore/CoreNode.cs
@@ -56,7 +56,7 @@ namespace WalletWasabi.BitcoinCore
coreNode.Config = new CoreConfig();
if (File.Exists(configPath))
{
- var configString = await File.ReadAllTextAsync(configPath).ConfigureAwait(false);
+ var configString = await File.ReadAllTextAsync(configPath, cancel).ConfigureAwait(false);
coreNode.Config.AddOrUpdate(configString); // Bitcoin Core considers the last entry to be valid.
}
cancel.ThrowIfCancellationRequested();
@@ -177,7 +177,7 @@ namespace WalletWasabi.BitcoinCore
|| !File.Exists(configPath))
{
IoHelpers.EnsureContainingDirectoryExists(configPath);
- await File.WriteAllTextAsync(configPath, coreNode.Config.ToString()).ConfigureAwait(false);
+ await File.WriteAllTextAsync(configPath, coreNode.Config.ToString(), cancel).ConfigureAwait(false);
}
cancel.ThrowIfCancellationRequested();

MODIFY
WalletWasabi/BitcoinCore/P2pNode.cs
WalletWasabi/BitcoinCore/P2pNode.cs
@@ -60,7 +60,7 @@ namespace WalletWasabi.BitcoinCore
parameters.TemplateBehaviors.Add(new TrustedP2pBehavior(MempoolService));
Node = await Node.ConnectAsync(Network, EndPoint, parameters).ConfigureAwait(false);
- Node.VersionHandshake();
+ Node.VersionHandshake(cancel);
if (!Node.PeerVersion.Services.HasFlag(NodeServices.Network))
{

MODIFY
WalletWasabi/BitcoinCore/Processes/BitcoindRpcProcessBridge.cs
WalletWasabi/BitcoinCore/Processes/BitcoindRpcProcessBridge.cs
@@ -101,7 +101,7 @@ namespace WalletWasabi.BitcoinCore.Processes
}
// Wait a moment before the next check.
- await Task.Delay(100).ConfigureAwait(false);
+ await Task.Delay(100, cancel).ConfigureAwait(false);
}
}
catch (Exception)

MODIFY
WalletWasabi/Blockchain/Transactions/TransactionStore.cs
WalletWasabi/Blockchain/Transactions/TransactionStore.cs
@@ -42,7 +42,7 @@ namespace WalletWasabi.Blockchain.Transactions
TransactionsFileManager = new IoManager(transactionsFilePath);
cancel.ThrowIfCancellationRequested();
- using (await TransactionsFileAsyncLock.LockAsync().ConfigureAwait(false))
+ using (await TransactionsFileAsyncLock.LockAsync(cancel).ConfigureAwait(false))
{
IoHelpers.EnsureDirectoryExists(WorkFolderPath);
cancel.ThrowIfCancellationRequested();

MODIFY
WalletWasabi/Stores/IndexStore.cs
WalletWasabi/Stores/IndexStore.cs
@@ -76,9 +76,9 @@ namespace WalletWasabi.Stores
{
using (BenchmarkLogger.Measure())
{
- using (await IndexLock.LockAsync().ConfigureAwait(false))
- using (await MatureIndexAsyncLock.LockAsync().ConfigureAwait(false))
- using (await ImmatureIndexAsyncLock.LockAsync().ConfigureAwait(false))
+ using (await IndexLock.LockAsync(cancel).ConfigureAwait(false))
+ using (await MatureIndexAsyncLock.LockAsync(cancel).ConfigureAwait(false))
+ using (await ImmatureIndexAsyncLock.LockAsync(cancel).ConfigureAwait(false))
{
IoHelpers.EnsureDirectoryExists(WorkFolderPath);
@@ -95,7 +95,7 @@ namespace WalletWasabi.Stores
if (!MatureIndexFileManager.Exists())
{
- await MatureIndexFileManager.WriteAllLinesAsync(new[] { StartingFilter.ToLine() }).ConfigureAwait(false);
+ await MatureIndexFileManager.WriteAllLinesAsync(new[] { StartingFilter.ToLine() }, cancel).ConfigureAwait(false);
}
cancel.ThrowIfCancellationRequested();
@@ -179,7 +179,7 @@ namespace WalletWasabi.Stores
{
if (ImmatureIndexFileManager.Exists())
{
- foreach (var line in await ImmatureIndexFileManager.ReadAllLinesAsync().ConfigureAwait(false)) // We can load ImmatureIndexFileManager to the memory, no problem.
+ foreach (var line in await ImmatureIndexFileManager.ReadAllLinesAsync(cancel).ConfigureAwait(false)) // We can load ImmatureIndexFileManager to the memory, no problem.
{
ProcessLine(line, enqueue: true);
cancel.ThrowIfCancellationRequested();
@@ -318,7 +318,7 @@ namespace WalletWasabi.Stores
{
FilterModel? filter = null;
- using (await IndexLock.LockAsync().ConfigureAwait(false))
+ using (await IndexLock.LockAsync(cancel).ConfigureAwait(false))
{
filter = ImmatureFilters.Last();
ImmatureFilters.RemoveLast();
@@ -413,7 +413,7 @@ namespace WalletWasabi.Stores
var currentImmatureLines = ImmatureFilters.Select(x => x.ToLine()).ToArray(); // So we do not read on ImmatureFilters while removing them.
var matureLinesToAppend = currentImmatureLines.SkipLast(100);
var immatureLines = currentImmatureLines.TakeLast(100);
- var tasks = new Task[] { MatureIndexFileManager.AppendAllLinesAsync(matureLinesToAppend), ImmatureIndexFileManager.WriteAllLinesAsync(immatureLines) };
+ var tasks = new Task[] { MatureIndexFileManager.AppendAllLinesAsync(matureLinesToAppend, cancel), ImmatureIndexFileManager.WriteAllLinesAsync(immatureLines, cancel) };
while (ImmatureFilters.Count > 100)
{
ImmatureFilters.RemoveFirst();

MODIFY
WalletWasabi/Tor/Http/TorHttpClient.cs
WalletWasabi/Tor/Http/TorHttpClient.cs
@@ -252,7 +252,7 @@ namespace WalletWasabi.Tor.Http
}
else
{
- request.Content.Headers.ContentLength ??= (await request.Content.ReadAsStringAsync().ConfigureAwait(false)).Length;
+ request.Content.Headers.ContentLength ??= (await request.Content.ReadAsStringAsync(cancel).ConfigureAwait(false)).Length;
}
}
}

MODIFY
WalletWasabi/Tor/Socks5/TorSocks5Client.cs
WalletWasabi/Tor/Socks5/TorSocks5Client.cs
@@ -345,7 +345,7 @@ namespace WalletWasabi.Tor.Socks5
{
await AssertConnectedAsync(cancellationToken).ConfigureAwait(false);
- using (await AsyncLock.LockAsync().ConfigureAwait(false))
+ using (await AsyncLock.LockAsync(cancellationToken).ConfigureAwait(false))
{
var stream = TcpClient.GetStream();

MODIFY
WalletWasabi/Wallets/FileSystemBlockRepository.cs
WalletWasabi/Wallets/FileSystemBlockRepository.cs
@@ -210,7 +210,7 @@ namespace WalletWasabi.Wallets
{
// Try get the block.
Block? block = null;
- using (await BlockFolderLock.LockAsync().ConfigureAwait(false))
+ using (await BlockFolderLock.LockAsync(cancellationToken).ConfigureAwait(false))
{
var encoder = new HexEncoder();
var filePath = Path.Combine(BlocksFolderPath, hash.ToString());
@@ -249,11 +249,11 @@ namespace WalletWasabi.Wallets
var path = Path.Combine(BlocksFolderPath, block.GetHash().ToString());
if (!File.Exists(path))
{
- using (await BlockFolderLock.LockAsync().ConfigureAwait(false))
+ using (await BlockFolderLock.LockAsync(cancellationToken).ConfigureAwait(false))
{
if (!File.Exists(path))
{
- await File.WriteAllBytesAsync(path, block.ToBytes()).ConfigureAwait(false);
+ await File.WriteAllBytesAsync(path, block.ToBytes(), cancellationToken).ConfigureAwait(false);
}
}
}
@@ -268,7 +268,7 @@ namespace WalletWasabi.Wallets
{
try
{
- using (await BlockFolderLock.LockAsync().ConfigureAwait(false))
+ using (await BlockFolderLock.LockAsync(cancellationToken).ConfigureAwait(false))
{
var filePaths = Directory.EnumerateFiles(BlocksFolderPath);
var fileNames = filePaths.Select(Path.GetFileName);
@@ -293,7 +293,7 @@ namespace WalletWasabi.Wallets
/// <returns>The requested bitcoin block.</returns>
public async Task<int> CountAsync(CancellationToken cancellationToken)
{
- using (await BlockFolderLock.LockAsync().ConfigureAwait(false))
+ using (await BlockFolderLock.LockAsync(cancellationToken).ConfigureAwait(false))
{
return Directory.EnumerateFiles(BlocksFolderPath).Count();
}

MODIFY
WalletWasabi/Wallets/Wallet.cs
WalletWasabi/Wallets/Wallet.cs
@@ -159,7 +159,7 @@ namespace WalletWasabi.Wallets
while (!BitcoinStore.IsInitialized)
{
- await Task.Delay(100).ConfigureAwait(false);
+ await Task.Delay(100, cancel).ConfigureAwait(false);
cancel.ThrowIfCancellationRequested();
}
@@ -170,7 +170,7 @@ namespace WalletWasabi.Wallets
ChaumianClient.Start();
- using (await HandleFiltersLock.LockAsync().ConfigureAwait(false))
+ using (await HandleFiltersLock.LockAsync(cancel).ConfigureAwait(false))
{
await LoadWalletStateAsync(cancel).ConfigureAwait(false);
await LoadDummyMempoolAsync().ConfigureAwait(false);

MODIFY
WalletWasabi/WebClients/PayJoin/PayjoinClient.cs
WalletWasabi/WebClients/PayJoin/PayjoinClient.cs
@@ -88,7 +88,7 @@ namespace WalletWasabi.WebClients.PayJoin
if (!bpuResponse.IsSuccessStatusCode)
{
- var errorStr = await bpuResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ var errorStr = await bpuResponse.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
try
{
var error = JObject.Parse(errorStr);
@@ -104,7 +104,7 @@ namespace WalletWasabi.WebClients.PayJoin
}
}
- var hexOrBase64 = await bpuResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ var hexOrBase64 = await bpuResponse.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
var newPSBT = PSBT.Parse(hexOrBase64, originalTx.Network);
// Checking that the PSBT of the receiver is clean

Forward the CancellationToken parameter to methods that take one