pub struct CachedReads {
pub accounts: AddressMap<CachedAccount>,
pub contracts: B256Map<Bytecode>,
pub block_hashes: HashMap<u64, B256>,
}Expand description
A container type that caches reads from an underlying Database.
This is intended to be used in conjunction with block executors and builders during payload building which repeatedly accesses the same data.
CachedReads::as_db_mut transforms this type into a Database implementation that uses
CachedReads as a caching layer for operations, and records any cache misses.
§Example
use evm2::evm::Database;
use reth_evm::cached::CachedReads;
fn build_payload<DB: Database>(db: DB) {
let mut cached_reads = CachedReads::default();
let db = cached_reads.as_db_mut(db);
// this is `Database` and can be used to build a payload, it never commits to `CachedReads` or the underlying database, but all reads from the underlying database are cached in `CachedReads`.
// Subsequent payload build attempts can use cached reads and avoid hitting the underlying database.
// Note: `cached_reads` must outlive `db` to satisfy lifetime requirements.
}Fields§
§accounts: AddressMap<CachedAccount>Block state account with storage.
contracts: B256Map<Bytecode>Created contracts.
block_hashes: HashMap<u64, B256>Block hash mapped to the block number.
Implementations§
Source§impl CachedReads
impl CachedReads
Sourcepub fn with_account_capacity(capacity: usize) -> Self
pub fn with_account_capacity(capacity: usize) -> Self
Creates a new CachedReads with capacity for account entries.
Sourcepub const fn as_db_mut<DB>(&mut self, db: DB) -> CachedReadsDbMut<'_, DB>
pub const fn as_db_mut<DB>(&mut self, db: DB) -> CachedReadsDbMut<'_, DB>
Gets a mutable Database that will cache reads from the underlying database.
Sourcepub fn insert_account(
&mut self,
address: Address,
info: AccountInfo,
storage: U256Map<U256>,
)
pub fn insert_account( &mut self, address: Address, info: AccountInfo, storage: U256Map<U256>, )
Inserts an account info into the cache.
Sourcepub fn extend(&mut self, other: Self)
pub fn extend(&mut self, other: Self)
Extends current cache with entries from another CachedReads instance.
Note: It is expected that both instances are based on the exact same state.
Trait Implementations§
Source§impl Clone for CachedReads
impl Clone for CachedReads
Source§impl Debug for CachedReads
impl Debug for CachedReads
Auto Trait Implementations§
impl Forget for CachedReads
impl Freeze for CachedReads
impl Move for CachedReads
impl RefUnwindSafe for CachedReads
impl Send for CachedReads
impl Sync for CachedReads
impl Unpin for CachedReads
impl UnsafeUnpin for CachedReads
impl UnwindSafe for CachedReads
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> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> 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 moreimpl<T> MaybeDebug for Twhere
T: Debug,
§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> ⓘ
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§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>,
Source§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