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

Turn staking requirement into integer math variant #877

Merged
merged 4 commits into from
Oct 9, 2019

Conversation

Doy-lee
Copy link
Collaborator

@Doy-lee Doy-lee commented Oct 8, 2019

Original comment and data points for the algorithm from @jagerman

x = 385824 429024 472224 515424 558624 601824 645024 688224 731424 774624 817824 861024 904224

y =  20458380815527 19332319724305 18438564443912 17729190407764 17166159862153 16719282221956 16364595203882 16083079931076 15859641110978 15682297601941 15541539965538 15429820555489 15341148800970

So, e.g., for H=450000 you'd get i=1, so:  intlsr = 19332319724305 + (450000 - 429024) * (18438564443912 - 19332319724305) / (472224 - 429024)
= 18898.351882603

versus 18872.560735094 from the LSR.

This is a linear step-down approximation of the staking requirement to remove the use of floating point math.

unknown

Will write some unit tests- to verify later.

Executing RandomX has side effects on the current rounding mode
depending on the hash program it generates and doesn't reset the
rounding mode after the fact. So explicitly set it after.
@Doy-lee Doy-lee force-pushed the IntegerMathStakingRequirement branch from 342e985 to d39a144 Compare October 8, 2019 23:56
@@ -77,11 +77,8 @@ uint64_t get_staking_requirement(cryptonote::network_type m_nettype, uint64_t he
uint64_t base = 0, variable = 0;
if (hf_version >= cryptonote::network_version_11_infinite_staking)
{
auto round_method = std::fegetround();
std::fesetround(FE_TONEAREST);
Copy link
Member

@jagerman jagerman Oct 9, 2019

Choose a reason for hiding this comment

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

I think this fesetround should stay: I don't think there's any particular guarantee as to what rounding mode the thread is in without an explicit call, and I'm assuming it's essentially a no-op if setting it to the mode it's already in.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And updated.

Instead of implicitly relying on the mode we expect it to be
@Doy-lee Doy-lee force-pushed the IntegerMathStakingRequirement branch from 61f5369 to 049c2e8 Compare October 9, 2019 01:41
@Doy-lee Doy-lee merged commit c88f17d into oxen-io:dev Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants