Skip to content

Commit

Permalink
Set rounding mode back to default (TO_NEAREST) after randomx
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Doy-lee committed Oct 8, 2019
1 parent dddec30 commit 342e985
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/cryptonote_core/cryptonote_tx_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ namespace cryptonote
{
blobdata bd = get_block_hashing_blob(b);
rx_slow_hash(main_height, seed_height, seed_hash.data, bd.data(), bd.size(), res.data, 0, 1);
std::fesetround(FE_TONEAREST);
}

bool get_block_longhash(const Blockchain *pbc, const block& b, crypto::hash& res, const uint64_t height, const int miners)
Expand All @@ -993,7 +994,8 @@ namespace cryptonote
const_cast<int &>(miners) = 0;
#endif

if (hf_version >= network_version_12_checkpointing) {
if (hf_version >= network_version_12_checkpointing)
{
uint64_t seed_height, main_height;
crypto::hash hash;
if (pbc != NULL)
Expand All @@ -1008,6 +1010,7 @@ namespace cryptonote
main_height = 0;
}
rx_slow_hash(main_height, seed_height, hash.data, bd.data(), bd.size(), res.data, miners, 0);
std::fesetround(FE_TONEAREST);
return true;
}

Expand Down
3 changes: 0 additions & 3 deletions src/cryptonote_core/service_node_rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
base = 15000 * COIN;
variable = (25007.0 * COIN) / loki::exp2(height_adjusted/129600.0);
std::fesetround(round_method);
}
else
{
Expand Down

0 comments on commit 342e985

Please sign in to comment.