Fix tests and remove try-finally.
MODIFY
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
@@ -12,6 +12,8 @@ using WalletWasabi.Tests.Helpers;
using WalletWasabi.Tests.XunitConfiguration;
using WalletWasabi.Tor;
using WalletWasabi.Tor.Http;
+using WalletWasabi.Tor.Socks5;
+using WalletWasabi.Tor.Socks5.Pool;
using WalletWasabi.WebClients.Wasabi;
using Xunit;
@@ -23,14 +25,19 @@ namespace WalletWasabi.Tests.IntegrationTests
public LiveServerTests(LiveServerTestsFixture liveServerTestsFixture)
{
LiveServerTestsFixture = liveServerTestsFixture;
+
+ TorHttpPool = new TorHttpPool(new TorTcpConnectionFactory(Common.TorSocks5Endpoint));
+ TorManager = new TorProcessManager(Common.TorSettings, Common.TorSocks5Endpoint);
}
+ private TorProcessManager TorManager { get; }
+ private TorHttpPool TorHttpPool { get; }
private LiveServerTestsFixture LiveServerTestsFixture { get; }
public async Task InitializeAsync()
{
- var torManager = new TorProcessManager(Common.TorSettings, Common.TorSocks5Endpoint);
- bool started = await torManager.StartAsync(ensureRunning: true);
+
+ bool started = await TorManager.StartAsync(ensureRunning: true);
Assert.True(started, "Tor failed to start.");
}
@@ -48,7 +55,7 @@ namespace WalletWasabi.Tests.IntegrationTests
{
Network network = (networkType == NetworkType.Mainnet) ? Network.Main : Network.TestNet;
- using var torHttpClient = MakeTorHttpClient(networkType);
+ TorHttpClient torHttpClient = MakeTorHttpClient(networkType);
var client = new WasabiClient(torHttpClient);
var filterModel = StartingFilters.GetStartingFilter(network);
@@ -64,7 +71,7 @@ namespace WalletWasabi.Tests.IntegrationTests
[InlineData(NetworkType.Testnet)]
public async Task GetAllRoundStatesAsync(NetworkType networkType)
{
- using var torHttpClient = MakeTorHttpClient(networkType);
+ TorHttpClient torHttpClient = MakeTorHttpClient(networkType);
var client = new SatoshiClient(torHttpClient);
var states = await client.GetAllRoundStatesAsync();
Assert.True(states.NotNullAndNotEmpty());
@@ -76,7 +83,7 @@ namespace WalletWasabi.Tests.IntegrationTests
[InlineData(NetworkType.Testnet)]
public async Task GetTransactionsAsync(NetworkType networkType)
{
- using var torHttpClient = MakeTorHttpClient(networkType);
+ TorHttpClient torHttpClient = MakeTorHttpClient(networkType);
var client = new WasabiClient(torHttpClient);
var randomTxIds = Enumerable.Range(0, 20).Select(_ => RandomUtils.GetUInt256());
@@ -102,7 +109,7 @@ namespace WalletWasabi.Tests.IntegrationTests
[InlineData(NetworkType.Testnet)]
public async Task GetExchangeRateAsync(NetworkType networkType) // xunit wtf: If this function is called GetExchangeRatesAsync, it'll stuck on 1 CPU VMs (Manjuro, Fedora)
{
- using var torHttpClient = MakeTorHttpClient(networkType);
+ TorHttpClient torHttpClient = MakeTorHttpClient(networkType);
var client = new WasabiClient(torHttpClient);
var exchangeRates = await client.GetExchangeRatesAsync();
@@ -119,7 +126,7 @@ namespace WalletWasabi.Tests.IntegrationTests
[InlineData(NetworkType.Testnet)]
public async Task GetVersionsTestsAsync(NetworkType networkType)
{
- using var torHttpClient = MakeTorHttpClient(networkType);
+ TorHttpClient torHttpClient = MakeTorHttpClient(networkType);
var client = new WasabiClient(torHttpClient);
var versions = await client.GetVersionsAsync(CancellationToken.None);
@@ -134,7 +141,7 @@ namespace WalletWasabi.Tests.IntegrationTests
[InlineData(NetworkType.Testnet)]
public async Task CheckUpdatesTestsAsync(NetworkType networkType)
{
- using var torHttpClient = MakeTorHttpClient(networkType);
+ TorHttpClient torHttpClient = MakeTorHttpClient(networkType);
var client = new WasabiClient(torHttpClient);
var updateStatus = await client.CheckUpdatesAsync(CancellationToken.None);
@@ -160,7 +167,7 @@ namespace WalletWasabi.Tests.IntegrationTests
[InlineData(NetworkType.Testnet)]
public async Task GetLegalDocumentsTestsAsync(NetworkType networkType)
{
- using var torHttpClient = MakeTorHttpClient(networkType);
+ TorHttpClient torHttpClient = MakeTorHttpClient(networkType);
var client = new WasabiClient(torHttpClient);
var content = await client.GetLegalDocumentsAsync(CancellationToken.None);
@@ -176,7 +183,7 @@ namespace WalletWasabi.Tests.IntegrationTests
private TorHttpClient MakeTorHttpClient(NetworkType networkType)
{
Uri baseUri = LiveServerTestsFixture.UriMappings[networkType];
- return new TorHttpClient(baseUri, Common.TorSocks5Endpoint);
+ return new TorHttpClient(baseUri, TorHttpPool);
}
}
}

MODIFY
WalletWasabi.Tests/IntegrationTests/TorTests.cs
WalletWasabi.Tests/IntegrationTests/TorTests.cs
@@ -8,16 +8,25 @@ using WalletWasabi.Tests.Helpers;
using WalletWasabi.Tor;
using WalletWasabi.Tor.Http;
using WalletWasabi.Tor.Socks5;
+using WalletWasabi.Tor.Socks5.Pool;
using Xunit;
namespace WalletWasabi.Tests.IntegrationTests
{
public class TorTests : IAsyncLifetime
{
+ public TorTests()
+ {
+ TorHttpPool = new TorHttpPool(new TorTcpConnectionFactory(Common.TorSocks5Endpoint));
+ TorManager = new(Common.TorSettings, Common.TorSocks5Endpoint);
+ }
+
+ private TorHttpPool TorHttpPool { get; }
+ private TorProcessManager TorManager { get; }
+
public async Task InitializeAsync()
{
- var torManager = new TorProcessManager(Common.TorSettings, Common.TorSocks5Endpoint);
- bool started = await torManager.StartAsync(ensureRunning: true);
+ bool started = await TorManager.StartAsync(ensureRunning: true);
Assert.True(started, "Tor failed to start.");
}
@@ -29,7 +38,7 @@ namespace WalletWasabi.Tests.IntegrationTests
[Fact]
public async Task CanDoRequestManyDifferentAsync()
{
- using var client = new TorHttpClient(new Uri("http://api.qbit.ninja"), Common.TorSocks5Endpoint);
+ TorHttpClient client = MakeTorHttpClient(new Uri("http://api.qbit.ninja"));
await QBitTestAsync(client, 10, alterRequests: true);
}
@@ -38,7 +47,7 @@ namespace WalletWasabi.Tests.IntegrationTests
{
using CancellationTokenSource ctsTimeout = new(TimeSpan.FromMinutes(2));
- using var client = MakeTorHttpClient(new Uri("http://anglesharp.azurewebsites.net/"));
+ TorHttpClient client = MakeTorHttpClient(new Uri("http://anglesharp.azurewebsites.net/"));
var response = await client.SendAsync(HttpMethod.Get, "Chunked", null, ctsTimeout.Token);
var content = await response.Content.ReadAsStringAsync(ctsTimeout.Token);
Assert.Contains("Chunked transfer encoding test", content);
@@ -51,7 +60,7 @@ namespace WalletWasabi.Tests.IntegrationTests
{
using CancellationTokenSource ctsTimeout = new(TimeSpan.FromMinutes(2));
- using var client = MakeTorHttpClient(new Uri("https://postman-echo.com"));
+ TorHttpClient client = MakeTorHttpClient(new Uri("https://postman-echo.com"));
using HttpContent content = new StringContent("This is expected to be sent back as part of response body.");
HttpResponseMessage message = await client.SendAsync(HttpMethod.Post, "post", content, ctsTimeout.Token);
@@ -70,7 +79,7 @@ namespace WalletWasabi.Tests.IntegrationTests
IPAddress? torIp;
// 1. Get real IP
- using (var httpClient = new HttpClient())
+ using (HttpClient httpClient = new())
{
var content = await (await httpClient.GetAsync(requestUri)).Content.ReadAsStringAsync(ctsTimeout.Token);
var gotIp = IPAddress.TryParse(content.Replace("\n", ""), out realIp);
@@ -78,9 +87,9 @@ namespace WalletWasabi.Tests.IntegrationTests
}
// 2. Get Tor IP
- using (var client = MakeTorHttpClient(new Uri(requestUri)))
{
- var content = await (await client.SendAsync(HttpMethod.Get, "", null, ctsTimeout.Token)).Content.ReadAsStringAsync(ctsTimeout.Token);
+ TorHttpClient torClient = MakeTorHttpClient(new Uri(requestUri));
+ var content = await (await torClient.SendAsync(HttpMethod.Get, "", null, ctsTimeout.Token)).Content.ReadAsStringAsync(ctsTimeout.Token);
var gotIp = IPAddress.TryParse(content.Replace("\n", ""), out torIp);
Assert.True(gotIp);
}
@@ -93,7 +102,7 @@ namespace WalletWasabi.Tests.IntegrationTests
{
using CancellationTokenSource ctsTimeout = new(TimeSpan.FromMinutes(2));
- using var client = MakeTorHttpClient(new Uri("https://postman-echo.com"));
+ TorHttpClient client = MakeTorHttpClient(new Uri("https://postman-echo.com"));
using HttpResponseMessage httpResponseMessage = await client.SendAsync(HttpMethod.Get, "get?foo1=bar1&foo2=bar2", null, ctsTimeout.Token);
var content = await httpResponseMessage.Content.ReadAsStringAsync(ctsTimeout.Token);
@@ -105,7 +114,7 @@ namespace WalletWasabi.Tests.IntegrationTests
{
using CancellationTokenSource ctsTimeout = new(TimeSpan.FromMinutes(2));
- using var client = MakeTorHttpClient(new Uri("http://172.217.6.142"));
+ TorHttpClient client = MakeTorHttpClient(new Uri("http://172.217.6.142"));
HttpResponseMessage httpResponseMessage = await client.SendAsync(HttpMethod.Get, relativeUri: "", content: null, ctsTimeout.Token);
string content = await httpResponseMessage.Content.ReadAsStringAsync(ctsTimeout.Token);
@@ -117,7 +126,7 @@ namespace WalletWasabi.Tests.IntegrationTests
{
using CancellationTokenSource ctsTimeout = new(TimeSpan.FromMinutes(2));
- using var client = MakeTorHttpClient(new Uri("http://api.qbit.ninja"));
+ TorHttpClient client = MakeTorHttpClient(new Uri("http://api.qbit.ninja"));
await (await client.SendAsync(HttpMethod.Get, "/transactions/38d4cfeb57d6685753b7a3b3534c3cb576c34ca7344cd4582f9613ebf0c2b02a?format=json&headeronly=true", null, ctsTimeout.Token)).Content.ReadAsStringAsync(ctsTimeout.Token);
await (await client.SendAsync(HttpMethod.Get, "/balances/15sYbVpRh6dyWycZMwPdxJWD4xbfxReeHe?unspentonly=true", null, ctsTimeout.Token)).Content.ReadAsStringAsync(ctsTimeout.Token);
await (await client.SendAsync(HttpMethod.Get, "balances/akEBcY5k1dn2yeEdFnTMwdhVbHxtgHb6GGi?from=tip&until=336000", null, ctsTimeout.Token)).Content.ReadAsStringAsync(ctsTimeout.Token);
@@ -128,7 +137,7 @@ namespace WalletWasabi.Tests.IntegrationTests
{
using CancellationTokenSource ctsTimeout = new(TimeSpan.FromMinutes(2));
- using var client = MakeTorHttpClient(new Uri("http://expyuzz4wqqyqhjn.onion/"));
+ TorHttpClient client = MakeTorHttpClient(new Uri("http://expyuzz4wqqyqhjn.onion/"));
HttpResponseMessage response = await client.SendAsync(HttpMethod.Get, relativeUri: "", null, ctsTimeout.Token);
var content = await response.Content.ReadAsStringAsync(ctsTimeout.Token);
@@ -142,7 +151,7 @@ namespace WalletWasabi.Tests.IntegrationTests
{
using CancellationTokenSource ctsTimeout = new(TimeSpan.FromMinutes(2));
- using var client = MakeTorHttpClient(new Uri("http://www.dds6qkxpwdeubwucdiaord2xgbbeyds25rbsgr73tbfpqpt4a6vjwsyd.onion"));
+ TorHttpClient client = MakeTorHttpClient(new Uri("http://www.dds6qkxpwdeubwucdiaord2xgbbeyds25rbsgr73tbfpqpt4a6vjwsyd.onion"));
HttpResponseMessage response = await client.SendAsync(HttpMethod.Get, "", null, ctsTimeout.Token);
var content = await response.Content.ReadAsStringAsync();
@@ -156,9 +165,9 @@ namespace WalletWasabi.Tests.IntegrationTests
{
using CancellationTokenSource ctsTimeout = new(TimeSpan.FromMinutes(2));
- using var c1 = MakeTorHttpClient(new Uri("http://api.ipify.org"));
- using var c2 = MakeTorHttpClient(new Uri("http://api.ipify.org"));
- using var c3 = MakeTorHttpClient(new Uri("http://api.ipify.org"));
+ TorHttpClient c1 = MakeTorHttpClient(new Uri("http://api.ipify.org"));
+ TorHttpClient c2 = MakeTorHttpClient(new Uri("http://api.ipify.org"));
+ TorHttpClient c3 = MakeTorHttpClient(new Uri("http://api.ipify.org"));
Task<HttpResponseMessage> t1 = c1.SendAsync(HttpMethod.Get, "", null, ctsTimeout.Token);
Task<HttpResponseMessage> t2 = c2.SendAsync(HttpMethod.Get, "", null, ctsTimeout.Token);
Task<HttpResponseMessage> t3 = c3.SendAsync(HttpMethod.Get, "", null, ctsTimeout.Token);
@@ -178,9 +187,9 @@ namespace WalletWasabi.Tests.IntegrationTests
{
using CancellationTokenSource ctsTimeout = new(TimeSpan.FromMinutes(2));
- using var c1 = MakeTorHttpClient(new Uri("http://api.ipify.org"), isolateStream: true);
- using var c2 = MakeTorHttpClient(new Uri("http://api.ipify.org"), isolateStream: true);
- using var c3 = MakeTorHttpClient(new Uri("http://api.ipify.org"), isolateStream: true);
+ TorHttpClient c1 = MakeTorHttpClient(new Uri("http://api.ipify.org"), isolateStream: true);
+ TorHttpClient c2 = MakeTorHttpClient(new Uri("http://api.ipify.org"), isolateStream: true);
+ TorHttpClient c3 = MakeTorHttpClient(new Uri("http://api.ipify.org"), isolateStream: true);
Task<HttpResponseMessage> t1 = c1.SendAsync(HttpMethod.Get, "", null, ctsTimeout.Token);
Task<HttpResponseMessage> t2 = c2.SendAsync(HttpMethod.Get, "", null, ctsTimeout.Token);
Task<HttpResponseMessage> t3 = c3.SendAsync(HttpMethod.Get, "", null, ctsTimeout.Token);
@@ -198,14 +207,14 @@ namespace WalletWasabi.Tests.IntegrationTests
[Fact]
public async Task TorRunningAsync()
{
- using TorSocks5Client client1 = new(new IPEndPoint(IPAddress.Loopback, 9050));
+ TorTcpConnectionFactory client1 = new(new IPEndPoint(IPAddress.Loopback, 9050));
Assert.True(await client1.IsTorRunningAsync());
- using TorSocks5Client client2 = new(new IPEndPoint(IPAddress.Loopback, 9054));
+ TorTcpConnectionFactory client2 = new(new IPEndPoint(IPAddress.Loopback, 9054));
Assert.False(await client2.IsTorRunningAsync());
}
- private static async Task<List<string>> QBitTestAsync(TorHttpClient client, int times, bool alterRequests = false)
+ private async Task<List<string>> QBitTestAsync(TorHttpClient client, int times, bool alterRequests = false)
{
using CancellationTokenSource ctsTimeout = new(TimeSpan.FromMinutes(2));
@@ -217,7 +226,7 @@ namespace WalletWasabi.Tests.IntegrationTests
var task = client.SendAsync(HttpMethod.Get, relativetUri);
if (alterRequests)
{
- using var ipClient = MakeTorHttpClient(new Uri("https://api.ipify.org/"));
+ TorHttpClient ipClient = MakeTorHttpClient(new Uri("https://api.ipify.org/"));
var task2 = ipClient.SendAsync(HttpMethod.Get, "/", null, ctsTimeout.Token);
tasks.Add(task2);
}
@@ -235,9 +244,9 @@ namespace WalletWasabi.Tests.IntegrationTests
return contents;
}
- private static TorHttpClient MakeTorHttpClient(Uri uri, bool isolateStream = false)
+ private TorHttpClient MakeTorHttpClient(Uri uri, bool isolateStream = false)
{
- return new TorHttpClient(uri, Common.TorSocks5Endpoint, isolateStream);
+ return new TorHttpClient(uri, TorHttpPool, isolateStream);
}
}
}

MODIFY
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
@@ -261,7 +261,7 @@ namespace WalletWasabi.Tests.RegressionTests
blindedOutputScriptsHash = new uint256(NBitcoin.Crypto.Hashes.SHA256(blindedData.BlindedOutput.ToBytes()));
proof = key.SignCompact(blindedOutputScriptsHash);
inputsRequest.Inputs.First().Proof = proof;
- using (var aliceClient = await CreateNewAliceClientAsync(roundId, registeredAddresses, signerPubKeys, requesters, inputsRequest))
+ var aliceClient = await CreateNewAliceClientAsync(roundId, registeredAddresses, signerPubKeys, requesters, inputsRequest);
{
// Test DelayedClientRoundRegistration logic.
ClientRoundRegistration first = null;
@@ -309,7 +309,7 @@ namespace WalletWasabi.Tests.RegressionTests
Assert.Equal(2, currentRound.AnonymitySet);
Assert.Equal(0, currentRound.CountAlices());
- using (var aliceClient = await CreateNewAliceClientAsync(roundId, registeredAddresses, signerPubKeys, requesters, inputsRequest))
+ aliceClient = await CreateNewAliceClientAsync(roundId, registeredAddresses, signerPubKeys, requesters, inputsRequest);
{
Assert.NotEqual(Guid.Empty, aliceClient.UniqueId);
Assert.True(aliceClient.RoundId > 0);
@@ -375,7 +375,7 @@ namespace WalletWasabi.Tests.RegressionTests
h => currentRound.PhaseChanged += h,
h => currentRound.PhaseChanged -= h);
- using (var aliceClient = await CreateNewAliceClientAsync(roundId, registeredAddresses, signerPubKeys, requesters, inputsRequest))
+ aliceClient = await CreateNewAliceClientAsync(roundId, registeredAddresses, signerPubKeys, requesters, inputsRequest);
{
Assert.Equal(2, currentRound.AnonymitySet);
Assert.Equal(2, currentRound.CountAlices());
@@ -461,7 +461,7 @@ namespace WalletWasabi.Tests.RegressionTests
new InputProofModel { Input = coin.Outpoint, Proof = key.SignCompact(blindedOutputScriptsHash) }
}
};
- using (var aliceClient = await CreateNewAliceClientAsync(roundId, registeredAddresses, signerPubKeys, requesters, inputRequest))
+ aliceClient = await CreateNewAliceClientAsync(roundId, registeredAddresses, signerPubKeys, requesters, inputRequest);
{
Assert.NotEqual(Guid.Empty, aliceClient.UniqueId);
Assert.True(aliceClient.RoundId > 0);
@@ -510,7 +510,8 @@ namespace WalletWasabi.Tests.RegressionTests
new InputProofModel { Input = coin.Outpoint, Proof = key.SignCompact(blindedOutputScriptsHash) }
}
};
- using (var aliceClient = await CreateNewAliceClientAsync(roundId, registeredAddresses, signerPubKeys, requesters, inputRequest))
+
+ aliceClient = await CreateNewAliceClientAsync(roundId, registeredAddresses, signerPubKeys, requesters, inputRequest);
{
Assert.NotEqual(Guid.Empty, aliceClient.UniqueId);
Assert.True(aliceClient.RoundId > 0);
@@ -591,8 +592,9 @@ namespace WalletWasabi.Tests.RegressionTests
new InputProofModel { Input = input2, Proof = key2.SignCompact(blindedOutputScriptsHash2) }
}
};
- using (var aliceClient1 = await CreateNewAliceClientAsync(roundId, new[] { outputAddress1 }, signerPubKeys, new[] { requester1 }, inputRequest1))
- using (var aliceClient2 = await CreateNewAliceClientAsync(roundId, new[] { outputAddress2 }, signerPubKeys, new[] { requester2 }, inputRequest2))
+
+ var aliceClient1 = await CreateNewAliceClientAsync(roundId, new[] { outputAddress1 }, signerPubKeys, new[] { requester1 }, inputRequest1);
+ var aliceClient2 = await CreateNewAliceClientAsync(roundId, new[] { outputAddress2 }, signerPubKeys, new[] { requester2 }, inputRequest2);
{
Assert.Equal(aliceClient2.RoundId, aliceClient1.RoundId);
Assert.NotEqual(aliceClient2.UniqueId, aliceClient1.UniqueId);

MODIFY
WalletWasabi/Blockchain/TransactionBroadcasting/TransactionBroadcaster.cs
WalletWasabi/Blockchain/TransactionBroadcasting/TransactionBroadcaster.cs
@@ -91,9 +91,7 @@ namespace WalletWasabi.Blockchain.TransactionBroadcasting
Logger.LogInfo("Broadcasting with backend...");
IHttpClient httpClient = HttpClientFactory.NewBackendHttpClient(isolateStream: true);
- try
- {
- var client = new WasabiClient(httpClient);
+ WasabiClient client = new(httpClient);
try
{
@@ -112,11 +110,6 @@ namespace WalletWasabi.Blockchain.TransactionBroadcasting
throw;
}
- }
- finally
- {
- (httpClient as IDisposable)?.Dispose();
- }
BelieveTransaction(transaction);

MODIFY
WalletWasabi/CoinJoin/Client/Clients/AliceClientBase.cs
WalletWasabi/CoinJoin/Client/Clients/AliceClientBase.cs
@@ -19,10 +19,8 @@ using UnblindedSignature = WalletWasabi.Crypto.UnblindedSignature;
namespace WalletWasabi.CoinJoin.Client.Clients
{
- public abstract class AliceClientBase : IDisposable
+ public abstract class AliceClientBase
{
- private volatile bool _disposedValue = false; // To detect redundant calls
-
protected AliceClientBase(
long roundId,
IEnumerable<BitcoinAddress> registeredAddresses,
@@ -66,8 +64,7 @@ namespace WalletWasabi.CoinJoin.Client.Clients
Inputs = inputs
};
AliceClient4 client = new(roundId, registeredAddresses, signerPubKeys, requesters, network, httpClient);
- try
- {
+
// Correct it if forgot to set.
if (request.RoundId != roundId)
{
@@ -101,12 +98,6 @@ namespace WalletWasabi.CoinJoin.Client.Clients
return client;
}
- catch
- {
- client?.Dispose();
- throw;
- }
- }
public async Task<(RoundPhase currentPhase, IEnumerable<ActiveOutput> activeOutputs)> PostConfirmationAsync()
{
@@ -211,25 +202,5 @@ namespace WalletWasabi.CoinJoin.Client.Clients
}
Logger.LogInfo($"Round ({RoundId}), Alice ({UniqueId}): Posted {signatures.Count} signatures.");
}
-
- protected virtual void Dispose(bool disposing)
- {
- if (!_disposedValue)
- {
- if (disposing)
- {
- (HttpClient as IDisposable)?.Dispose();
- }
-
- _disposedValue = true;
- }
- }
-
- // This code added to correctly implement the disposable pattern.
- public void Dispose()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- Dispose(true);
- }
}
}

MODIFY
WalletWasabi/CoinJoin/Client/Clients/CoinJoinClient.cs
WalletWasabi/CoinJoin/Client/Clients/CoinJoinClient.cs
@@ -425,19 +425,12 @@ namespace WalletWasabi.CoinJoin.Client.Clients
foreach (var activeOutput in shuffledOutputs)
{
IHttpClient httpClient = Synchronizer.HttpClientFactory.NewBackendHttpClient(isolateStream: true);
- try
- {
var bobClient = new BobClient(httpClient);
if (!await bobClient.PostOutputAsync(ongoingRound.RoundId, activeOutput).ConfigureAwait(false))
{
Logger.LogWarning($"Round ({ongoingRound.State.RoundId}) Bobs did not have enough time to post outputs before timeout. If you see this message, contact nopara73, so he can optimize the phase timeout periods to the worst Internet/Tor connections, which may be yours.");
break;
}
- }
- finally
- {
- (httpClient as IDisposable)?.Dispose();
- }
// Unblind our exposed links.
foreach (OutPoint input in registeredInputs)
@@ -533,7 +526,6 @@ namespace WalletWasabi.CoinJoin.Client.Clients
Logger.LogWarning(ex.Message.Split('\n')[1]);
await DequeueCoinsFromMixNoLockAsync(coinReference, DequeueReason.Banned).ConfigureAwait(false);
- aliceClient?.Dispose();
return;
}
catch (HttpRequestException ex) when (ex.Message.Contains("Provided input is not unspent", StringComparison.InvariantCultureIgnoreCase))
@@ -553,19 +545,16 @@ namespace WalletWasabi.CoinJoin.Client.Clients
Logger.LogWarning(ex.Message.Split('\n')[1]);
await DequeueCoinsFromMixNoLockAsync(coinReference, DequeueReason.Spent).ConfigureAwait(false);
- aliceClient?.Dispose();
return;
}
catch (HttpRequestException ex) when (ex.Message.Contains("No such running round in InputRegistration", StringComparison.InvariantCultureIgnoreCase))
{
Logger.LogInfo("Client tried to register a round that is not in InputRegistration anymore. Trying again later.");
- aliceClient?.Dispose();
return;
}
catch (HttpRequestException ex) when (RpcErrorTools.IsTooLongMempoolChainError(ex.Message))
{
Logger.LogInfo("Coordinator failed because too much unconfirmed parent transactions. Trying again later.");
- aliceClient?.Dispose();
return;
}
@@ -588,7 +577,6 @@ namespace WalletWasabi.CoinJoin.Client.Clients
if (roundRegistered is null)
{
// If our SatoshiClient does not yet know about the round, because of delay, then delay the round registration.
- DelayedRoundRegistration?.Dispose();
DelayedRoundRegistration = registration;
}
@@ -999,8 +987,6 @@ namespace WalletWasabi.CoinJoin.Client.Clients
using (await MixLock.LockAsync(cancel).ConfigureAwait(false))
{
- State.DisposeAllAliceClients();
-
IEnumerable<OutPoint> allCoins = State.GetAllQueuedCoins();
foreach (var coinReference in allCoins)
{
@@ -1053,19 +1039,11 @@ namespace WalletWasabi.CoinJoin.Client.Clients
private async Task<AliceClientBase> CreateAliceClientAsync(long roundId, List<OutPoint> registrableCoins, (HdPubKey change, IEnumerable<HdPubKey> actives) outputAddresses)
{
- RoundStateResponse4 state;
HttpClientFactory factory = Synchronizer.HttpClientFactory;
IHttpClient satoshiHttpClient = factory.NewBackendHttpClient(isolateStream: true);
- try
- {
- var satoshiClient = new SatoshiClient(satoshiHttpClient);
- state = (RoundStateResponse4)await satoshiClient.GetRoundStateAsync(roundId).ConfigureAwait(false);
- }
- finally
- {
- (satoshiHttpClient as IDisposable)?.Dispose();
- }
+ SatoshiClient satoshiClient = new(satoshiHttpClient);
+ RoundStateResponse4 state = (RoundStateResponse4)await satoshiClient.GetRoundStateAsync(roundId).ConfigureAwait(false);
PubKey[] signerPubKeys = state.SignerPubKeys.ToArray();
PublicNonceWithIndex[] numerateNonces = state.RPubKeys.ToArray();

MODIFY
WalletWasabi/CoinJoin/Client/Rounds/ClientRound.cs
WalletWasabi/CoinJoin/Client/Rounds/ClientRound.cs
@@ -24,7 +24,6 @@ namespace WalletWasabi.CoinJoin.Client.Rounds
public void ClearRegistration()
{
- Registration?.Dispose();
Registration = null;
}
}

MODIFY
WalletWasabi/CoinJoin/Client/Rounds/ClientRoundRegistration.cs
WalletWasabi/CoinJoin/Client/Rounds/ClientRoundRegistration.cs
@@ -9,10 +9,8 @@ using WalletWasabi.Helpers;
namespace WalletWasabi.CoinJoin.Client.Rounds
{
- public class ClientRoundRegistration : IDisposable
+ public class ClientRoundRegistration
{
- private volatile bool _disposedValue = false; // To detect redundant calls
-
public ClientRoundRegistration(AliceClientBase aliceClient, IEnumerable<SmartCoin> coinsRegistereds, BitcoinAddress changeAddress)
{
AliceClient = Guard.NotNull(nameof(aliceClient), aliceClient);
@@ -44,29 +42,5 @@ namespace WalletWasabi.CoinJoin.Client.Rounds
CompletedPhase = phase;
}
}
-
- #region IDisposable Support
-
- protected virtual void Dispose(bool disposing)
- {
- if (!_disposedValue)
- {
- if (disposing)
- {
- AliceClient?.Dispose();
- }
-
- _disposedValue = true;
- }
- }
-
- // This code added to correctly implement the disposable pattern.
- public void Dispose()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- Dispose(true);
- }
-
- #endregion IDisposable Support
}
}

MODIFY
WalletWasabi/CoinJoin/Client/Rounds/ClientState.cs
WalletWasabi/CoinJoin/Client/Rounds/ClientState.cs
@@ -407,8 +407,6 @@ namespace WalletWasabi.CoinJoin.Client.Rounds
}
}
- round?.Registration?.AliceClient?.Dispose();
-
Logger.LogInfo($"Round ({round.State.RoundId}) removed. Reason: It's not running anymore.");
}
Rounds.RemoveAll(x => roundsToRemove.Contains(x.State.RoundId));
@@ -449,16 +447,5 @@ namespace WalletWasabi.CoinJoin.Client.Rounds
}
}
}
-
- public void DisposeAllAliceClients()
- {
- lock (StateLock)
- {
- foreach (var aliceClient in Rounds?.Select(x => x?.Registration?.AliceClient))
- {
- aliceClient?.Dispose();
- }
- }
- }
}
}

Fix tests and remove try-finally.