Skip to content

Make DatabaseStorageRoot stateful #15479

@Rjected

Description

@Rjected

Describe the feature

Right now DatabaseStorageRoot has an associated TX type and takes &'a Self::TX on every method:

/// Extends [`StorageRoot`] with operations specific for working with a database transaction.
pub trait DatabaseStorageRoot<'a, TX> {
/// Create a new storage root calculator from database transaction and raw address.
fn from_tx(tx: &'a TX, address: Address) -> Self;
/// Create a new storage root calculator from database transaction and hashed address.
fn from_tx_hashed(tx: &'a TX, hashed_address: B256) -> Self;
/// Calculates the storage root for this [`HashedStorage`] and returns it.
fn overlay_root(
tx: &'a TX,
address: Address,
hashed_storage: HashedStorage,
) -> Result<B256, StorageRootError>;
}

This is not necessary, instead we can make this into a regular trait that is stateful and takes &self. For example it would look like:

/// Extends [`StorageRoot`] with operations specific for working with a database transaction.
pub trait DatabaseStorageRoot {
    /// Create a new storage root calculator from database transaction and raw address.
    fn from_tx(&self, address: Address) -> Self;

    /// Create a new storage root calculator from database transaction and hashed address.
    fn from_tx_hashed(&self, hashed_address: B256) -> Self;

    /// Calculates the storage root for this [`HashedStorage`] and returns it.
    fn overlay_root(
        &self,
        address: Address,
        hashed_storage: HashedStorage,
    ) -> Result<B256, StorageRootError>;
}

And the implementers can have a from_tx method on the struct itself

Additional context

No response

Metadata

Metadata

Labels

A-dbRelated to the databaseA-trieRelated to Merkle Patricia Trie implementationC-enhancementNew feature or requestD-good-first-issueNice and easy! A great choice to get started

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions