Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
remove BundleStateInit, AccountRevertInit, and RevertInit
  • Loading branch information
quentinv72 committed Jun 16, 2024
commit 9b212d64a8b3e24e9838de716d01a2b88fa4813c
91 changes: 3 additions & 88 deletions crates/evm/execution-types/src/execution_outcome.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use reth_primitives::{
logs_bloom,
revm::compat::{into_reth_acc, into_revm_acc},
Account, Address, BlockNumber, Bloom, Bytecode, Log, Receipt, Receipts, Requests, StorageEntry,
B256, U256,
logs_bloom, revm::compat::into_reth_acc, Account, Address, BlockNumber, Bloom, Bytecode, Log,
Receipt, Receipts, Requests, B256, U256,
};
use reth_trie::HashedPostState;
use revm::{
db::{states::BundleState, BundleAccount},
primitives::AccountInfo,
};
use std::collections::HashMap;

/// Represents the outcome of block execution, including post-execution changes and reverts.
///
Expand All @@ -36,16 +33,6 @@ pub struct ExecutionOutcome {
pub requests: Vec<Requests>,
}

/// Type used to initialize revms bundle state.
pub type BundleStateInit =
HashMap<Address, (Option<Account>, Option<Account>, HashMap<B256, (U256, U256)>)>;

/// Types used inside `RevertsInit` to initialize revms reverts.
pub type AccountRevertInit = (Option<Option<Account>>, Vec<StorageEntry>);

/// Type used to initialize revms reverts.
pub type RevertsInit = HashMap<BlockNumber, HashMap<Address, AccountRevertInit>>;

impl ExecutionOutcome {
/// Creates a new `ExecutionOutcome`.
///
Expand All @@ -60,48 +47,6 @@ impl ExecutionOutcome {
Self { bundle, receipts, first_block, requests }
}

/// Creates a new `ExecutionOutcome` from initialization parameters.
///
/// This constructor initializes a new `ExecutionOutcome` instance using detailed
/// initialization parameters.
pub fn new_init(
state_init: BundleStateInit,
revert_init: RevertsInit,
contracts_init: Vec<(B256, Bytecode)>,
receipts: Receipts,
first_block: BlockNumber,
requests: Vec<Requests>,
) -> Self {
// sort reverts by block number
let mut reverts = revert_init.into_iter().collect::<Vec<_>>();
reverts.sort_unstable_by_key(|a| a.0);

// initialize revm bundle
let bundle = BundleState::new(
state_init.into_iter().map(|(address, (original, present, storage))| {
(
address,
original.map(into_revm_acc),
present.map(into_revm_acc),
storage.into_iter().map(|(k, s)| (k.into(), s)).collect(),
)
}),
reverts.into_iter().map(|(_, reverts)| {
// does not needs to be sorted, it is done when taking reverts.
reverts.into_iter().map(|(address, (original, storage))| {
(
address,
original.map(|i| i.map(into_revm_acc)),
storage.into_iter().map(|entry| (entry.key.into(), entry.value)),
)
})
}),
contracts_init.into_iter().map(|(code_hash, bytecode)| (code_hash, bytecode.0)),
);

Self { bundle, receipts, first_block, requests }
}

/// Return revm bundle state.
pub const fn state(&self) -> &BundleState {
&self.bundle
Expand Down Expand Up @@ -395,37 +340,7 @@ mod tests {
};

// Assert that creating a new ExecutionOutcome using the constructor matches exec_res
assert_eq!(
ExecutionOutcome::new(bundle, receipts.clone(), first_block, requests.clone()),
exec_res
);

// Create a BundleStateInit object and insert initial data
let mut state_init: BundleStateInit = HashMap::new();
state_init
.insert(Address::new([2; 20]), (None, Some(Account::default()), HashMap::default()));

// Create a HashMap for account reverts and insert initial data
let mut revert_inner: HashMap<Address, AccountRevertInit> = HashMap::new();
revert_inner.insert(Address::new([2; 20]), (None, vec![]));

// Create a RevertsInit object and insert the revert_inner data
let mut revert_init: RevertsInit = HashMap::new();
revert_init.insert(123, revert_inner);

// Assert that creating a new ExecutionOutcome using the new_init method matches
// exec_res
assert_eq!(
ExecutionOutcome::new_init(
state_init,
revert_init,
vec![],
receipts,
first_block,
requests,
),
exec_res
);
assert_eq!(ExecutionOutcome::new(bundle, receipts, first_block, requests), exec_res);
}

#[test]
Expand Down
4 changes: 1 addition & 3 deletions crates/storage/provider/src/bundle_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ mod hashed_state_changes;
mod state_changes;
mod state_reverts;

pub use bundle_state_with_receipts::{
AccountRevertInit, BundleStateInit, ExecutionOutcome, OriginalValuesKnown, RevertsInit,
};
pub use bundle_state_with_receipts::{ExecutionOutcome, OriginalValuesKnown};
pub use hashed_state_changes::HashedStateChanges;
pub use state_changes::StateChanges;
pub use state_reverts::{StateReverts, StorageRevertsIter};