Skip to content

Commit 7ca0f43

Browse files
committed
mtc_worker: Compute max_landmarks once
1 parent 895f2a0 commit 7ca0f43

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

crates/mtc_worker/config/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ pub struct LogParams {
3939
pub clean_interval_secs: u64,
4040
}
4141

42+
impl LogParams {
43+
/// Return the maximum number of landmarks that cover unexpired certificates at any given time.
44+
pub fn max_landmarks(&self) -> usize {
45+
self.max_certificate_lifetime_secs
46+
.div_ceil(self.landmark_interval_secs)
47+
+ 1
48+
}
49+
}
50+
4251
fn default_u8<const V: u8>() -> u8 {
4352
V
4453
}

crates/mtc_worker/src/frontend_worker.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,9 @@ async fn get_landmark_sequence(
477477
return Err("failed to get landmark sequence".into());
478478
};
479479

480-
let max_landmarks = params
481-
.max_certificate_lifetime_secs
482-
.div_ceil(params.landmark_interval_secs)
483-
+ 1;
484-
485-
let landmark_sequence = LandmarkSequence::from_bytes(&landmark_sequence_bytes, max_landmarks)
486-
.map_err(|e| e.to_string())?;
480+
let landmark_sequence =
481+
LandmarkSequence::from_bytes(&landmark_sequence_bytes, params.max_landmarks())
482+
.map_err(|e| e.to_string())?;
487483

488484
Ok(landmark_sequence)
489485
}

crates/mtc_worker/src/sequencer_do.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ fn checkpoint_callback(env: &Env, name: &str) -> CheckpointCallbacker {
8181
}
8282

8383
// Time to add a new landmark.
84-
let max_landmarks = params
85-
.max_certificate_lifetime_secs
86-
.div_ceil(params.landmark_interval_secs)
87-
+ 1;
84+
let max_landmarks = params.max_landmarks();
8885

8986
// Load current landmark sequence.
9087
let mut seq =

0 commit comments

Comments
 (0)