Skip to content

Commit f4fa1ef

Browse files
committed
f - Expand Cache documentation
1 parent 11d0276 commit f4fa1ef

File tree

1 file changed

+13
-2
lines changed
  • lightning-block-sync/src

1 file changed

+13
-2
lines changed

lightning-block-sync/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,29 @@ pub trait ChainListener {
147147
/// The `Cache` trait defines behavior for managing a block header cache, where block headers are
148148
/// keyed by block hash.
149149
///
150-
/// Used by [`ChainNotifier`] to store headers along the best chain. Implementations may define
151-
/// their own cache eviction policy.
150+
/// Used by [`ChainNotifier`] to store headers along the best chain, which is important for ensuring
151+
/// that blocks can be disconnected if they are no longer accessible from a block source (e.g., if
152+
/// the block source does not store stale forks indefinitely).
153+
///
154+
/// Implementations may define how long to retain headers such that it's unlikely they will ever be
155+
/// needed to disconnect a block. In cases where block sources provide access to headers on stale
156+
/// forks reliably, caches may be entirely unnecessary.
152157
///
153158
/// [`ChainNotifier`]: struct.ChainNotifier.html
154159
pub trait Cache {
155160
/// Retrieves the block header keyed by the given block hash.
156161
fn get(&self, block_hash: &BlockHash) -> Option<&ValidatedBlockHeader>;
157162

158163
/// Inserts a block header keyed by the given block hash.
164+
///
165+
/// Called when a block has been connected to the best chain to ensure it is available to be
166+
/// disconnected later if needed.
159167
fn insert(&mut self, block_hash: BlockHash, block_header: ValidatedBlockHeader);
160168

161169
/// Removes the block header keyed by the given block hash.
170+
///
171+
/// Called when a block has been disconnected from the best chain. Once disconnected, a block's
172+
/// header is no longer needed and thus can be removed.
162173
fn remove(&mut self, block_hash: &BlockHash) -> Option<ValidatedBlockHeader>;
163174
}
164175

0 commit comments

Comments
 (0)