mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-08 23:08:19 -05:00
do not use once_cell
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -9984,7 +9984,6 @@ dependencies = [
|
||||
"itertools 0.14.0",
|
||||
"metrics",
|
||||
"notify",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"rand 0.9.2",
|
||||
"rayon",
|
||||
|
||||
@@ -54,7 +54,6 @@ parking_lot.workspace = true
|
||||
dashmap = { workspace = true, features = ["inline"] }
|
||||
strum.workspace = true
|
||||
eyre.workspace = true
|
||||
once_cell.workspace = true
|
||||
|
||||
# test-utils
|
||||
reth-ethereum-engine-primitives = { workspace = true, optional = true }
|
||||
|
||||
@@ -33,7 +33,6 @@ use alloy_primitives::{
|
||||
Address, BlockHash, BlockNumber, TxHash, TxNumber, B256,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use once_cell::sync::OnceCell;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use rayon::slice::ParallelSliceMut;
|
||||
use reth_chain_state::ExecutedBlock;
|
||||
@@ -94,10 +93,10 @@ pub type DatabaseProviderRO<DB, N> = DatabaseProvider<<DB as Database>::TX, N>;
|
||||
|
||||
/// Cached cursor for plain storage state.
|
||||
pub(crate) type PlainStorageCursor<Tx> =
|
||||
Arc<OnceCell<Mutex<<Tx as DbTx>::DupCursor<tables::PlainStorageState>>>>;
|
||||
Arc<Mutex<Option<<Tx as DbTx>::DupCursor<tables::PlainStorageState>>>>;
|
||||
/// Cached cursor for storage changeset.
|
||||
pub(crate) type StorageChangesetCursor<Tx> =
|
||||
Arc<OnceCell<Mutex<<Tx as DbTx>::DupCursor<tables::StorageChangeSets>>>>;
|
||||
Arc<Mutex<Option<<Tx as DbTx>::DupCursor<tables::StorageChangeSets>>>>;
|
||||
|
||||
/// A [`DatabaseProvider`] that holds a read-write database transaction.
|
||||
///
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
};
|
||||
use alloy_eips::merge::EPOCH_SLOTS;
|
||||
use alloy_primitives::{Address, BlockNumber, Bytes, StorageKey, StorageValue, B256};
|
||||
use parking_lot::Mutex;
|
||||
use parking_lot::{MappedMutexGuard, MutexGuard};
|
||||
use reth_db_api::{
|
||||
cursor::{DbCursorRO, DbDupCursorRO},
|
||||
models::{storage_sharded_key::StorageShardedKey, ShardedKey},
|
||||
@@ -125,18 +125,30 @@ impl<'b, Provider: DBProvider + BlockNumReader> HistoricalStateProviderRef<'b, P
|
||||
|
||||
fn storage_changeset_cursor(
|
||||
&self,
|
||||
) -> ProviderResult<&Mutex<<Provider::Tx as DbTx>::DupCursor<tables::StorageChangeSets>>> {
|
||||
self.storage_changeset_cursor
|
||||
.get_or_try_init(|| self.provider.tx_ref().cursor_dup_read().map(Mutex::new))
|
||||
.map_err(Into::into)
|
||||
) -> ProviderResult<
|
||||
MappedMutexGuard<'_, <Provider::Tx as DbTx>::DupCursor<tables::StorageChangeSets>>,
|
||||
> {
|
||||
MutexGuard::try_map_or_err(self.storage_changeset_cursor.lock(), |cursor| {
|
||||
ProviderResult::Ok(match cursor {
|
||||
Some(cursor) => cursor,
|
||||
None => cursor.insert(self.provider.tx_ref().cursor_dup_read()?),
|
||||
})
|
||||
})
|
||||
.map_err(|(_, err)| err)
|
||||
}
|
||||
|
||||
fn plain_storage_cursor(
|
||||
&self,
|
||||
) -> ProviderResult<&Mutex<<Provider::Tx as DbTx>::DupCursor<tables::PlainStorageState>>> {
|
||||
self.plain_storage_cursor
|
||||
.get_or_try_init(|| self.provider.tx_ref().cursor_dup_read().map(Mutex::new))
|
||||
.map_err(Into::into)
|
||||
) -> ProviderResult<
|
||||
MappedMutexGuard<'_, <Provider::Tx as DbTx>::DupCursor<tables::PlainStorageState>>,
|
||||
> {
|
||||
MutexGuard::try_map_or_err(self.plain_storage_cursor.lock(), |cursor| {
|
||||
ProviderResult::Ok(match cursor {
|
||||
Some(cursor) => cursor,
|
||||
None => cursor.insert(self.provider.tx_ref().cursor_dup_read()?),
|
||||
})
|
||||
})
|
||||
.map_err(|(_, err)| err)
|
||||
}
|
||||
|
||||
/// Lookup an account in the `AccountsHistory` table
|
||||
@@ -481,7 +493,6 @@ impl<Provider: DBProvider + BlockNumReader + BlockHashReader + ChangeSetReader>
|
||||
HistoryInfo::InChangeset(changeset_block_number) => {
|
||||
let entry = self
|
||||
.storage_changeset_cursor()?
|
||||
.lock()
|
||||
.seek_by_key_subkey((changeset_block_number, address).into(), storage_key)?
|
||||
.filter(|entry| entry.key == storage_key);
|
||||
Ok(Some(
|
||||
@@ -497,7 +508,6 @@ impl<Provider: DBProvider + BlockNumReader + BlockHashReader + ChangeSetReader>
|
||||
HistoryInfo::InPlainState | HistoryInfo::MaybeInPlainState => {
|
||||
let entry = self
|
||||
.plain_storage_cursor()?
|
||||
.lock()
|
||||
.seek_by_key_subkey(address, storage_key)?
|
||||
.filter(|entry| entry.key == storage_key);
|
||||
Ok(entry.map(|e| e.value).or(Some(StorageValue::ZERO)))
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::{
|
||||
AccountReader, BlockHashReader, HashedPostStateProvider, StateProvider, StateRootProvider,
|
||||
};
|
||||
use alloy_primitives::{Address, BlockNumber, Bytes, StorageKey, StorageValue, B256};
|
||||
use parking_lot::Mutex;
|
||||
use parking_lot::{MappedMutexGuard, MutexGuard};
|
||||
use reth_db_api::{cursor::DbDupCursorRO, tables, transaction::DbTx};
|
||||
use reth_primitives_traits::{Account, Bytecode};
|
||||
use reth_storage_api::{BytecodeReader, DBProvider, StateProofProvider, StorageRootProvider};
|
||||
@@ -54,10 +54,16 @@ impl<'b, Provider: DBProvider> LatestStateProviderRef<'b, Provider> {
|
||||
|
||||
fn plain_storage_cursor(
|
||||
&self,
|
||||
) -> ProviderResult<&Mutex<<Provider::Tx as DbTx>::DupCursor<tables::PlainStorageState>>> {
|
||||
self.plain_storage_cursor
|
||||
.get_or_try_init(|| self.provider.tx_ref().cursor_dup_read().map(Mutex::new))
|
||||
.map_err(Into::into)
|
||||
) -> ProviderResult<
|
||||
MappedMutexGuard<'_, <Provider::Tx as DbTx>::DupCursor<tables::PlainStorageState>>,
|
||||
> {
|
||||
MutexGuard::try_map_or_err(self.plain_storage_cursor.lock(), |cursor| {
|
||||
ProviderResult::Ok(match cursor {
|
||||
Some(cursor) => cursor,
|
||||
None => cursor.insert(self.provider.tx_ref().cursor_dup_read()?),
|
||||
})
|
||||
})
|
||||
.map_err(|(_, err)| err)
|
||||
}
|
||||
|
||||
fn tx(&self) -> &Provider::Tx {
|
||||
@@ -194,7 +200,7 @@ impl<Provider: DBProvider + BlockHashReader> StateProvider
|
||||
storage_key: StorageKey,
|
||||
) -> ProviderResult<Option<StorageValue>> {
|
||||
if let Some(entry) =
|
||||
self.plain_storage_cursor()?.lock().seek_by_key_subkey(account, storage_key)? &&
|
||||
self.plain_storage_cursor()?.seek_by_key_subkey(account, storage_key)? &&
|
||||
entry.key == storage_key
|
||||
{
|
||||
return Ok(Some(entry.value))
|
||||
|
||||
Reference in New Issue
Block a user