Skip to content

Commit

Permalink
Document how Finalized and NonFinalized clones are different
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Sep 27, 2022
1 parent 04a5808 commit 96d3966
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 5 additions & 2 deletions zebra-state/src/service/finalized_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ pub(super) use zebra_db::ZebraDb;
/// The finalized part of the chain state, stored in the db.
///
/// `rocksdb` allows concurrent writes through a shared reference,
/// so finalized state instances are cloneable. When the final clone is dropped,
/// the database is closed.
/// so clones of the finalized state represent the same database instance.
/// When the final clone is dropped, the database is closed.
///
/// This is different from `NonFinalizedState::clone()`,
/// which returns an independent copy of the chains.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct FinalizedState {
// Configuration
Expand Down
8 changes: 7 additions & 1 deletion zebra-state/src/service/non_finalized_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ mod tests;
pub(crate) use chain::Chain;

/// The state of the chains in memory, including queued blocks.
#[derive(Debug, Clone)]
///
/// Clones of the non-finalized state contain independent copies of the chains.
/// This is different from `FinalizedState::clone()`,
/// which returns a shared reference to the database.
///
/// Most chain data is clone-on-write using [`Arc`].
#[derive(Clone, Debug)]
pub struct NonFinalizedState {
/// Verified, non-finalized chains, in ascending order.
///
Expand Down

0 comments on commit 96d3966

Please sign in to comment.