Skip to content

Commit 13517a6

Browse files
committed
mtc_api: Make LandmarkSequence::add more robust
If the number of landmarks is greater than the max, then drain the oldest landmarks from the deque. This makes the code more robust in case we ever decode a `LandmarkSequence` with a different `max_landmarks` than when it was encoded.
1 parent 38b79c9 commit 13517a6

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

crates/mtc_api/src/landmark.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ impl LandmarkSequence {
5050
));
5151
}
5252
}
53-
// Keep `max_landmarks + 1` tree sizes, since we want `max_landmarks`
54-
// landmark intervals.
55-
if self.landmarks.len() == self.max_landmarks + 1 {
56-
self.landmarks.pop_front();
53+
if self.landmarks.len() >= self.max_landmarks {
54+
self.landmarks
55+
.drain(..self.landmarks.len() - self.max_landmarks);
5756
}
5857
self.landmarks.push_back(tree_size);
5958
self.last_landmark += 1;

0 commit comments

Comments
 (0)