revm_database/states/
changes.rs

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