Add phase check
MODIFY
HiddenWallet.ChaumianTumbler/Configuration/Config.cs
HiddenWallet.ChaumianTumbler/Configuration/Config.cs
@@ -49,8 +49,8 @@ namespace HiddenWallet.ChaumianTumbler.Configuration
[JsonProperty(PropertyName = "InputRegistrationPhaseTimeoutInSeconds")]
public int? InputRegistrationPhaseTimeoutInSeconds { get; private set; }
- [JsonProperty(PropertyName = "InputConfirmationPhaseTimeoutInSeconds")]
- public int? InputConfirmationPhaseTimeoutInSeconds { get; private set; }
+ [JsonProperty(PropertyName = "ConnectionConfirmationPhaseTimeoutInSeconds")]
+ public int? ConnectionConfirmationPhaseTimeoutInSeconds { get; private set; }
[JsonProperty(PropertyName = "OutputRegistrationPhaseTimeoutInSeconds")]
public int? OutputRegistrationPhaseTimeoutInSeconds { get; private set; }
@@ -94,7 +94,7 @@ namespace HiddenWallet.ChaumianTumbler.Configuration
MaximumAnonymitySet = 100; // for now, in theory 300-400 should be fine, too
AverageTimeToSpendInInputRegistrationInSeconds = 180; // 3min
InputRegistrationPhaseTimeoutInSeconds = 86400; // one day
- InputConfirmationPhaseTimeoutInSeconds = 60;
+ ConnectionConfirmationPhaseTimeoutInSeconds = 60;
OutputRegistrationPhaseTimeoutInSeconds = 60;
SigningPhaseTimeoutInSeconds = 60;
MaximumInputsPerAlices = 7;
@@ -119,7 +119,7 @@ namespace HiddenWallet.ChaumianTumbler.Configuration
MaximumAnonymitySet = config.MaximumAnonymitySet ?? MaximumAnonymitySet;
AverageTimeToSpendInInputRegistrationInSeconds = config.AverageTimeToSpendInInputRegistrationInSeconds ?? AverageTimeToSpendInInputRegistrationInSeconds;
InputRegistrationPhaseTimeoutInSeconds = config.InputRegistrationPhaseTimeoutInSeconds ?? InputRegistrationPhaseTimeoutInSeconds;
- InputConfirmationPhaseTimeoutInSeconds = config.InputConfirmationPhaseTimeoutInSeconds ?? InputConfirmationPhaseTimeoutInSeconds;
+ ConnectionConfirmationPhaseTimeoutInSeconds = config.ConnectionConfirmationPhaseTimeoutInSeconds ?? ConnectionConfirmationPhaseTimeoutInSeconds;
OutputRegistrationPhaseTimeoutInSeconds = config.OutputRegistrationPhaseTimeoutInSeconds ?? OutputRegistrationPhaseTimeoutInSeconds;
SigningPhaseTimeoutInSeconds = config.SigningPhaseTimeoutInSeconds ?? SigningPhaseTimeoutInSeconds;
MaximumInputsPerAlices = config.MaximumInputsPerAlices ?? MaximumInputsPerAlices;

