Permalink
Browse files

Handle connection failures when dequeue

  • Loading branch information...
nopara73 committed Oct 19, 2018
1 parent ce5e744 commit 24b1c70c2f771276926fcd880769737defd3b981
Showing with 74 additions and 12 deletions.
  1. +42 −8 WalletWasabi/Services/CcjClient.cs
  2. +32 −4 WalletWasabi/WebClients/Wasabi/ChaumianCoinJoin/AliceClient.cs
@@ -655,29 +655,63 @@ public async Task<IEnumerable<SmartCoin>> QueueCoinsToMixAsync(string password,
public async Task DequeueCoinsFromMixAsync(params SmartCoin[] coins)
{
using (await MixLock.LockAsync())
using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3)))
{
await DequeueCoinsFromMixNoLockAsync(State.GetSpentCoins().ToArray());
try
{
using (await MixLock.LockAsync(cts.Token))
{
await DequeueCoinsFromMixNoLockAsync(State.GetSpentCoins().ToArray());
await DequeueCoinsFromMixNoLockAsync(coins.Select(x => (x.TransactionId, x.Index)).ToArray());
await DequeueCoinsFromMixNoLockAsync(coins.Select(x => (x.TransactionId, x.Index)).ToArray());
}
}
catch (TaskCanceledException)
{
await DequeueCoinsFromMixNoLockAsync(State.GetSpentCoins().ToArray());
await DequeueCoinsFromMixNoLockAsync(coins.Select(x => (x.TransactionId, x.Index)).ToArray());
}
}
}
public async Task DequeueCoinsFromMixAsync(params (uint256 txid, uint index)[] coins)
{
using (await MixLock.LockAsync())
using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3)))
{
await DequeueCoinsFromMixNoLockAsync(State.GetSpentCoins().ToArray());
try
{
using (await MixLock.LockAsync(cts.Token))
{
await DequeueCoinsFromMixNoLockAsync(State.GetSpentCoins().ToArray());
await DequeueCoinsFromMixNoLockAsync(coins);
}
}
catch (TaskCanceledException)
{
await DequeueCoinsFromMixNoLockAsync(State.GetSpentCoins().ToArray());
await DequeueCoinsFromMixNoLockAsync(coins);
await DequeueCoinsFromMixNoLockAsync(coins);
}
}
}
public async Task DequeueAllCoinsFromMixAsync()
{
using (await MixLock.LockAsync())
using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3)))
{
await DequeueCoinsFromMixNoLockAsync(State.GetAllQueuedCoins().ToArray());
try
{
using (await MixLock.LockAsync(cts.Token))
{
await DequeueCoinsFromMixNoLockAsync(State.GetAllQueuedCoins().ToArray());
}
}
catch (TaskCanceledException)
{
await DequeueCoinsFromMixNoLockAsync(State.GetAllQueuedCoins().ToArray());
}
}
}
@@ -13,6 +13,8 @@
using WalletWasabi.Logging;
using WalletWasabi.TorSocks5;
using WalletWasabi.Bases;
using System.Threading;
using WalletWasabi.Exceptions;
namespace WalletWasabi.WebClients.Wasabi.ChaumianCoinJoin
{
@@ -94,14 +96,40 @@ public async Task<string> PostConfirmationAsync()
/// <returns>null or roundHash</returns>
public async Task PostUnConfirmationAsync()
{
using (HttpResponseMessage response = await TorClient.SendAsync(HttpMethod.Post, $"/api/v{Helpers.Constants.BackendMajorVersion}/btc/chaumiancoinjoin/unconfirmation?uniqueId={UniqueId}&roundId={RoundId}"))
using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3)))
{
if (!response.IsSuccessStatusCode)
try
{
await response.ThrowRequestExceptionFromContentAsync();
using (HttpResponseMessage response = await TorClient.SendAsync(HttpMethod.Post, $"/api/v{Helpers.Constants.BackendMajorVersion}/btc/chaumiancoinjoin/unconfirmation?uniqueId={UniqueId}&roundId={RoundId}", cancel: cts.Token))
{
if (response.StatusCode == HttpStatusCode.BadRequest || response.StatusCode == HttpStatusCode.Gone) // Otherwise maybe some internet connection issue there's. Let's consider that as timed out.
{
await response.ThrowRequestExceptionFromContentAsync();
}
}
}
catch (TaskCanceledException) // If couldn't do it within 3 seconds then it'll likely time out and take it as unconfirmed.
{
return;
}
catch (OperationCanceledException) // If couldn't do it within 3 seconds then it'll likely time out and take it as unconfirmed.
{
return;
}
catch (TimeoutException) // If couldn't do it within 3 seconds then it'll likely time out and take it as unconfirmed.
{
return;
}
catch (ConnectionException) // If some internet connection issue then it'll likely time out and take it as unconfirmed.
{
return;
}
catch (TorSocks5FailureResponseException) // If some Tor connection issue then it'll likely time out and take it as unconfirmed.
{
return;
}
Logger.LogInfo<AliceClient>($"Round ({RoundId}), Alice ({UniqueId}): Unconfirmed connection.");
}
Logger.LogInfo<AliceClient>($"Round ({RoundId}), Alice ({UniqueId}): Unconfirmed connection.");
}
public async Task<Transaction> GetUnsignedCoinJoinAsync()

0 comments on commit 24b1c70

Please sign in to comment.