Skip to content

Commit

Permalink
chore: fix some docs (#6701)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evalir committed Jan 3, 2024
1 parent 47b3695 commit 9e3ab9b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
12 changes: 9 additions & 3 deletions crates/evm/core/src/backend/in_memory_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/bluealloy/revm/blob/8f4348dc93022cffb3730d9db5d3ab1aad77676a/crates/revm/src/db/in_memory_db.rs#L81-L83>.
/// 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);

Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions crates/evm/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ pub trait DatabaseExt: Database<Error = DatabaseError> {
/// 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
Expand Down Expand Up @@ -204,21 +204,21 @@ pub trait DatabaseExt: Database<Error = DatabaseError> {
/// Returns the Fork url that's currently used in the database, if fork mode is on
fn active_fork_url(&self) -> Option<String>;

/// 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<LocalForkId>) -> eyre::Result<LocalForkId>;

/// Ensures that a corresponding `ForkId` exists for the given local `id`
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/evm/src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 9e3ab9b

Please sign in to comment.