remove lifetime param in storage trait (#5046)

This commit is contained in:
robinsdan
2023-10-17 21:30:50 +08:00
committed by GitHub
parent d3ea66bb79
commit ede8278916
29 changed files with 212 additions and 303 deletions

View File

@ -6,7 +6,7 @@ use reth_db::{
};
use reth_primitives::{Account, StorageEntry, B256};
impl<'a, 'tx, TX: DbTx<'tx>> HashedCursorFactory for &'a TX {
impl<'a, TX: DbTx> HashedCursorFactory for &'a TX {
type AccountCursor = <TX as DbTxGAT<'a>>::Cursor<tables::HashedAccount>;
type StorageCursor = <TX as DbTxGAT<'a>>::DupCursor<tables::HashedStorage>;
@ -19,9 +19,9 @@ impl<'a, 'tx, TX: DbTx<'tx>> HashedCursorFactory for &'a TX {
}
}
impl<'tx, C> HashedAccountCursor for C
impl<C> HashedAccountCursor for C
where
C: DbCursorRO<'tx, tables::HashedAccount>,
C: DbCursorRO<tables::HashedAccount>,
{
fn seek(&mut self, key: B256) -> Result<Option<(B256, Account)>, reth_db::DatabaseError> {
self.seek(key)
@ -32,9 +32,9 @@ where
}
}
impl<'tx, C> HashedStorageCursor for C
impl<C> HashedStorageCursor for C
where
C: DbCursorRO<'tx, tables::HashedStorage> + DbDupCursorRO<'tx, tables::HashedStorage>,
C: DbCursorRO<tables::HashedStorage> + DbDupCursorRO<tables::HashedStorage>,
{
fn is_storage_empty(&mut self, key: B256) -> Result<bool, reth_db::DatabaseError> {
Ok(self.seek_exact(key)?.is_none())

View File

@ -169,7 +169,7 @@ impl<'a, 'b, TX> HashedPostStateCursorFactory<'a, 'b, TX> {
}
}
impl<'a, 'b, 'tx, TX: DbTx<'tx>> HashedCursorFactory for HashedPostStateCursorFactory<'a, 'b, TX> {
impl<'a, 'b, TX: DbTx> HashedCursorFactory for HashedPostStateCursorFactory<'a, 'b, TX> {
type AccountCursor =
HashedPostStateAccountCursor<'b, <TX as DbTxGAT<'a>>::Cursor<tables::HashedAccount>>;
type StorageCursor =
@ -246,9 +246,9 @@ impl<'b, C> HashedPostStateAccountCursor<'b, C> {
}
}
impl<'b, 'tx, C> HashedAccountCursor for HashedPostStateAccountCursor<'b, C>
impl<'b, C> HashedAccountCursor for HashedPostStateAccountCursor<'b, C>
where
C: DbCursorRO<'tx, tables::HashedAccount>,
C: DbCursorRO<tables::HashedAccount>,
{
/// Seek the next entry for a given hashed account key.
///
@ -408,9 +408,9 @@ impl<'b, C> HashedPostStateStorageCursor<'b, C> {
}
}
impl<'b, 'tx, C> HashedStorageCursor for HashedPostStateStorageCursor<'b, C>
impl<'b, C> HashedStorageCursor for HashedPostStateStorageCursor<'b, C>
where
C: DbCursorRO<'tx, tables::HashedStorage> + DbDupCursorRO<'tx, tables::HashedStorage>,
C: DbCursorRO<tables::HashedStorage> + DbDupCursorRO<tables::HashedStorage>,
{
/// Returns `true` if the account has no storage entries.
///

View File

@ -35,10 +35,7 @@ impl<'a, TX> PrefixSetLoader<'a, TX> {
}
}
impl<'a, 'b, TX> PrefixSetLoader<'a, TX>
where
TX: DbTx<'b>,
{
impl<'a, TX: DbTx> PrefixSetLoader<'a, TX> {
/// Load all account and storage changes for the given block range.
pub fn load(
self,

View File

@ -35,9 +35,9 @@ impl<'a, TX> Proof<'a, TX, &'a TX> {
}
}
impl<'a, 'tx, TX, H> Proof<'a, TX, H>
impl<'a, TX, H> Proof<'a, TX, H>
where
TX: DbTx<'tx>,
TX: DbTx,
H: HashedCursorFactory + Clone,
{
/// Generate an account proof from intermediate nodes.

View File

@ -95,10 +95,7 @@ impl<'a, TX, H> StateRoot<'a, TX, H> {
}
}
impl<'a, 'tx, TX> StateRoot<'a, TX, &'a TX>
where
TX: DbTx<'tx>,
{
impl<'a, TX: DbTx> StateRoot<'a, TX, &'a TX> {
/// Create a new [StateRoot] instance.
pub fn new(tx: &'a TX) -> Self {
Self {
@ -180,9 +177,9 @@ where
}
}
impl<'a, 'tx, TX, H> StateRoot<'a, TX, H>
impl<'a, TX, H> StateRoot<'a, TX, H>
where
TX: DbTx<'tx>,
TX: DbTx,
H: HashedCursorFactory + Clone,
{
/// Walks the intermediate nodes of existing state trie (if any) and hashed entries. Feeds the
@ -381,10 +378,7 @@ pub struct StorageRoot<'a, TX, H> {
pub changed_prefixes: PrefixSet,
}
impl<'a, 'tx, TX> StorageRoot<'a, TX, &'a TX>
where
TX: DbTx<'tx>,
{
impl<'a, TX: DbTx> StorageRoot<'a, TX, &'a TX> {
/// Creates a new storage root calculator given an raw address.
pub fn new(tx: &'a TX, address: Address) -> Self {
Self::new_hashed(tx, keccak256(address))
@ -441,9 +435,9 @@ impl<'a, TX, H> StorageRoot<'a, TX, H> {
}
}
impl<'a, 'tx, TX, H> StorageRoot<'a, TX, H>
impl<'a, TX, H> StorageRoot<'a, TX, H>
where
TX: DbTx<'tx>,
TX: DbTx,
H: HashedCursorFactory,
{
/// Walks the hashed storage table entries for a given address and calculates the storage root.
@ -559,8 +553,8 @@ mod tests {
use reth_provider::{DatabaseProviderRW, ProviderFactory};
use std::{collections::BTreeMap, ops::Mul, str::FromStr};
fn insert_account<'a, TX: DbTxMut<'a>>(
tx: &TX,
fn insert_account(
tx: &impl DbTxMut,
address: Address,
account: Account,
storage: &BTreeMap<B256, U256>,
@ -570,11 +564,7 @@ mod tests {
insert_storage(tx, hashed_address, storage);
}
fn insert_storage<'a, TX: DbTxMut<'a>>(
tx: &TX,
hashed_address: B256,
storage: &BTreeMap<B256, U256>,
) {
fn insert_storage(tx: &impl DbTxMut, hashed_address: B256, storage: &BTreeMap<B256, U256>) {
for (k, v) in storage {
tx.put::<tables::HashedStorage>(
hashed_address,

View File

@ -14,9 +14,9 @@ impl<C> AccountTrieCursor<C> {
}
}
impl<'a, C> TrieCursor<StoredNibbles> for AccountTrieCursor<C>
impl<C> TrieCursor<StoredNibbles> for AccountTrieCursor<C>
where
C: DbCursorRO<'a, tables::AccountsTrie>,
C: DbCursorRO<tables::AccountsTrie>,
{
fn seek_exact(
&mut self,

View File

@ -24,9 +24,9 @@ impl<C> StorageTrieCursor<C> {
}
}
impl<'a, C> TrieCursor<StoredNibblesSubKey> for StorageTrieCursor<C>
impl<C> TrieCursor<StoredNibblesSubKey> for StorageTrieCursor<C>
where
C: DbDupCursorRO<'a, tables::StoragesTrie> + DbCursorRO<'a, tables::StoragesTrie>,
C: DbDupCursorRO<tables::StoragesTrie> + DbCursorRO<tables::StoragesTrie>,
{
fn seek_exact(
&mut self,

View File

@ -105,10 +105,7 @@ impl TrieUpdates {
}
/// Flush updates all aggregated updates to the database.
pub fn flush<'a, 'tx, TX>(self, tx: &'a TX) -> Result<(), reth_db::DatabaseError>
where
TX: DbTx<'tx> + DbTxMut<'tx>,
{
pub fn flush(self, tx: &(impl DbTx + DbTxMut)) -> Result<(), reth_db::DatabaseError> {
if self.trie_operations.is_empty() {
return Ok(())
}