Skip to content

Commit

Permalink
Fix randomx cache selection for RPCs
Browse files Browse the repository at this point in the history
Was using the wrong cache slot, and returning invalid PoW hashes to RPC clients
  • Loading branch information
Howard Chu authored and hyc committed Oct 1, 2019
1 parent b60cf6a commit fe0b7f4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/crypto/rx-slow-hash.c
Expand Up @@ -243,14 +243,17 @@ void rx_slow_hash(const uint64_t mainheight, const uint64_t seedheight, const ch
CTHR_MUTEX_LOCK(rx_mutex);

/* if alt block but with same seed as mainchain, no need for alt cache */
if (is_alt && s_height == seedheight && !memcmp(rx_s[toggle].rs_hash, seedhash, sizeof(rx_s[toggle].rs_hash)))
is_alt = 0;

if (is_alt) {
if (s_height == seedheight && !memcmp(rx_s[toggle].rs_hash, seedhash, sizeof(rx_s[toggle].rs_hash)))
is_alt = 0;
else
toggle ^= 1;
} else {
/* RPC could request an earlier block on mainchain */
if (!is_alt && s_height > seedheight)
is_alt = 1;
if (s_height > seedheight)
is_alt = 1;
}

toggle ^= (is_alt != 0);
if (toggle != rx_toggle)
changed = 1;
rx_toggle = toggle;
Expand Down

0 comments on commit fe0b7f4

Please sign in to comment.