@@ -158,34 +158,30 @@ pub trait ChainListener {
158
158
/// [`ChainNotifier`]: struct.ChainNotifier.html
159
159
pub trait Cache {
160
160
/// 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 > ;
162
162
163
- /// Inserts a block header keyed by the given block hash.
164
- ///
165
163
/// Called when a block has been connected to the best chain to ensure it is available to be
166
164
/// 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 ) ;
168
166
169
- /// Removes the block header keyed by the given block hash.
170
- ///
171
167
/// Called when a block has been disconnected from the best chain. Once disconnected, a block's
172
168
/// 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 > ;
174
170
}
175
171
176
172
/// Unbounded cache of block headers keyed by block hash.
177
173
pub type UnboundedCache = std:: collections:: HashMap < BlockHash , ValidatedBlockHeader > ;
178
174
179
175
impl Cache for UnboundedCache {
180
- fn get ( & self , block_hash : & BlockHash ) -> Option < & ValidatedBlockHeader > {
176
+ fn look_up ( & self , block_hash : & BlockHash ) -> Option < & ValidatedBlockHeader > {
181
177
self . get ( block_hash)
182
178
}
183
179
184
- fn insert ( & mut self , block_hash : BlockHash , block_header : ValidatedBlockHeader ) {
180
+ fn block_connected ( & mut self , block_hash : BlockHash , block_header : ValidatedBlockHeader ) {
185
181
self . insert ( block_hash, block_header) ;
186
182
}
187
183
188
- fn remove ( & mut self , block_hash : & BlockHash ) -> Option < ValidatedBlockHeader > {
184
+ fn block_disconnected ( & mut self , block_hash : & BlockHash ) -> Option < ValidatedBlockHeader > {
189
185
self . remove ( block_hash)
190
186
}
191
187
}
@@ -229,7 +225,7 @@ impl<C: Cache> ChainNotifier<C> {
229
225
match & event {
230
226
& ForkStep :: DisconnectBlock ( ref header) => {
231
227
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 ) {
233
229
assert_eq ! ( cached_header, * header) ;
234
230
}
235
231
chain_listener. block_disconnected ( & header. header , header. height ) ;
@@ -259,7 +255,7 @@ impl<C: Cache> ChainNotifier<C> {
259
255
debug_assert_eq ! ( block. block_hash, header. block_hash) ;
260
256
261
257
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) ;
263
259
chain_listener. block_connected ( & block, header. height ) ;
264
260
new_tip = Some ( header) ;
265
261
}
@@ -322,7 +318,7 @@ impl<C: Cache> ChainNotifier<C> {
322
318
chain_poller : & mut P ,
323
319
header : & ValidatedBlockHeader ,
324
320
) -> BlockSourceResult < ValidatedBlockHeader > {
325
- match self . header_cache . get ( & header. header . prev_blockhash ) {
321
+ match self . header_cache . look_up ( & header. header . prev_blockhash ) {
326
322
Some ( prev_header) => Ok ( * prev_header) ,
327
323
None => chain_poller. look_up_previous_header ( header) . await ,
328
324
}
0 commit comments