@@ -147,18 +147,29 @@ pub trait ChainListener {
147
147
/// The `Cache` trait defines behavior for managing a block header cache, where block headers are
148
148
/// keyed by block hash.
149
149
///
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.
152
157
///
153
158
/// [`ChainNotifier`]: struct.ChainNotifier.html
154
159
pub trait Cache {
155
160
/// Retrieves the block header keyed by the given block hash.
156
161
fn get ( & self , block_hash : & BlockHash ) -> Option < & ValidatedBlockHeader > ;
157
162
158
163
/// 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.
159
167
fn insert ( & mut self , block_hash : BlockHash , block_header : ValidatedBlockHeader ) ;
160
168
161
169
/// 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.
162
173
fn remove ( & mut self , block_hash : & BlockHash ) -> Option < ValidatedBlockHeader > ;
163
174
}
164
175
0 commit comments