Skip to content

Commit 6f92f9e

Browse files
committed
store: improve comments in ChainStore.blocks()
1 parent 8d14119 commit 6f92f9e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

store/postgres/src/chain_store.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,11 +2254,18 @@ impl ChainStoreTrait for ChainStore {
22542254
};
22552255
let lookup_herd = self.lookup_herd.cheap_clone();
22562256
let logger = self.logger.cheap_clone();
2257-
//TODO(krishna): Add comments explaining the return value of cached_query
2257+
// This match can only return ByHash because lookup_fut explicitly constructs
2258+
// BlocksLookupResult::ByHash. The cache preserves the exact future result,
2259+
// so ByNumber variant is structurally impossible here.
22582260
let res = match lookup_herd.cached_query(hash, lookup_fut, &logger).await {
22592261
(BlocksLookupResult::ByHash(res), _) => res,
2260-
_ => unreachable!(),
2262+
(BlocksLookupResult::ByNumber(_), _) => {
2263+
Arc::new(Err(StoreError::Unknown(anyhow::anyhow!(
2264+
"Unexpected BlocksLookupResult::ByNumber returned from cached block lookup by hash"
2265+
))))
2266+
}
22612267
};
2268+
22622269
// Try to avoid cloning a non-concurrent lookup; it's not
22632270
// entirely clear whether that will actually avoid a clone
22642271
// since it depends on a lot of the details of how the

0 commit comments

Comments
 (0)