Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Fixup ancestor/descendants duplicate ancestors propagation in progres…
Browse files Browse the repository at this point in the history
…s map
  • Loading branch information
carllin committed Mar 20, 2021
1 parent cdcc0d7 commit 24e969a
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 78 deletions.
33 changes: 29 additions & 4 deletions core/src/cluster_slot_state_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ fn on_cluster_update(
}

fn get_cluster_duplicate_confirmed_hash<'a>(
slot: Slot,
gossip_duplicate_confirmed_hash: Option<&'a Hash>,
local_frozen_hash: &'a Hash,
is_local_replay_duplicate_confirmed: bool,
Expand All @@ -176,8 +177,14 @@ fn get_cluster_duplicate_confirmed_hash<'a>(
local_duplicate_confirmed_hash,
gossip_duplicate_confirmed_hash,
) {
(Some(local_frozen_hash), Some(gossip_duplicate_confirmed_hash)) => {
assert_eq!(local_frozen_hash, gossip_duplicate_confirmed_hash);
(Some(local_duplicate_confirmed_hash), Some(gossip_duplicate_confirmed_hash)) => {
if local_duplicate_confirmed_hash != gossip_duplicate_confirmed_hash {
error!(
"For slot {}, the gossip duplicate confirmed hash {}, is not equal
to the confirmed hash we replayed: {}",
slot, gossip_duplicate_confirmed_hash, local_duplicate_confirmed_hash
);
}
Some(&local_frozen_hash)
}
(Some(local_frozen_hash), None) => Some(local_frozen_hash),
Expand All @@ -189,6 +196,7 @@ fn apply_state_changes(
slot: Slot,
progress: &mut ProgressMap,
fork_choice: &mut HeaviestSubtreeForkChoice,
ancestors: &HashMap<Slot, HashSet<Slot>>,
descendants: &HashMap<Slot, HashSet<Slot>>,
state_changes: Vec<ResultingStateChange>,
) {
Expand All @@ -211,6 +219,7 @@ fn apply_state_changes(
ResultingStateChange::DuplicateConfirmedSlotMatchesCluster => {
progress.set_confirmed_duplicate_slot(
slot,
ancestors.get(&slot).unwrap_or(&HashSet::default()),
descendants.get(&slot).unwrap_or(&HashSet::default()),
);
fork_choice.mark_fork_valid_candidate(slot);
Expand All @@ -224,6 +233,7 @@ pub(crate) fn check_slot_agrees_with_cluster(
root: Slot,
frozen_hash: Option<Hash>,
gossip_duplicate_confirmed_slots: &GossipDuplicateConfirmedSlots,
ancestors: &HashMap<Slot, HashSet<Slot>>,
descendants: &HashMap<Slot, HashSet<Slot>>,
progress: &mut ProgressMap,
fork_choice: &mut HeaviestSubtreeForkChoice,
Expand All @@ -242,8 +252,9 @@ pub(crate) fn check_slot_agrees_with_cluster(

let frozen_hash = frozen_hash.unwrap();
let gossip_duplicate_confirmed_hash = gossip_duplicate_confirmed_slots.get(&slot);
let is_local_replay_duplicate_confirmed = progress.is_confirmed(slot).expect("If the frozen hash exists, then the slot must exist in bank forks and thus in progress map");
let is_local_replay_duplicate_confirmed = progress.is_supermajority_confirmed(slot).expect("If the frozen hash exists, then the slot must exist in bank forks and thus in progress map");
let cluster_duplicate_confirmed_hash = get_cluster_duplicate_confirmed_hash(
slot,
gossip_duplicate_confirmed_hash,
&frozen_hash,
is_local_replay_duplicate_confirmed,
Expand All @@ -270,7 +281,14 @@ pub(crate) fn check_slot_agrees_with_cluster(
is_slot_duplicate,
is_dead,
);
apply_state_changes(slot, progress, fork_choice, descendants, state_changes);
apply_state_changes(
slot,
progress,
fork_choice,
ancestors,
descendants,
state_changes,
);
}

#[cfg(test)]
Expand All @@ -282,6 +300,7 @@ mod test {
struct InitialState {
heaviest_subtree_fork_choice: HeaviestSubtreeForkChoice,
progress: ProgressMap,
ancestors: HashMap<Slot, HashSet<Slot>>,
descendants: HashMap<Slot, HashSet<Slot>>,
slot: Slot,
}
Expand All @@ -291,6 +310,8 @@ mod test {
let forks = tr(0) / (tr(1) / (tr(2) / tr(3)));
let mut vote_simulator = VoteSimulator::new(1);
vote_simulator.fill_bank_forks(forks, &HashMap::new());
let ancestors = vote_simulator.bank_forks.read().unwrap().ancestors();

let descendants = vote_simulator
.bank_forks
.read()
Expand All @@ -301,6 +322,7 @@ mod test {
InitialState {
heaviest_subtree_fork_choice: vote_simulator.heaviest_subtree_fork_choice,
progress: vote_simulator.progress,
ancestors,
descendants,
slot: 0,
}
Expand Down Expand Up @@ -569,6 +591,7 @@ mod test {
let InitialState {
mut heaviest_subtree_fork_choice,
mut progress,
ancestors,
descendants,
slot,
} = setup();
Expand All @@ -579,6 +602,7 @@ mod test {
slot,
&mut progress,
&mut heaviest_subtree_fork_choice,
&ancestors,
&descendants,
vec![ResultingStateChange::MarkSlotDuplicate],
);
Expand All @@ -604,6 +628,7 @@ mod test {
slot,
&mut progress,
&mut heaviest_subtree_fork_choice,
&ancestors,
&descendants,
vec![ResultingStateChange::DuplicateConfirmedSlotMatchesCluster],
);
Expand Down
1 change: 1 addition & 0 deletions core/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,7 @@ pub mod test {
for (i, duplicate_ancestor) in confirm_ancestors.into_iter().enumerate() {
vote_simulator.progress.set_confirmed_duplicate_slot(
duplicate_ancestor,
ancestors.get(&duplicate_ancestor).unwrap(),
&descendants.get(&duplicate_ancestor).unwrap(),
);
let res = tower.check_switch_threshold(
Expand Down
Loading

0 comments on commit 24e969a

Please sign in to comment.