Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

dispute-coordinator: fix earliest session checks for pruning and import #6358

Merged
merged 4 commits into from
Nov 28, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
RollingSession: add fn contains
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
  • Loading branch information
sandreim committed Nov 28, 2022
commit 2170476b18dd289b84a8f5e5204209267bb308e8
20 changes: 20 additions & 0 deletions node/subsystem-util/src/rolling_session_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ impl RollingSessionWindow {
self.earliest_session + (self.session_info.len() as SessionIndex).saturating_sub(1)
}

/// Returns `true` if `session_index` is contained in the window.
pub fn contains(&self, session_index: SessionIndex) -> bool {
session_index >= self.earliest_session() && session_index <= self.latest_session()
}

async fn earliest_non_finalized_block_session<Sender>(
sender: &mut Sender,
) -> Result<u32, SessionsUnavailable>
Expand Down Expand Up @@ -783,6 +788,21 @@ mod tests {
cache_session_info_test(1, 2, Some(window), 2, None);
}

#[test]
fn cache_session_window_contains() {
let window = RollingSessionWindow {
earliest_session: 10,
session_info: vec![dummy_session_info(1)],
window_size: SESSION_WINDOW_SIZE,
db_params: Some(dummy_db_params()),
};

assert!(!window.contains(0));
assert!(!window.contains(10 + SESSION_WINDOW_SIZE.get()));
assert!(!window.contains(11));
assert!(!window.contains(10 + SESSION_WINDOW_SIZE.get() - 1));
}

#[test]
fn cache_session_info_first_late() {
cache_session_info_test(
Expand Down