Skip to content

Commit

Permalink
f - Rename NonDiscardingCache to ReadOnlyCache
Browse files Browse the repository at this point in the history
  • Loading branch information
jkczyz committed Feb 13, 2021
1 parent f18348f commit c94c272
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lightning-block-sync/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub async fn sync_listeners<B: BlockSource, C: Cache>(
let mut most_connected_blocks = Vec::new();
for (old_header, chain_listener) in chain_listeners_with_old_headers.drain(..) {
// Disconnect any stale blocks, but keep them in the cache for the next iteration.
let header_cache = &mut NonDiscardingCache(header_cache);
let header_cache = &mut ReadOnlyCache(header_cache);
let mut chain_notifier = ChainNotifier { header_cache };
let difference =
chain_notifier.find_difference(new_header, &old_header, &mut chain_poller).await?;
Expand Down Expand Up @@ -80,11 +80,13 @@ pub async fn sync_listeners<B: BlockSource, C: Cache>(
Ok(new_header)
}

/// A cache that won't discard any block headers. Used to prevent losing headers that are needed to
/// disconnect blocks common to more than one listener.
struct NonDiscardingCache<'a, C: Cache>(&'a mut C);
/// A wrapper to make a cache read-only.
///
/// Used to prevent losing headers that may be needed to disconnect blocks common to more than one
/// listener.
struct ReadOnlyCache<'a, C: Cache>(&'a mut C);

impl<'a, C: Cache> Cache for NonDiscardingCache<'a, C> {
impl<'a, C: Cache> Cache for ReadOnlyCache<'a, C> {
fn look_up(&self, block_hash: &BlockHash) -> Option<&ValidatedBlockHeader> {
self.0.look_up(block_hash)
}
Expand Down

0 comments on commit c94c272

Please sign in to comment.