Skip to content
Open
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
16 changes: 1 addition & 15 deletions crates/store/src/state/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::num::NonZeroUsize;
use std::path::Path;
use std::sync::Arc;
use std::sync::atomic::AtomicUsize;

use arc_swap::ArcSwap;
use miden_node_tracing::spawn::spawn_blocking_in_current_span;
Expand Down Expand Up @@ -32,15 +31,7 @@ use crate::state::loader::{
verify_tree_consistency,
};
use crate::state::writer::{WriteRequest, WriteWorker, WriterTask};
use crate::state::{
BlockCache,
BlockWriter,
ProofCache,
ProofWriter,
SnapshotGuard,
State,
StateSnapshot,
};
use crate::state::{BlockCache, BlockWriter, ProofCache, ProofWriter, State, StateSnapshot};
use crate::{COMPONENT, DataDirectory, DatabaseOptions};

/// Awaits a spawned load task, forwarding its result.
Expand Down Expand Up @@ -291,9 +282,6 @@ impl State {
let block_cache = BlockCache::new(BLOCK_CACHE_CAPACITY);
let proof_cache = ProofCache::new(PROOF_CACHE_CAPACITY);

// Shared counter of live snapshot generations, for observability.
let snapshots_live = Arc::new(AtomicUsize::new(0));

// Create the initial snapshot from reader views of the just-loaded trees.
let initial_snapshot = Arc::new(StateSnapshot::new(
nullifier_tree
Expand All @@ -304,7 +292,6 @@ impl State {
forest
.reader()
.map_err(|e| StateInitializationError::AccountStateForestIoError(e.as_report()))?,
SnapshotGuard::new(Arc::clone(&snapshots_live), latest_block_num),
));
let latest_snapshot = Arc::new(ArcSwap::from(initial_snapshot));

Expand All @@ -324,7 +311,6 @@ impl State {
account_tree,
blockchain,
forest,
snapshots_live,
apply_block_thread_priority,
);
let state = Self {
Expand Down
2 changes: 1 addition & 1 deletion crates/store/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub use lifecycle::LoadedState;
use miden_protocol::block::BlockNumber;
pub use replica::{BlockCache, BlockNotification, ProofCache, ProofNotification};
use tokio::sync::watch;
use view::StateSnapshot;
pub use view::{ScopedBlockNum, ScopedBlockRange, StateView, StateWitnesses, TransactionInputs};
use view::{SnapshotGuard, StateSnapshot};
pub use writer::{BlockWriter, ProofWriter, WriterTask};

use crate::blocks::BlockStore;
Expand Down
14 changes: 3 additions & 11 deletions crates/store/src/state/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ mod scoped;
pub use scoped::{ScopedBlockNum, ScopedBlockRange};

mod snapshot;
pub(in crate::state) use snapshot::{
PublishedGenerations,
SNAPSHOTS_LIVE_WARN_THRESHOLD,
SnapshotGuard,
StateSnapshot,
};
pub(in crate::state) use snapshot::{PublishedGenerations, StateSnapshot};

mod account;
mod block;
Expand All @@ -53,8 +48,7 @@ pub use transaction_inputs::TransactionInputs;
///
/// Obtained from [`State::view`]; create one per request and drop it when the request completes.
/// Holding a view pins a snapshot generation (and thereby the `RocksDB` snapshots backing the
/// trees), so it must not be stored in long-lived structs; leaked or slow readers are reported by
/// the store's snapshot-lifetime warnings.
/// trees), so it must not be stored in long-lived structs.
///
/// Reads that are technically not block-scoped (for example, immutable content-addressed data)
/// also live here so that every read path flows through one type.
Expand Down Expand Up @@ -97,9 +91,7 @@ impl State {
///
/// Work in the closure should be kept to low-complexity compute over the view, ideally with no
/// I/O and no other `.await` points. Anything slower holds the pinned snapshot, and therefore
/// its underlying `RocksDB` snapshot, for as long as it runs. The snapshot's lifetime is logged
/// as a warning if held too long, but that is a backstop, not a substitute for keeping closures
/// short.
/// its underlying `RocksDB` snapshot, for as long as it runs.
pub async fn with_view<R>(&self, f: impl AsyncFnOnce(&StateView) -> R) -> R {
let view = self.view();
f(&view).await
Expand Down
Loading