Skip to content

Commit

Permalink
fix: randomX on mac x86 (tari-project#6559)
Browse files Browse the repository at this point in the history
Description
---
Randomx on Mac using x86 fails with the recommended flags and requires
fallback to the default flags.
  • Loading branch information
SWvheerden committed Sep 12, 2024
1 parent 7bc4c95 commit 2278b3f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions base_layer/core/src/proof_of_work/randomx_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,24 @@ impl RandomXVMInstance {
dataset: Option<RandomXDataset>,
) -> Result<Self, RandomXVMFactoryError> {
// Note: Memory required per VM in light mode is 256MB

// Note: RandomXFlag::FULL_MEM and RandomXFlag::LARGE_PAGES are incompatible with
// light mode. These are not set by RandomX automatically even in fast mode.
let cache = match cache {
Some(c) => c,
None => RandomXCache::new(flags, key)?,
let (flags, cache) = match cache {
Some(c) => (flags, c),
None => match RandomXCache::new(flags, key) {
Ok(cache) => (flags, cache),
Err(err) => {
warn!(
target: LOG_TARGET,
"Error initializing RandomX cache with flags {:?}. {:?}. Fallback to default flags", flags, err
);
// This is informed by how RandomX falls back on any cache allocation failure
// https://github.com/xmrig/xmrig/blob/02b2b87bb685ab83b132267aa3c2de0766f16b8b/src/crypto/rx/RxCache.cpp#L88
let flags = RandomXFlag::FLAG_DEFAULT;
let cache = RandomXCache::new(flags, key)?;
(flags, cache)
},
},
};
let vm = RandomXVM::new(flags, Some(cache), dataset)?;

Expand Down

0 comments on commit 2278b3f

Please sign in to comment.