Skip to content

Commit 114ddbb

Browse files
committed
docs
1 parent 21cb865 commit 114ddbb

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

glue/src/stateful/db.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
//! Database batch lifecycle traits for stateful applications.
2+
//!
3+
//! This module defines the traits that bridge the [`Stateful`](super::wrapper::Stateful)
4+
//! wrapper with the underlying storage layer (QMDB). The batch lifecycle has
5+
//! three stages:
6+
//!
7+
//! 1. [`Unmerkleized`]: an in-progress batch of reads and writes.
8+
//! 2. [`Merkleized`]: a sealed batch whose state root has been computed.
9+
//! 3. Finalization: applying a merkleized batch's changeset to the
10+
//! database via [`ManagedDb::finalize`].
11+
//!
12+
//! [`DatabaseSet`] composes one or more [`ManagedDb`] instances (each behind
13+
//! its own `Arc<AsyncRwLock<...>>`) into a single unit that the wrapper
14+
//! manages as a group. It is implemented for `Arc<AsyncRwLock<T>>` (singleton)
15+
//! and for tuples of up to 8 such values.
16+
117
use commonware_cryptography::Digest;
218
use commonware_utils::sync::AsyncRwLock;
319
use std::{fmt::Debug, future::Future, sync::Arc};

glue/src/stateful/wrapper.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
//! Consensus-facing wrapper that manages pending state on behalf of a
2+
//! stateful application.
3+
//!
4+
//! [`Stateful`] implements the consensus [`Application`](ConsensusApplication)
5+
//! and [`VerifyingApplication`](ConsensusVerifyingApplication) traits by
6+
//! delegating execution to the inner [`Application`] while managing the
7+
//! pending-tip DAG of merkleized batches:
8+
//!
9+
//! - Before each `propose` or `verify`, the wrapper forks unmerkleized
10+
//! batches from the parent block's pending state (or from the committed
11+
//! database state if the parent has been finalized).
12+
//! - After execution, the wrapper stores the resulting merkleized batches
13+
//! as a new pending tip keyed by the block's payload.
14+
//! - On finalization, the wrapper applies the winning tip's changesets to
15+
//! the underlying databases and prunes dead forks.
16+
//!
17+
//! # Lazy Recovery
18+
//!
19+
//! Pending state lives entirely in memory. After a restart the map is empty,
20+
//! but the wrapper recovers lazily: when a parent's state is missing, it
21+
//! walks back through the block DAG via a [`BlockProvider`] to the nearest
22+
//! known ancestor, then replays forward via [`Application::replay`]. Each
23+
//! replayed block is inserted into the pending map immediately so that
24+
//! partial progress survives timeouts.
25+
126
use super::{db::DatabaseSet, Application};
227
use commonware_consensus::{
328
marshal::ancestry::{AncestorStream, BlockProvider},

0 commit comments

Comments
 (0)