fix distance calculation in get_closest_completion (#21601)

This commit is contained in:
Jeff Biseda 2021-12-03 22:36:46 -08:00 committed by GitHub
parent 4c4bc873a0
commit 9c6b95e1e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 2 deletions

View File

@ -127,9 +127,36 @@ pub fn get_closest_completion(
let shred_index = blockstore.get_index(slot).unwrap();
let dist = if let Some(shred_index) = shred_index {
let shred_count = shred_index.data().num_shreds() as u64;
last_index - shred_count
if last_index.saturating_add(1) < shred_count {
datapoint_error!(
"repair_generic_traversal_error",
(
"error",
format!(
"last_index + 1 < shred_count. last_index={} shred_count={}",
last_index, shred_count,
),
String
),
);
}
last_index.saturating_add(1).saturating_sub(shred_count)
} else {
last_index - slot_meta.consumed
if last_index < slot_meta.consumed {
datapoint_error!(
"repair_generic_traversal_error",
(
"error",
format!(
"last_index < slot_meta.consumed. last_index={} slot_meta.consumed={}",
last_index,
slot_meta.consumed,
),
String
),
);
}
last_index.saturating_sub(slot_meta.consumed)
};
v.push((slot, dist));
processed_slots.insert(slot);