Cache input requests
MODIFY
HiddenWallet.ChaumianTumbler/Controllers/TumblerController.cs
HiddenWallet.ChaumianTumbler/Controllers/TumblerController.cs
@@ -53,6 +53,9 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
}
}
+ private static ConcurrentHashSet<(IActionResult Response, InputsRequest Request)> SuccessfulInputRequestCache { get; set; }
+ private volatile int _currentInputRequestCacheRound;
+
private static readonly AsyncLock InputRegistrationLock = new AsyncLock();
[Route("inputs")]
[HttpPost]
@@ -60,6 +63,28 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
{
var roundId = Global.StateMachine.RoundId;
+ // if wasnt initialized initialize
+ if (SuccessfulInputRequestCache == null)
+ {
+ SuccessfulInputRequestCache = new ConcurrentHashSet<(IActionResult, InputsRequest)>();
+ _currentInputRequestCacheRound = roundId;
+ }
+
+ // if different round, initialize
+ if (_currentInputRequestCacheRound != roundId)
+ {
+ SuccessfulInputRequestCache = new ConcurrentHashSet<(IActionResult, InputsRequest)>();
+ _currentInputRequestCacheRound = roundId;
+ }
+
+ foreach(var cacheRecord in SuccessfulInputRequestCache)
+ {
+ if (cacheRecord.Request.IsSame(request))
+ {
+ return cacheRecord.Response;
+ }
+ }
+
TumblerPhase phase = TumblerPhase.InputRegistration;
try
@@ -236,11 +261,13 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
Global.StateMachine.UpdatePhase(TumblerPhase.ConnectionConfirmation);
}
- return new ObjectResult(new InputsResponse()
+ var ret = new ObjectResult(new InputsResponse()
{
UniqueId = uniqueId.ToString(),
SignedBlindedOutput = HexHelpers.ToString(signature)
});
+ SuccessfulInputRequestCache.Add((ret, request));
+ return ret;
}
}
catch (Exception ex)

MODIFY
HiddenWallet/ChaumianCoinJoin/Models/InputsRequest.cs
HiddenWallet/ChaumianCoinJoin/Models/InputsRequest.cs
@@ -10,5 +10,20 @@ namespace HiddenWallet.ChaumianCoinJoin.Models
public InputProofModel[] Inputs { get; set; }
public string BlindedOutput { get; set; }
public string ChangeOutput { get; set; }
+
+ public bool IsSame(InputsRequest other)
+ {
+ if (BlindedOutput != other.BlindedOutput) return false;
+ if (ChangeOutput != other.ChangeOutput) return false;
+ int inputsCount = Inputs.Count();
+ if (inputsCount != other.Inputs.Count()) return false;
+ for (int i = 0; i < inputsCount; i++)
+ {
+ if (Inputs[i].Input != other.Inputs[i].Input) return false;
+ if (Inputs[i].Proof != other.Inputs[i].Proof) return false;
+ }
+
+ return true;
+ }
}
}
\ No newline at end of file

Cache input requests