pub struct RandomXDataset { /* private fields */ }Expand description
The Dataset is a read-only memory structure that is used during VM program execution.
Implementations§
Source§impl RandomXDataset
impl RandomXDataset
Sourcepub fn new(
flags: RandomXFlag,
cache: RandomXCache,
start: u32,
) -> Result<RandomXDataset, RandomXError>
pub fn new( flags: RandomXFlag, cache: RandomXCache, start: u32, ) -> Result<RandomXDataset, RandomXError>
Creates a new dataset object, allocates memory to the dataset object and initializes it.
flags is one of the following:
- FLAG_DEFAULT
- FLAG_LARGE_PAGES
cache is a cache object.
start is the item number where initialization should start. Pass 0. The items
[start, RandomXDataset::count()) are initialized by the RandomX library; the leading start items are
zeroed, since the library never writes them.
§Warning
The RandomX API requires that every item from 0 to RandomXDataset::count() - 1 is initialized before a
dataset may be used (see the note on randomx_init_dataset in randomx.h). A non-zero start therefore
produces a dataset that does not satisfy that precondition and must not be passed to
RandomXVM::new or RandomXVM::reinit_dataset. Doing so is not detected or reported: the VM will read
the zeroed leading items as though they were real dataset items and silently compute hashes that disagree
with every other RandomX implementation.
The only legitimate use of a non-zero start in the upstream API is splitting the initialization of a single
shared dataset across several threads, each initializing a different item range. This wrapper cannot express
that, because new always allocates its own dataset, so there is no correct value other than 0.
Sourcepub fn count() -> Result<u32, RandomXError>
pub fn count() -> Result<u32, RandomXError>
Returns the number of items in the dataset or an error on failure.
Sourcepub fn get_data(&self) -> Result<Vec<u8>, RandomXError>
pub fn get_data(&self) -> Result<Vec<u8>, RandomXError>
Returns a copy of the entire internal memory buffer of the dataset, or an error on failure.
The returned buffer is RandomXDataset::count() items of RANDOMX_DATASET_ITEM_SIZE (64) bytes each, i.e.
approximately 2.03 GB with the default RandomX configuration. This is an expensive, fully allocating copy of
the dataset, so avoid calling it on a hot path. The allocation is fallible: an out-of-memory condition is
reported as a RandomXError instead of aborting the process.
If the dataset was created with a non-zero start, the first start items were never initialised by the
RandomX library; RandomXDataset::new zeroes them, so they are returned here as zero bytes.
Trait Implementations§
Source§impl Clone for RandomXDataset
impl Clone for RandomXDataset
Source§fn clone(&self) -> RandomXDataset
fn clone(&self) -> RandomXDataset
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more