pub struct RandomXVmCache {
pub seeds: VecDeque<(usize, [u8; 32])>,
pub vms: HashMap<usize, Arc<RandomXVm>>,
pub cached_vm: Option<([u8; 32], Arc<RandomXVm>)>,
}Expand description
The randomX VMs cache, keeps the VM needed to calculate the current block’s proof-of-work hash (if a VM is needed) and a couple more around this VM.
Fields§
§seeds: VecDeque<(usize, [u8; 32])>The top RX_SEEDS_CACHED RX seeds.
vms: HashMap<usize, Arc<RandomXVm>>The VMs for seeds (if after hf 12, otherwise this will be empty).
cached_vm: Option<([u8; 32], Arc<RandomXVm>)>A single cached VM that was given to us from a part of Cuprate.
Implementations§
Source§impl RandomXVmCache
impl RandomXVmCache
pub async fn init_from_chain_height<D: Database + Clone>( chain_height: usize, hf: &HardFork, database: D, ) -> Result<Self, ContextCacheError>
Sourcepub fn add_vm(&mut self, vm: ([u8; 32], Arc<RandomXVm>))
pub fn add_vm(&mut self, vm: ([u8; 32], Arc<RandomXVm>))
Add a randomX VM to the cache, with the seed it was created with.
Sourcepub async fn get_alt_vm<D: Database>(
&self,
height: usize,
chain: Chain,
database: D,
) -> Result<Arc<RandomXVm>, ContextCacheError>
pub async fn get_alt_vm<D: Database>( &self, height: usize, chain: Chain, database: D, ) -> Result<Arc<RandomXVm>, ContextCacheError>
Creates a RX VM for an alt chain, looking at the main chain RX VMs to see if we can use one of them first.
Sourcepub async fn get_vms(&mut self) -> HashMap<usize, Arc<RandomXVm>>
pub async fn get_vms(&mut self) -> HashMap<usize, Arc<RandomXVm>>
Get the main-chain RandomX VMs.
Sourcepub async fn pop_blocks_main_chain<D: Database + Clone>(
&mut self,
new_height: usize,
database: D,
) -> Result<(), ContextCacheError>
pub async fn pop_blocks_main_chain<D: Database + Clone>( &mut self, new_height: usize, database: D, ) -> Result<(), ContextCacheError>
Removes all the RandomX VMs above the new_height.
Trait Implementations§
Source§impl Clone for RandomXVmCache
impl Clone for RandomXVmCache
Source§fn clone(&self) -> RandomXVmCache
fn clone(&self) -> RandomXVmCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for RandomXVmCache
impl RefUnwindSafe for RandomXVmCache
impl Send for RandomXVmCache
impl Sync for RandomXVmCache
impl Unpin for RandomXVmCache
impl UnsafeUnpin for RandomXVmCache
impl UnwindSafe for RandomXVmCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 120 bytes