-
Notifications
You must be signed in to change notification settings - Fork 9
fix: avoid panic for sentinel blocks in debug builds #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The workaround with the available heights also doesn't work in debug builds. I just didn't realize since I was always running release builds lately. Now while working on integration tests, this became an issue again.
📝 WalkthroughWalkthroughThis PR removes in-memory height tracking from PersistentBlockStorage by eliminating the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant BlockStorage as PersistentBlockStorage
participant Cache as SegmentCache
participant Segment
Note over Client,Segment: Previous Flow (with available_heights tracking)
Client->>BlockStorage: store_block(height, block)
BlockStorage->>BlockStorage: update available_heights HashSet
Client->>BlockStorage: load_block(height)
BlockStorage->>BlockStorage: check available_heights
alt height found
BlockStorage->>Cache: fetch via range query
Cache->>Segment: get segment data
Segment-->>Cache: return item
Cache-->>BlockStorage: return item
else height not found
BlockStorage-->>Client: return None
end
Note over Client,Segment: New Flow (direct SegmentCache access)
Client->>BlockStorage: store_block(height, block)
BlockStorage->>Cache: direct storage operation
Client->>BlockStorage: load_block(height)
BlockStorage->>Cache: get_item(height)
Cache->>Cache: compute segment & offset
Cache->>Segment: fetch_segment(segment_id)
Segment-->>Cache: segment data
Cache->>Segment: get_single(offset)
Segment-->>Cache: return item or sentinel
Cache->>Cache: filter sentinel values
Cache-->>BlockStorage: return Option<HashedBlock>
BlockStorage-->>Client: return Option<HashedBlock>
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
dash-spv/src/storage/blocks.rs (1)
14-25:⚠️ Potential issue | 🟡 MinorUpdate impl
BlockStorageto useCoreBlockHeightin method signatures, matching the trait.The
BlockStoragetrait declares parameters asCoreBlockHeight(lines 19, 24), while theimplblock usesu32directly (lines 62, 66).CoreBlockHeightis a type alias foru32, so they compile to the same type, but the inconsistency between trait and implementation makes the code harder to follow. Update the impl methods to useCoreBlockHeightto match the trait interface.
🧹 Nitpick comments (2)
dash-spv/src/storage/segments.rs (1)
496-500: Consider adding adebug_assertfor offset bounds, consistent withinsert.
insert(line 480) hasdebug_assert!(offset < Self::ITEMS_PER_SEGMENT). Adding the same guard here would maintain consistency and catch misuse early.Suggested change
pub fn get_single(&mut self, offset: u32) -> &I { + debug_assert!(offset < Self::ITEMS_PER_SEGMENT); self.last_accessed = Instant::now(); &self.items[offset as usize] }dash-spv/src/storage/blocks.rs (1)
66-68:load_blockacquires a write lock for a conceptually read-only operation.
get_itemrequires&mut self(due to LRUlast_accessedtracking in the segment cache), so a write lock is needed. This serializes all block loads. Not a regression from this PR, but worth noting for future optimization — e.g., using interior mutability (Cell<Instant>) forlast_accessedcould allow read-lock access.
The workaround with the available heights also doesn't work in debug builds. I just didn't realize since I was always running release builds lately. Now while working on integration tests, this became an issue again.
Summary by CodeRabbit