diff --git a/crates/database/interface/src/lib.rs b/crates/database/interface/src/lib.rs index 7a4469d09d..533fb301ae 100644 --- a/crates/database/interface/src/lib.rs +++ b/crates/database/interface/src/lib.rs @@ -12,10 +12,12 @@ use state::{Account, AccountInfo, Bytecode}; #[cfg(feature = "asyncdb")] pub mod async_db; pub mod empty_db; +pub mod try_commit; #[cfg(feature = "asyncdb")] pub use async_db::{DatabaseAsync, WrapDatabaseAsync}; pub use empty_db::{EmptyDB, EmptyDBTyped}; +pub use try_commit::{ArcUpgradeError, TryDatabaseCommit}; /// EVM database interface. #[auto_impl(&mut, Box)] diff --git a/crates/database/interface/src/try_commit.rs b/crates/database/interface/src/try_commit.rs new file mode 100644 index 0000000000..9a6b39c33b --- /dev/null +++ b/crates/database/interface/src/try_commit.rs @@ -0,0 +1,84 @@ +use crate::DatabaseCommit; +use core::{convert::Infallible, error::Error, fmt}; +use primitives::{Address, HashMap}; +use state::Account; +use std::sync::Arc; + +/// EVM database commit interface that can fail. +/// +/// This is intended for use with types that may fail to commit changes, e.g. +/// because they are directly interacting with the filesystem, or must arrange +/// access to a shared resource. +pub trait TryDatabaseCommit { + /// Error type for when [`TryDatabaseCommit::try_commit`] fails. + type Error: Error; + + /// Attempt to commit changes to the database. + fn try_commit(&mut self, changes: HashMap
) -> Result<(), Self::Error>; +} + +impl