Skip to content

Commit

Permalink
docs: update Backend and MultiFork docs (#8229)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Jun 22, 2024
1 parent 0c3657e commit 43eb061
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
10 changes: 8 additions & 2 deletions crates/evm/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ struct _ObjectSafe(dyn DatabaseExt);
/// snapshot is created before fork `B` is selected, then fork `A` will be the active fork again
/// after reverting the snapshot.
#[derive(Clone, Debug)]
#[must_use]
pub struct Backend {
/// The access point for managing forks
forks: MultiFork,
Expand Down Expand Up @@ -417,14 +418,19 @@ pub struct Backend {

impl Backend {
/// Creates a new Backend with a spawned multi fork thread.
///
/// If `fork` is `Some` this will use a `fork` database, otherwise with an in-memory
/// database.
pub fn spawn(fork: Option<CreateFork>) -> Self {
Self::new(MultiFork::spawn(), fork)
}

/// Creates a new instance of `Backend`
///
/// if `fork` is `Some` this will launch with a `fork` database, otherwise with an in-memory
/// database
/// If `fork` is `Some` this will use a `fork` database, otherwise with an in-memory
/// database.
///
/// Prefer using [`spawn`](Self::spawn) instead.
pub fn new(forks: MultiFork, fork: Option<CreateFork>) -> Self {
trace!(target: "backend", forking_mode=?fork.is_some(), "creating executor backend");
// Note: this will take of registering the `fork`
Expand Down
18 changes: 11 additions & 7 deletions crates/evm/core/src/fork/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl<T: Into<String>> From<T> for ForkId {
/// The Sender half of multi fork pair.
/// Can send requests to the `MultiForkHandler` to create forks
#[derive(Clone, Debug)]
#[must_use]
pub struct MultiFork {
/// Channel to send `Request`s to the handler
handler: Sender<Request>,
Expand All @@ -73,13 +74,6 @@ pub struct MultiFork {
}

impl MultiFork {
/// Creates a new pair multi fork pair
pub fn new() -> (Self, MultiForkHandler) {
let (handler, handler_rx) = channel(1);
let _shutdown = Arc::new(ShutDownMultiFork { handler: Some(handler.clone()) });
(Self { handler, _shutdown }, MultiForkHandler::new(handler_rx))
}

/// Creates a new pair and spawns the `MultiForkHandler` on a background thread.
pub fn spawn() -> Self {
trace!(target: "fork::multi", "spawning multifork");
Expand Down Expand Up @@ -109,6 +103,16 @@ impl MultiFork {
fork
}

/// Creates a new pair multi fork pair.
///
/// Use [`spawn`](Self::spawn) instead.
#[doc(hidden)]
pub fn new() -> (Self, MultiForkHandler) {
let (handler, handler_rx) = channel(1);
let _shutdown = Arc::new(ShutDownMultiFork { handler: Some(handler.clone()) });
(Self { handler, _shutdown }, MultiForkHandler::new(handler_rx))
}

/// Returns a fork backend
///
/// If no matching fork backend exists it will be created
Expand Down

0 comments on commit 43eb061

Please sign in to comment.