Skip to main content

RandomXDataset

Struct RandomXDataset 

Source
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

Source

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.

Source

pub fn count() -> Result<u32, RandomXError>

Returns the number of items in the dataset or an error on failure.

Source

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

Source§

fn clone(&self) -> RandomXDataset

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RandomXDataset

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.