fn create(key: &[u8], flags: RandomXFlag) -> Result<Self, RandomXError> {
        let (flags, cache) = 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 dataset = RandomXDataset::new(flags, &cache, 0)?;
        let vm = RandomXVM::new(flags, Some(&cache), Some(&dataset))?;

        Ok(Self {
            instance: Arc::new(Mutex::new((vm, cache, dataset))),
            flags,
        })
    }
// Note: Can maybe even get more gains by creating a new VM and sharing the dataset and cache
Can maybe even get more gains by creating a new VM and sharing the dataset and cache
Can maybe even get more gains by creating a new VM and sharing the dataset and cache
fn create(key: &[u8], flags: RandomXFlag) -> Result<Self, RandomXError> {
        let (flags, cache) = 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 dataset = RandomXDataset::new(flags, &cache, 0)?;
        let vm = RandomXVM::new(flags, Some(&cache), Some(&dataset))?;
        Ok(Self {
            instance: Arc::new(Mutex::new((vm, cache, dataset))),
            flags,
        })
    }
fn create ( key : & [ u8 ] , flags : RandomXFlag ) -> Result < Self , RandomXError > { let ( flags , cache ) = match RandomXCache :: new ( flags , key ) { Ok ( cache ) => ( flags , cache ) , Err ( err ) => { warn ! ( target LOG_TARGET " " 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 dataset = RandomXDataset :: new ( flags , & cache , 0 ) ? ; let vm = RandomXVM :: new ( flags , Some ( & cache ) , Some ( & dataset ) ) ? ; Ok ( Self { instance : Arc :: new ( Mutex :: new ( ( vm , cache , dataset ) ) ) , flags , } ) }
Note: Can maybe even get more gains by creating a new VM and sharing the dataset and cache
Note : Can maybe even get more gains by creating a new VM and sharing the dataset and cache
key
&[u8]
flags
RandomXFlag
key
&[u8]
flags
RandomXFlag