Skip to content
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

Apply time preference check for all lower TimeFrames #12356

Merged
merged 4 commits into from Feb 6, 2024

Conversation

turbolay
Copy link
Collaborator

@turbolay turbolay commented Feb 3, 2024

Problem found by @Kruwed

tl;dr: When you are willing to wait for several days for the best moment of the month, you are also willing to wait few extra hours for the best moment of the day

Currently, IsRoundEconomic only takes into consideration the MedianFeeRate related to the exact TimeFrame selected in user's Coinjoin settings,
But in cases where a FeeRateMedian for a short TimeFrame is lower than the FeeRateMedian for a longer TimeFrame , and the user has the longer TimeFrame in its settings, IsRoundEconomic will allow coinjoin.


Example:
Median past day, 24 sat/vbyte
Median past week, 27 sat/vbyte
Median past month, 35 sat/vbyte

The user has Weekly selected, the current coinjoin round's fee rate is 26 sat/vb
Currently, IsRoundEconomic will return true, while it would be better to wait for the current round fee rate to also go below the daily median.


I know that this problem is a bit tricky to understand, I had to wrap my head around it for quite some time.
What this PR is doing is to check for the current FeeRateMedian of all lower or equal TimeFrame of what the user has in settings. That way, IsRoundEconomic will also return false until all the current round's fee rate goes below the MedianFeeRate for all lower TimeFrame.

I wanted to write a test but I didn't manage to do it without changing the method to static or struggling to instantiate CoinJoinClient, if anyone has a suggestion on how to do it I would gladly write the test.

{
if (FeeRateMedianTimeFrame == default)
{
return true;
}

if (RoundStatusUpdater.CoinJoinFeeRateMedians.TryGetValue(FeeRateMedianTimeFrame, out var medianFeeRate))
if (RoundStatusUpdater.CoinJoinFeeRateMedians.ContainsKey(FeeRateMedianTimeFrame))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is more or less useless now but I didn't want to change the behaviour.

@turbolay turbolay requested a review from molnard February 3, 2024 18:14
Copy link
Collaborator

@molnard molnard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cACK! You can make it static and add a test - that's fine.

@molnard molnard added this to the v2.0.6 milestone Feb 5, 2024
Copy link
Collaborator

@yahiheb yahiheb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is failing.

Copy link
Collaborator

@molnard molnard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cACK - tests need to be fixed.

@turbolay
Copy link
Collaborator Author

turbolay commented Feb 6, 2024

Thanks @molnard for cbaee79, sorry for the mistake

Copy link
Collaborator

@molnard molnard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, test is 👌

@molnard molnard merged commit 9fa8953 into zkSNACKs:master Feb 6, 2024
7 checks passed
@molnard
Copy link
Collaborator

molnard commented Feb 16, 2024

Sorry if irrelevant but I don't see PR that is merging this to the release branch. Can you verify if it is merged, if not then create a PR for that.

@turbolay turbolay deleted the timePreferenceLowerTimeFrames branch February 26, 2024 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants