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