MODIFY
HiddenWallet.ChaumianTumbler/Controllers/TumblerController.cs
HiddenWallet.ChaumianTumbler/Controllers/TumblerController.cs
@@ -74,6 +74,11 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
{
try
{
+ if (Global.StateMachine.Phase != TumblerPhase.InputRegistration || !Global.StateMachine.AcceptRequest)
+ {
+ return new ObjectResult(new FailureResponse { Message = "Wrong phase", Details = "" });
+ }
+
// Check not nulls
if (request.BlindedOutput == null) return new BadRequestResult();
if (request.ChangeOutput == null) return new BadRequestResult();
@@ -133,9 +138,6 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
throw new ArgumentException("Total provided inputs must be > denomination + fee");
}
-
- // only enable requests in specific phases
-
throw new NotImplementedException();
}
catch (Exception ex)
@@ -150,6 +152,11 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
{
try
{
+ if (Global.StateMachine.Phase != TumblerPhase.InputRegistration || !Global.StateMachine.AcceptRequest)
+ {
+ return new ObjectResult(new FailureResponse { Message = "Wrong phase", Details = "" });
+ }
+
throw new NotImplementedException();
}
catch (Exception ex)
@@ -164,6 +171,11 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
{
try
{
+ if (Global.StateMachine.Phase != TumblerPhase.ConnectionConfirmation || !Global.StateMachine.AcceptRequest)
+ {
+ return new ObjectResult(new FailureResponse { Message = "Wrong phase", Details = "" });
+ }
+
if (request.UniqueId == null) return new BadRequestResult();
throw new NotImplementedException();
@@ -180,6 +192,11 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
{
try
{
+ if (Global.StateMachine.Phase != TumblerPhase.OutputRegistration || !Global.StateMachine.AcceptRequest)
+ {
+ return new ObjectResult(new FailureResponse { Message = "Wrong phase", Details = "" });
+ }
+
if (request.SignedOutput == null) return new BadRequestResult();
throw new NotImplementedException();
@@ -196,6 +213,11 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
{
try
{
+ if (Global.StateMachine.Phase != TumblerPhase.Signing || !Global.StateMachine.AcceptRequest)
+ {
+ return new ObjectResult(new FailureResponse { Message = "Wrong phase", Details = "" });
+ }
+
throw new NotImplementedException();
}
catch (Exception ex)
@@ -210,6 +232,11 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
{
try
{
+ if (Global.StateMachine.Phase != TumblerPhase.Signing || !Global.StateMachine.AcceptRequest)
+ {
+ return new ObjectResult(new FailureResponse { Message = "Wrong phase", Details = "" });
+ }
+
if (request.Signature == null) return new BadRequestResult();
throw new NotImplementedException();
}

MODIFY
HiddenWallet.ChaumianTumbler/TumblerStateMachine.cs
HiddenWallet.ChaumianTumbler/TumblerStateMachine.cs
@@ -22,6 +22,7 @@ namespace HiddenWallet.ChaumianTumbler
public Money FeePerOutputs { get; private set; }
public int AnonymitySet { get; private set; } = (int)Global.Config.MinimumAnonymitySet;
public TimeSpan TimeSpentInInputRegistration { get; private set; } = TimeSpan.FromSeconds((int)Global.Config.AverageTimeToSpendInInputRegistrationInSeconds) + TimeSpan.FromSeconds(1); // took one sec longer, so the first round will use the same anonymity set
+ public bool AcceptRequest { get; private set; } = false;
private SmartBitClient SmartBitClient { get; }
@@ -34,15 +35,21 @@ namespace HiddenWallet.ChaumianTumbler
SmartBitClient = new SmartBitClient(Network.Main);
}
+ public void BroadcastPhaseChange()
+ {
+ AcceptRequest = true;
+ var broadcast = new PhaseChangeBroadcast { NewPhase = Phase.ToString(), Message = "" };
+ _broadcaster.Broadcast(broadcast);
+ }
+
public void UpdatePhase(TumblerPhase phase)
{
if (phase == Phase) return;
+ AcceptRequest = false;
Phase = phase;
_ctsPhaseCancel.Cancel();
_ctsPhaseCancel = new CancellationTokenSource();
- var broadcast = new PhaseChangeBroadcast { NewPhase = phase.ToString(), Message = "" };
- _broadcaster.Broadcast(broadcast);
Console.WriteLine($"NEW PHASE: {phase}");
}
@@ -52,10 +59,10 @@ namespace HiddenWallet.ChaumianTumbler
{
case TumblerPhase.InputRegistration:
{
- UpdatePhase(TumblerPhase.InputConfirmation);
+ UpdatePhase(TumblerPhase.ConnectionConfirmation);
break;
}
- case TumblerPhase.InputConfirmation:
+ case TumblerPhase.ConnectionConfirmation:
{
UpdatePhase(TumblerPhase.OutputRegistration);
break;
@@ -94,6 +101,7 @@ namespace HiddenWallet.ChaumianTumbler
CalculateAnonymitySet();
await Task.WhenAll(denominationTask, feeTask);
+ BroadcastPhaseChange();
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel, _ctsPhaseCancel.Token))
@@ -106,17 +114,19 @@ namespace HiddenWallet.ChaumianTumbler
AdvancePhase();
break;
}
- case TumblerPhase.InputConfirmation:
+ case TumblerPhase.ConnectionConfirmation:
{
+ BroadcastPhaseChange();
using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel, _ctsPhaseCancel.Token))
{
- await Task.Delay(TimeSpan.FromSeconds((int)Global.Config.InputConfirmationPhaseTimeoutInSeconds), cts.Token).ContinueWith(t => { });
+ await Task.Delay(TimeSpan.FromSeconds((int)Global.Config.ConnectionConfirmationPhaseTimeoutInSeconds), cts.Token).ContinueWith(t => { });
}
AdvancePhase();
break;
}
case TumblerPhase.OutputRegistration:
{
+ BroadcastPhaseChange();
using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel, _ctsPhaseCancel.Token))
{
await Task.Delay(TimeSpan.FromSeconds((int)Global.Config.OutputRegistrationPhaseTimeoutInSeconds), cts.Token).ContinueWith(t => { });
@@ -126,6 +136,7 @@ namespace HiddenWallet.ChaumianTumbler
}
case TumblerPhase.Signing:
{
+ BroadcastPhaseChange();
using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel, _ctsPhaseCancel.Token))
{
await Task.Delay(TimeSpan.FromSeconds((int)Global.Config.SigningPhaseTimeoutInSeconds), cts.Token).ContinueWith(t => { });

MODIFY
HiddenWallet/ChaumianCoinJoin/TumblerPhase.cs
HiddenWallet/ChaumianCoinJoin/TumblerPhase.cs
@@ -7,7 +7,7 @@ namespace HiddenWallet.ChaumianCoinJoin
public enum TumblerPhase
{
InputRegistration,
- InputConfirmation,
+ ConnectionConfirmation,
OutputRegistration,
Signing,
}

Add phase check