Skip to content
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

fix(consensus): Fix off-by-one error in notary bound #296

Merged
merged 2 commits into from
Jul 1, 2024
Merged
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
43 changes: 17 additions & 26 deletions rs/consensus/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ pub fn get_adjusted_notary_delay(
}
NotaryDelay::ReachedMaxNotarizationCUPGap {
notarized_height,
cup_height,
next_cup_height,
} => {
warn!(
every_n_seconds => 5,
log,
"The gap between the notarization height ({notarized_height}) and \
the CUP height ({cup_height}) exceeds hard bound of \
the next CUP height ({next_cup_height}) exceeds hard bound of \
{ACCEPTABLE_NOTARIZATION_CUP_GAP}"
);
None
Expand All @@ -199,7 +199,7 @@ pub enum NotaryDelay {
/// hard limit on this gap, the notary cannot progress for now.
ReachedMaxNotarizationCUPGap {
notarized_height: Height,
cup_height: Height,
next_cup_height: Height,
},
}

Expand Down Expand Up @@ -257,24 +257,15 @@ pub fn get_adjusted_notary_delay_from_settings(
let certified_adjusted_delay =
finality_adjusted_delay + unit_delay.as_millis() as u64 * certified_gap;

// We measure the gap between our current CUP height and the current notarized
// height. If the notarized height is in a DKG interval for which we don't yet have
// the CUP, we limit the notarization-CUP gap to ACCEPTABLE_NOTARIZATION_CUP_GAP.
let last_cup = pool.get_highest_catch_up_package();
let last_cup_dkg_info = &last_cup
.content
.block
.as_ref()
.payload
.as_ref()
.as_summary()
.dkg;
let cup_height = last_cup.height();
let cup_gap = notarized_height.get().saturating_sub(cup_height.get());
if cup_gap >= last_cup_dkg_info.interval_length.get() + ACCEPTABLE_NOTARIZATION_CUP_GAP {
// We bound the gap between the next CUP height and the current notarization
// height by ACCEPTABLE_NOTARIZATION_CUP_GAP.
let next_cup_height = pool.get_next_cup_height();
if notarized_height.get().saturating_sub(next_cup_height.get())
>= ACCEPTABLE_NOTARIZATION_CUP_GAP
{
return NotaryDelay::ReachedMaxNotarizationCUPGap {
notarized_height,
cup_height,
next_cup_height,
};
}

Expand Down Expand Up @@ -679,13 +670,13 @@ mod tests {
.dkg
.clone();

for _ in 0..last_cup_dkg_info.interval_length.get() {
pool.advance_round_normal_operation_no_cup();
}

for _ in 0..(ACCEPTABLE_NOTARIZATION_CUP_GAP - 1) {
pool.advance_round_normal_operation_no_cup();
}
// Advance to next summary height
pool.advance_round_normal_operation_no_cup_n(
last_cup_dkg_info.interval_length.get() + 1,
);
assert!(pool.get_cache().finalized_block().payload.is_summary());
// Advance to one height before the highest possible CUP-less notarized height
pool.advance_round_normal_operation_no_cup_n(ACCEPTABLE_NOTARIZATION_CUP_GAP - 1);

let gap_trigger_height = Height::new(
PoolReader::new(&pool).get_notarized_height().get()
Expand Down