Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: update some docs related to state #1711

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions crates/revm/src/db/states/bundle_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,11 @@ impl BundleState {
self.contracts.get(hash).cloned()
}

/// Consume `TransitionState` by applying the changes and creating the reverts
/// Consume [`TransitionState`] by applying the changes and creating the
/// reverts.
///
/// If [BundleRetention::includes_reverts] is `true`, then the reverts will be retained.
/// If [BundleRetention::includes_reverts] is `true`, then the reverts will
/// be retained.
pub fn apply_transitions_and_create_reverts(
&mut self,
transitions: TransitionState,
Expand Down
17 changes: 10 additions & 7 deletions crates/revm/src/db/states/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ impl<DB: Database> State<DB> {
}
}

/// Get a mutable reference to the [`CacheAccount`] for the given address.
/// If the account is not found in the cache, it will be loaded from the
/// database and inserted into the cache.
pub fn load_cache_account(&mut self, address: Address) -> Result<&mut CacheAccount, DB::Error> {
match self.cache.accounts.entry(address) {
hash_map::Entry::Vacant(entry) => {
Expand Down Expand Up @@ -198,15 +201,15 @@ impl<DB: Database> State<DB> {
}

// TODO make cache aware of transitions dropping by having global transition counter.
/// Takes changeset and reverts from state and replaces it with empty one.
/// This will trop pending Transition and any transitions would be lost.
/// Takes the [`BundleState`] changeset from the [`State`], replacing it
/// with an empty one.
///
/// NOTE: If either:
/// * The [State] has not been built with [StateBuilder::with_bundle_update], or
/// * The [State] has a [TransitionState] set to `None` when
/// [State::merge_transitions] is called,
/// This will not apply any pending [`TransitionState`]. It is recommended
/// to call [`State::merge_transitions`] before taking the bundle.
///
/// this will panic.
/// If the `State` has been built with the
/// [`StateBuilder::with_bundle_prestate`] option, the pre-state will be
/// taken along with any changes made by [`State::merge_transitions`].
pub fn take_bundle(&mut self) -> BundleState {
core::mem::take(&mut self.bundle_state)
}
Expand Down
8 changes: 6 additions & 2 deletions crates/revm/src/db/states/transition_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ pub struct TransitionState {
}

impl TransitionState {
/// Create new transition state with one transition.
/// Create new transition state containing one [`TransitionAccount`].
pub fn single(address: Address, transition: TransitionAccount) -> Self {
let mut transitions = HashMap::new();
transitions.insert(address, transition);
TransitionState { transitions }
}

/// Return transition id and all account transitions. Leave empty transition map.
/// Take the contents of this [`TransitionState`] and replace it with an
/// empty one. See [`core::mem::take`].
pub fn take(&mut self) -> TransitionState {
core::mem::take(self)
}

/// Add transitions to the transition state. This will insert new
/// [`TransitionAccount`]s, or update existing ones via
/// [`TransitionAccount::update`].
pub fn add_transitions(&mut self, transitions: Vec<(Address, TransitionAccount)>) {
for (address, account) in transitions {
match self.transitions.entry(address) {
Expand Down
Loading