From 1d9725088bd3d5706c5e0fb2e3177603bc1e0278 Mon Sep 17 00:00:00 2001 From: JoseSK999 <83597627+JoseSK999@users.noreply.github.com> Date: Fri, 27 Feb 2026 19:28:11 +0100 Subject: [PATCH 1/2] fix: return a consistent `stop_height` value If we use `take_indices` we remove the `BTreeMap` key/value pairs, so at the end `stop_height` will return 0, rather than the actual stop height. Or we may process the highest block before the others, so the `stop_height` value would jump down to the next highest block. This method should instead return a consistent stop height value. My Floresta implementation was unable to finish SwiftSync due to this unexpected behavior. --- src/lib.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index decd5c7..674b3ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -246,6 +246,7 @@ fn read_compact_size(reader: &mut R) -> Result { #[derive(Debug)] pub struct Hintsfile { map: BTreeMap, + stop_height: u32, } impl Hintsfile { @@ -273,7 +274,7 @@ impl Hintsfile { let ef = EliasFano::from_reader(reader)?; map.insert(height, ef); } - Ok(Self { map }) + Ok(Self { map, stop_height }) } /// Get the unspent indices for a block height. Returns `None` if unavailable. @@ -289,7 +290,7 @@ impl Hintsfile { /// The last height this file encodes for. pub fn stop_height(&self) -> u32 { - self.map.keys().max().copied().unwrap_or_default() + self.stop_height } } @@ -331,10 +332,10 @@ mod sealed { pub trait Sealed {} } -impl sealed::Sealed for crate::StageNew {} -impl sealed::Sealed for crate::StageInProgress {} +impl sealed::Sealed for StageNew {} +impl sealed::Sealed for StageInProgress {} -/// Stage of hintsfile prgroess. +/// Stage of hintsfile progress. pub trait Stage: sealed::Sealed {} impl Stage for StageNew {} From 264cf952e62e440778a49ed501b980df77dc411f Mon Sep 17 00:00:00 2001 From: JoseSK999 <83597627+JoseSK999@users.noreply.github.com> Date: Sat, 28 Feb 2026 19:05:00 +0100 Subject: [PATCH 2/2] chore: replace `is_sorted` to allow 1.81.0 Rust New `debug_assert` is now enforcing no duplicates in the elements for `EliasFano` compression. --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 674b3ab..15a5cb2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ pub struct EliasFano { impl EliasFano { /// Compress a unique, ordered set of elements. pub fn compress(elements: &[u32]) -> Self { - debug_assert!(elements.is_sorted()); + debug_assert!(elements.windows(2).all(|w| w[0] < w[1])); debug_assert!(elements.len() < u32::MAX as usize); if elements.is_empty() { return Self {