Skip to content

Commit 54663da

Browse files
Mr-Leshiystevenj
andauthored
fix(rust/cardano-chain-follower): Fixing ProtectedLiveChainBlockList::get_block method, correctly process fuzzy point (#291)
* wip * wip * wip * wip * revert * Update rust/cardano-chain-follower/src/chain_sync_live_chains.rs Co-authored-by: Steven Johnson <[email protected]> * wip --------- Co-authored-by: Steven Johnson <[email protected]>
1 parent 155010e commit 54663da

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

rust/cardano-chain-follower/src/chain_sync_live_chains.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,23 @@ impl ProtectedLiveChainBlockList {
7676
fn get_block(&self, point: &Point, mut advance: i64, strict: bool) -> Option<MultiEraBlock> {
7777
let chain = self.0.read().ok()?;
7878

79-
let mut this = if strict {
79+
let mut this = if strict && !point.is_fuzzy() {
80+
// Strict with concrete point.
81+
// We can call `get` only for non fuzzy points.
82+
// Because of the `Point` type equality strictly defined that fuzzy point and non fuzzy
83+
// point are always not equal, even if they are pointing to the same slot.
8084
chain.get(point)?
85+
} else if strict {
86+
// Strict but fuzzy point.
87+
// For the fuzzy point make a a fuzzy lookup forwards (including the point).
88+
// Because of the `Point` type equality strictly defined that fuzzy point and non fuzzy
89+
// point are always not equal, even if they are pointing to the same slot.
90+
let found = chain.lower_bound(Bound::Included(point))?;
91+
// make sure the found point is what we wanted.
92+
if point.slot_or_default() != found.value().point().slot_or_default() {
93+
return None;
94+
}
95+
found
8196
} else if advance < 0 {
8297
// This is a fuzzy lookup backwards.
8398
advance = advance.saturating_add(1);

0 commit comments

Comments
 (0)