reth_trie_common/bundle_state/changes.rs
1use super::RevertToSlot;
2use alloc::vec::Vec;
3use alloy_primitives::{Address, B256, U256};
4use evm2::{bytecode::Bytecode, evm::AccountInfo};
5
6/// `accounts`/`storages`/`contracts` for inclusion into database.
7///
8/// Structure is made so it is easier to apply directly to database
9/// that mostly have separate tables to store `accounts`/`storages`/`contracts` data.
10///
11/// **Note**: That data is **not** sorted. Some database benefit of faster inclusion
12/// and smaller footprint if data is inserted in sorted order.
13#[derive(Clone, Debug, Default)]
14pub struct StateChangeset {
15 /// Vector of **not** sorted accounts information.
16 pub accounts: Vec<(Address, Option<AccountInfo>)>,
17 /// Vector of **not** sorted storage.
18 pub storage: Vec<PlainStorageChangeset>,
19 /// Vector of contracts by bytecode hash. **not** sorted.
20 pub contracts: Vec<(B256, Bytecode)>,
21}
22
23/// Plain storage changeset.
24///
25/// Used to apply storage changes of plain state to the database.
26#[derive(Clone, Debug, PartialEq, Eq, Default)]
27pub struct PlainStorageChangeset {
28 /// Address of account
29 pub address: Address,
30 /// Wipe storage
31 pub wipe_storage: bool,
32 /// Storage key value pairs
33 pub storage: Vec<(U256, U256)>,
34}
35
36/// Plain Storage Revert.
37///
38/// [`PlainStorageRevert`] contains old values of changed storage.
39#[derive(Clone, Debug, PartialEq, Eq, Default)]
40pub struct PlainStorageRevert {
41 /// Address of account
42 pub address: Address,
43 /// Whether storage is wiped in this revert
44 ///
45 /// **Note**: Wiped flag is set on first known selfdestruct and would require clearing the
46 /// state of this storage from database (And moving it to revert).
47 pub wiped: bool,
48 /// Contains the storage key and old values of that storage
49 ///
50 /// **Note**: Reverts are **not** sorted.
51 pub storage_revert: Vec<(U256, RevertToSlot)>,
52}
53
54/// Plain state reverts are used to easily store reverts into database.
55///
56/// Note that accounts are assumed **not** sorted.
57#[derive(Clone, Debug, Default)]
58pub struct PlainStateReverts {
59 /// Vector of account with removed contracts bytecode.
60 ///
61 /// **Note**: If AccountInfo is None means that account needs to be removed.
62 pub accounts: Vec<Vec<(Address, Option<AccountInfo>)>>,
63 /// Vector of storage with its address.
64 pub storage: Vec<Vec<PlainStorageRevert>>,
65}
66
67impl PlainStateReverts {
68 /// Constructs new [`PlainStateReverts`] with pre-allocated capacity.
69 pub fn with_capacity(capacity: usize) -> Self {
70 Self { accounts: Vec::with_capacity(capacity), storage: Vec::with_capacity(capacity) }
71 }
72}
73
74/// Storage reverts
75pub type StorageRevert = Vec<Vec<(Address, bool, Vec<(U256, RevertToSlot)>)>>;