Skip to content

Commit

Permalink
fix distance calculation in get_closest_completion (solana-labs#21601)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbiseda authored Dec 4, 2021
1 parent 4c4bc87 commit 9c6b95e
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions core/src/repair_generic_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9c6b95e

Please sign in to comment.