New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
State machine will follow the business logic (continuation) #10059
Conversation
8583ce6
to
da90903
Compare
@@ -249,6 +251,7 @@ private void ConfigureStateMachine() | |||
.Permit(Trigger.PlebStopChanged, State.Playing) | |||
.Permit(Trigger.WalletStartedCoinJoin, State.Playing) | |||
.Permit(Trigger.WalletStoppedCoinJoin, State.StoppedOrPaused) | |||
.Permit(Trigger.StartError, State.Playing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same change than #10032 but for PlebStop
walletToStart.LogDebug($"AutoStart was already scheduled, cancel the last task and do not wait."); | ||
trackedAutoStarts[walletToStart].CancellationTokenSource.Cancel(); | ||
trackedAutoStarts.Remove(walletToStart, out _); | ||
delayRestart = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to make sure that whenever user tries to restart CoinJoin when it was already scheduled, new arguments are taken into account.
This happens for example when user presses Play
in State.PlebStop
with only pending coins. A restart task was already scheduled by precedent action with OverridePlebStop
as false
, so when user presses Play
in State.PlebStop
we need to cancel the last task to start a new one with OverridePlebStop
as true
.
I set the delay to 0 as it doesn't really change anything but we could increase it a bit or use a StopWatch
if this could be a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would isolate the case. Compare the two trackedAutoStarts OverridePlebStop. If it is different, do the update if not then just debug the message and return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not able to see any issue with this fix, @yahiheb @MarnixCroes can you try to break it?
So far, I'm not able to break it.
51d9a39
to
ee9bdfe
Compare
46fd1d5
to
ee9bdfe
Compare
# Conflicts: # WalletWasabi/WabiSabi/Client/CoinJoinManager.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once all your coins are private and you get this message Hurray! Your funds are private
the play button does nothing on master. With this PR it works.
tACK
walletToStart.LogDebug($"AutoStart was already scheduled, cancel the last task and do not wait."); | ||
trackedAutoStarts[walletToStart].CancellationTokenSource.Cancel(); | ||
trackedAutoStarts.Remove(walletToStart, out _); | ||
delayRestart = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would isolate the case. Compare the two trackedAutoStarts OverridePlebStop. If it is different, do the update if not then just debug the message and return.
walletToStart.LogDebug($"AutoStart was already scheduled."); | ||
return; | ||
walletToStart.LogDebug("AutoStart was already scheduled, cancel the last task and do not wait."); | ||
TryRemoveTrackedAutoStart(trackedAutoStarts, walletToStart); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just let this go in this case, it will be removed later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that it will be removed correctly after while being sure the old task is not executed in case for eg of an infortunate timing
@molnard To do that I'd need to access parameters for the last task and hence change record |
That is a clean-cut. Yes. |
if (trackedAutoStarts.ContainsKey(walletToStart)) | ||
{ | ||
walletToStart.LogDebug($"AutoStart was already scheduled."); | ||
return; | ||
if (stopWhenAllMixed == trackedAutoStarts[walletToStart].StopWhenAllMixed && overridePlebStop == trackedAutoStarts[walletToStart].OverridePlebStop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dictionnary with IWallet
as key. Maybe consider changing? I don't know if necessary, neither what we could use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will address this in a subsequent PR probably using WalletName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or implement making sure the wallet name will be used when checking equality for dictionaries. ACK for doing it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment, wallet references are never changing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (trackedAutoStarts.ContainsKey(walletToStart)) | ||
{ | ||
walletToStart.LogDebug($"AutoStart was already scheduled."); | ||
return; | ||
if (stopWhenAllMixed == trackedAutoStarts[walletToStart].StopWhenAllMixed && overridePlebStop == trackedAutoStarts[walletToStart].OverridePlebStop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or implement making sure the wallet name will be used when checking equality for dictionaries. ACK for doing it later.
@brizik please test this with the help of @MarnixCroes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK
Last 2 commits does not change anything to the behavior:
|
@MarnixCroes can you take a look at this? |
|
||
#pragma warning disable CA2000 // Dispose objects before losing scope | ||
var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(stoppingToken); | ||
#pragma warning restore CA2000 // Dispose objects before losing scope | ||
|
||
var restartTask = Task.Run( | ||
var restartTask = new Task( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I explained in my comment:
Create the task then add to task list it then start it. There was no any issues before but now that we do not wait sometimes there could be a concurrency issues
At the end of the task we remove the task from the list, but the line to add the task into the list was after task run, I was afraid of a potential concurrency problem.
Should I revert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I did not see that. How can concurrency happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Between
if (trackedAutoStarts.TryRemove(walletToStart, out _)) |
and
if (trackedAutoStarts.TryAdd(walletToStart, new TrackedAutoStart(restartTask, stopWhenAllMixed, overridePlebStop, linkedCts))) |
because we do not wait anymore in some cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK 🥇
Supersedes #10032
Closes #9957
The point is to
NotifyWalletStartedCoinJoin(walletToStart)
whenScheduleRestartAutomatically
is called, but only once (hence use ofWasRestartedAutomatically
)The change with
PlebStop
is to adapt it to new behavior as it was broken. It makes sure that when a user chose toOverridePlebstop
, he won't have to override again until he pressesPause
. It should also block when balance becomes lower than the threshold during CJ because of fees (untested).I was not able to see any issue with this fix, @yahiheb @MarnixCroes can you try to break it?