Skip to content

Commit

Permalink
fix: reset tstorage on finalize (bluealloy#1168)
Browse files Browse the repository at this point in the history
* fix: reset tstorage on finalize

* destruct Self

* change order

* Update crates/revm/src/journaled_state.rs
  • Loading branch information
mattsse authored and fubuloubu committed Apr 11, 2024
1 parent 49b98bb commit 411fdd3
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions crates/revm/src/journaled_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::vec::Vec;
pub struct JournaledState {
/// Current state.
pub state: State,
/// EIP 1153 transient storage
/// [EIP-1153[(https://eips.ethereum.org/EIPS/eip-1153) transient storage that is discarded after every transactions
pub transient_storage: TransientStorage,
/// logs
pub logs: Vec<Log>,
Expand Down Expand Up @@ -92,12 +92,27 @@ impl JournaledState {
}

/// Does cleanup and returns modified state.
///
/// This resets the [JournaledState] to its initial state in [Self::new]
#[inline]
pub fn finalize(&mut self) -> (State, Vec<Log>) {
let state = mem::take(&mut self.state);
let logs = mem::take(&mut self.logs);
self.journal = vec![vec![]];
self.depth = 0;
let Self {
state,
transient_storage,
logs,
depth,
journal,
// kept, see [Self::new]
spec: _,
warm_preloaded_addresses: _,
} = self;

*transient_storage = TransientStorage::default();
*journal = vec![vec![]];
*depth = 0;
let state = mem::take(state);
let logs = mem::take(logs);

(state, logs)
}

Expand Down

0 comments on commit 411fdd3

Please sign in to comment.