Skip to content

Commit a4ab8f4

Browse files
committed
f - Rename Cache methods
1 parent f4fa1ef commit a4ab8f4

File tree

1 file changed

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

1 file changed

+9
-13
lines changed

lightning-block-sync/src/lib.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,34 +158,30 @@ pub trait ChainListener {
158158
/// [`ChainNotifier`]: struct.ChainNotifier.html
159159
pub trait Cache {
160160
/// Retrieves the block header keyed by the given block hash.
161-
fn get(&self, block_hash: &BlockHash) -> Option<&ValidatedBlockHeader>;
161+
fn look_up(&self, block_hash: &BlockHash) -> Option<&ValidatedBlockHeader>;
162162

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

169-
/// Removes the block header keyed by the given block hash.
170-
///
171167
/// Called when a block has been disconnected from the best chain. Once disconnected, a block's
172168
/// header is no longer needed and thus can be removed.
173-
fn remove(&mut self, block_hash: &BlockHash) -> Option<ValidatedBlockHeader>;
169+
fn block_disconnected(&mut self, block_hash: &BlockHash) -> Option<ValidatedBlockHeader>;
174170
}
175171

176172
/// Unbounded cache of block headers keyed by block hash.
177173
pub type UnboundedCache = std::collections::HashMap<BlockHash, ValidatedBlockHeader>;
178174

179175
impl Cache for UnboundedCache {
180-
fn get(&self, block_hash: &BlockHash) -> Option<&ValidatedBlockHeader> {
176+
fn look_up(&self, block_hash: &BlockHash) -> Option<&ValidatedBlockHeader> {
181177
self.get(block_hash)
182178
}
183179

184-
fn insert(&mut self, block_hash: BlockHash, block_header: ValidatedBlockHeader) {
180+
fn block_connected(&mut self, block_hash: BlockHash, block_header: ValidatedBlockHeader) {
185181
self.insert(block_hash, block_header);
186182
}
187183

188-
fn remove(&mut self, block_hash: &BlockHash) -> Option<ValidatedBlockHeader> {
184+
fn block_disconnected(&mut self, block_hash: &BlockHash) -> Option<ValidatedBlockHeader> {
189185
self.remove(block_hash)
190186
}
191187
}
@@ -229,7 +225,7 @@ impl<C: Cache> ChainNotifier<C> {
229225
match &event {
230226
&ForkStep::DisconnectBlock(ref header) => {
231227
println!("Disconnecting block {}", header.block_hash);
232-
if let Some(cached_header) = self.header_cache.remove(&header.block_hash) {
228+
if let Some(cached_header) = self.header_cache.block_disconnected(&header.block_hash) {
233229
assert_eq!(cached_header, *header);
234230
}
235231
chain_listener.block_disconnected(&header.header, header.height);
@@ -259,7 +255,7 @@ impl<C: Cache> ChainNotifier<C> {
259255
debug_assert_eq!(block.block_hash, header.block_hash);
260256

261257
println!("Connecting block {}", header.block_hash);
262-
self.header_cache.insert(header.block_hash, header);
258+
self.header_cache.block_connected(header.block_hash, header);
263259
chain_listener.block_connected(&block, header.height);
264260
new_tip = Some(header);
265261
}
@@ -322,7 +318,7 @@ impl<C: Cache> ChainNotifier<C> {
322318
chain_poller: &mut P,
323319
header: &ValidatedBlockHeader,
324320
) -> BlockSourceResult<ValidatedBlockHeader> {
325-
match self.header_cache.get(&header.header.prev_blockhash) {
321+
match self.header_cache.look_up(&header.header.prev_blockhash) {
326322
Some(prev_header) => Ok(*prev_header),
327323
None => chain_poller.look_up_previous_header(header).await,
328324
}

0 commit comments

Comments
 (0)