From 9e3ab9b3aff21c6e5ef8b7290df1ad079a24ab6e Mon Sep 17 00:00:00 2001 From: evalir Date: Wed, 3 Jan 2024 19:56:03 -0400 Subject: [PATCH] chore: fix some docs (#6701) --- crates/evm/core/src/backend/in_memory_db.rs | 12 +++++++++--- crates/evm/core/src/backend/mod.rs | 12 ++++++------ crates/evm/evm/src/executors/mod.rs | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/crates/evm/core/src/backend/in_memory_db.rs b/crates/evm/core/src/backend/in_memory_db.rs index b27bbe750cc7..3b19d0fce00f 100644 --- a/crates/evm/core/src/backend/in_memory_db.rs +++ b/crates/evm/core/src/backend/in_memory_db.rs @@ -84,9 +84,12 @@ impl DatabaseCommit for MemDb { /// `DbAccount`, this will be set to `AccountState::NotExisting` if the account does not exist yet. /// This is because there's a distinction between "non-existing" and "empty", /// see . -/// If an account is `NotExisting`, `Database(Ref)::basic` will always return `None` for the -/// requested `AccountInfo`. To prevent this, we ensure that a missing account is never marked as -/// `NotExisting` by always returning `Some` with this type. +/// If an account is `NotExisting`, `Database::basic_ref` will always return `None` for the +/// requested `AccountInfo`. +/// +/// To prevent this, we ensure that a missing account is never marked as `NotExisting` by always +/// returning `Some` with this type, which will then insert a default [`AccountInfo`] instead +/// of one marked as `AccountState::NotExisting`. #[derive(Clone, Debug, Default)] pub struct EmptyDBWrapper(EmptyDB); @@ -143,6 +146,7 @@ mod tests { let mut db = CacheDB::new(EmptyDB::default()); let address = Address::random(); + // We use `basic_ref` here to ensure that the account is not marked as `NotExisting`. let info = DatabaseRef::basic_ref(&db, address).unwrap(); assert!(info.is_none()); let mut info = info.unwrap_or_default(); @@ -165,6 +169,8 @@ mod tests { )); let info = Database::basic(&mut db, address).unwrap(); + // We know info exists, as MemDb always returns `Some(AccountInfo)` due to the + // `EmptyDbWrapper`. assert!(info.is_some()); let mut info = info.unwrap(); info.balance = U256::from(500u64); diff --git a/crates/evm/core/src/backend/mod.rs b/crates/evm/core/src/backend/mod.rs index 35a56371680c..3ba7dea53ef1 100644 --- a/crates/evm/core/src/backend/mod.rs +++ b/crates/evm/core/src/backend/mod.rs @@ -69,8 +69,8 @@ pub trait DatabaseExt: Database { /// Creates a new snapshot at the current point of execution. /// /// A snapshot is associated with a new unique id that's created for the snapshot. - /// Snapshots can be reverted: [DatabaseExt::revert], however a snapshot can only be reverted - /// once. After a successful revert, the same snapshot id cannot be used again. + /// Snapshots can be reverted: [DatabaseExt::revert], however, depending on the + /// [RevertSnapshotAction], it will keep the snapshot alive or delete it. fn snapshot(&mut self, journaled_state: &JournaledState, env: &Env) -> U256; /// Reverts the snapshot if it exists @@ -204,21 +204,21 @@ pub trait DatabaseExt: Database { /// Returns the Fork url that's currently used in the database, if fork mode is on fn active_fork_url(&self) -> Option; - /// Whether the database is currently in forked + /// Whether the database is currently in forked mode. fn is_forked_mode(&self) -> bool { self.active_fork_id().is_some() } - /// Ensures that an appropriate fork exits + /// Ensures that an appropriate fork exists /// - /// If `id` contains a requested `Fork` this will ensure it exits. + /// If `id` contains a requested `Fork` this will ensure it exists. /// Otherwise, this returns the currently active fork. /// /// # Errors /// /// Returns an error if the given `id` does not match any forks /// - /// Returns an error if no fork exits + /// Returns an error if no fork exists fn ensure_fork(&self, id: Option) -> eyre::Result; /// Ensures that a corresponding `ForkId` exists for the given local `id` diff --git a/crates/evm/evm/src/executors/mod.rs b/crates/evm/evm/src/executors/mod.rs index 05838560bdb0..863de256d976 100644 --- a/crates/evm/evm/src/executors/mod.rs +++ b/crates/evm/evm/src/executors/mod.rs @@ -2,7 +2,7 @@ //! //! Used for running tests, scripts, and interacting with the inner backend which holds the state. -// TODO: The individual executors in this module should be moved into the respective craits, and the +// TODO: The individual executors in this module should be moved into the respective crates, and the // `Executor` struct should be accessed using a trait defined in `foundry-evm-core` instead of // the concrete `Executor` type.