Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod message_test;

mod handlers;
mod message;
mod message_index_detector;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New tracker code is currently unused

Low Severity

message_index_detector is added to the binary, but MessageIndexTracker, seen_message(), and pending_messages_count() are not referenced anywhere else. The file also suppresses this with #![allow(dead_code)], which leaves dead code in production and increases maintenance risk.

Additional Locations (1)

Fix in Cursor Fix in Web

pub mod metrics;
mod protocol;
mod stress_test_node;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// TODO(AndrewL): remove this once the struct is used
#![allow(dead_code)]

#[derive(Default, Clone, Copy)]
pub struct MessageIndexTracker {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module name mismatches struct name semantically

Low Severity

The module is named message_index_detector but the struct it contains is MessageIndexTracker. "Detector" and "tracker" have different semantics — a detector identifies something, a tracker follows state over time. The struct clearly tracks state, so the module name is misleading. The module name could be message_index_tracker to match.

Additional Locations (1)

Fix in Cursor Fix in Web

seen_messages_count: u64,
max_message_index: Option<u64>,
min_message_index: Option<u64>,
}

impl MessageIndexTracker {
pub fn seen_message(&mut self, message_index: u64) {
self.seen_messages_count += 1;
if self.max_message_index.is_none() || self.max_message_index.unwrap() < message_index {
self.max_message_index = Some(message_index);
}
if self.min_message_index.is_none() || self.min_message_index.unwrap() > message_index {
self.min_message_index = Some(message_index);
}
}

pub fn pending_messages_count(&self) -> u64 {
if self.seen_messages_count == 0 {
return 0;
}

let min_message_index = self.min_message_index.unwrap();
let max_message_index = self.max_message_index.unwrap();
max_message_index - min_message_index + 1 - self.seen_messages_count

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate indices break pending count

Low Severity

pending_messages_count() assumes every seen_message() call is a unique index. Because seen_messages_count increments on duplicates, max - min + 1 - seen_messages_count can go negative and underflow as u64, producing an incorrect huge pending value (or debug overflow panic) in message_index_detector.rs.

Additional Locations (1)

Fix in Cursor Fix in Web

}
}
Loading