Handle slow client exceptions when debugging
MODIFY
HiddenWallet.Daemon/Wrappers/WalletWrapper.cs
HiddenWallet.Daemon/Wrappers/WalletWrapper.cs
@@ -277,7 +277,7 @@ namespace HiddenWallet.Daemon.Wrappers
public async Task<BaseResponse> BuildTransactionAsync(string password, SafeAccount safeAccount, BitcoinAddress address, Money amount, FeeType feeType)
{
// todo: delete this code comment, it was just a test, if you see it, I forgot to delete it
- // await _walletJob.CoinJoinService.TumbleAsync(AliceAccount, BobAccount, CancellationToken.None);
+ // await _walletJob.CoinJoinService.TumbleAsync(safeAccount == AliceAccount ? AliceAccount : BobAccount, safeAccount != AliceAccount ? AliceAccount : BobAccount, CancellationToken.None);
if (password != _password) throw new InvalidOperationException("Wrong password");
var result = await _walletJob.BuildTransactionAsync(address.ScriptPubKey, amount, feeType, safeAccount, (bool)Global.Config.CanSpendUnconfirmed);

MODIFY
HiddenWallet.FullSpvWallet/ChaumianCoinJoin/CoinJoinService.cs
HiddenWallet.FullSpvWallet/ChaumianCoinJoin/CoinJoinService.cs
@@ -33,8 +33,10 @@ namespace HiddenWallet.FullSpvWallet.ChaumianCoinJoin
public BlindingRsaPubKey PubKey { get; private set; }
- private volatile bool _tumblingInProcess;
+ public volatile bool TumblingInProcess;
public volatile TumblerPhase Phase;
+ public volatile Exception TumblingException;
+ public volatile bool CompletedLastPhase;
public Money Denomination { get; private set; }
public string UniqueAliceId { get; private set; }
@@ -47,7 +49,8 @@ namespace HiddenWallet.FullSpvWallet.ChaumianCoinJoin
public CoinJoinService(WalletJob walletJob)
{
- _tumblingInProcess = false;
+ TumblingInProcess = false;
+ CompletedLastPhase = true;
TumblerConnection = null;
WalletJob = walletJob ?? throw new ArgumentNullException(nameof(walletJob));
}
@@ -74,13 +77,20 @@ namespace HiddenWallet.FullSpvWallet.ChaumianCoinJoin
var jObject = JObject.Parse(data);
var phaseString = jObject.Value<string>("NewPhase");
+ Debug.WriteLine($"New Phase: {phaseString}");
Phase = TumblerPhaseHelpers.GetTumblerPhase(phaseString);
if (Phase != TumblerPhase.InputRegistration) // input registration is executed from tumbling function
+ {
+ try
{
await ExecutePhaseAsync(Phase, CancellationToken.None);
}
-
- Debug.WriteLine($"New Phase: {phaseString}");
+ catch
+ {
+ // handle inside
+ }
+ }
+ Debug.WriteLine($"Phase completed");
});
await TumblerConnection.StartAsync();
@@ -147,21 +157,31 @@ namespace HiddenWallet.FullSpvWallet.ChaumianCoinJoin
await Task.Delay(100, cancel);
}
- _tumblingInProcess = true;
+ TumblingInProcess = true;
await ExecutePhaseAsync(Phase, cancel);
// wait while input registration
- while (Phase == TumblerPhase.InputRegistration)
+ while (Phase == TumblerPhase.InputRegistration && TumblingInProcess)
{
await Task.Delay(100, cancel);
}
// wait for input registration again, this is the end of the round (beginning of the next round)
- while (Phase != TumblerPhase.InputRegistration)
+ while (Phase != TumblerPhase.InputRegistration && TumblingInProcess)
{
await Task.Delay(100, cancel);
}
- _tumblingInProcess = false;
+
+ // if tumbling
+ if(TumblingInProcess == false)
+ {
+ throw TumblingException;
+ }
+ else
+ {
+ TumblingInProcess = false;
+ TumblingException = null;
+ }
}
catch(OperationCanceledException)
{
@@ -171,10 +191,15 @@ namespace HiddenWallet.FullSpvWallet.ChaumianCoinJoin
private async Task ExecutePhaseAsync(TumblerPhase phase, CancellationToken cancel)
{
- if (_tumblingInProcess)
+ while (CompletedLastPhase == false)
+ {
+ await Task.Delay(100, cancel);
+ }
+ if (TumblingInProcess)
{
try
{
+ CompletedLastPhase = false;
if (phase == TumblerPhase.InputRegistration)
{
StatusResponse status = await TumblerClient.GetStatusAsync(cancel);
@@ -307,12 +332,17 @@ namespace HiddenWallet.FullSpvWallet.ChaumianCoinJoin
}
else throw new NotSupportedException("This should never happen");
}
- catch
+ catch (Exception ex)
{
// if an exception happened don't tumbler anymore in this round
- _tumblingInProcess = false;
+ TumblingInProcess = false;
+ TumblingException = ex;
throw;
}
+ finally
+ {
+ CompletedLastPhase = true;
+ }
}
}

Handle slow client exceptions when debugging