Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper functions that would create JournalInit from JournaledState #1879 #1961

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions crates/context/src/journal_init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use super::journaled_state::JournaledState;
use database_interface::EmptyDB;

/// A clonable version of JournaledState that uses EmptyDB.
pub type JournalInit = JournaledState<EmptyDB>;

impl<DB> JournaledState<DB> {
pub fn into_init(self) -> JournalInit {
JournalInit {
database: EmptyDB::default(),
state: self.state,
transient_storage: self.transient_storage,
logs: self.logs,
depth: self.depth,
journal: self.journal,
spec: self.spec,
warm_preloaded_addresses: self.warm_preloaded_addresses,
precompiles: self.precompiles,
}
}

pub fn to_init(&self) -> JournalInit {
JournalInit {
database: EmptyDB::default(),
state: self.state.clone(),
transient_storage: self.transient_storage.clone(),
logs: self.logs.clone(),
depth: self.depth,
journal: self.journal.clone(),
spec: self.spec,
warm_preloaded_addresses: self.warm_preloaded_addresses.clone(),
precompiles: self.precompiles.clone(),
}
}
}
19 changes: 19 additions & 0 deletions crates/context/src/journaled_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use state::{Account, EvmState, EvmStorageSlot, TransientStorage};
use core::mem;
use std::{vec, vec::Vec};

use crate::JournalInit;

/// A journal of state changes internal to the EVM
///
/// On each additional call, the depth of the journaled state is increased (`depth`) and a new journal is added.
Expand Down Expand Up @@ -1045,3 +1047,20 @@ pub enum JournalEntry {
/// Revert: Revert to previous bytecode.
CodeChange { address: Address },
}

impl<DB> JournaledState<DB> {
/// Initialize a new JournaledState from JournalInit with a database
pub fn from_init(init: &JournalInit, database: DB) -> Self {
Self {
database,
state: init.state.clone(),
transient_storage: init.transient_storage.clone(),
logs: init.logs.clone(),
depth: init.depth,
journal: init.journal.clone(),
spec: init.spec,
warm_preloaded_addresses: init.warm_preloaded_addresses.clone(),
precompiles: init.precompiles.clone(),
}
}
}
2 changes: 2 additions & 0 deletions crates/context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ extern crate alloc as std;
pub mod block;
pub mod cfg;
pub mod context;
mod journal_init;
pub mod journaled_state;
pub mod tx;

pub use block::BlockEnv;
pub use cfg::{Cfg, CfgEnv};
pub use context::*;
pub use journal_init::JournalInit;
pub use journaled_state::*;
pub use tx::TxEnv;
Loading