Fix up trusted validator snapshot selection

This commit is contained in:
Michael Vines 2020-02-23 17:10:20 -07:00
parent b106d3ba60
commit 394933e53c
1 changed files with 14 additions and 10 deletions

View File

@ -250,14 +250,16 @@ fn get_rpc_addr(
} }
let trusted_slots = if let Some(trusted_validators) = trusted_validators { let trusted_slots = if let Some(trusted_validators) = trusted_validators {
let trusted_slots = HashSet::new(); let mut trusted_slots = HashSet::new();
for trusted_validator in trusted_validators { for trusted_validator in trusted_validators {
if let Some(slot_hash) = cluster_info if let Some(snapshot_hashes) = cluster_info
.read() .read()
.unwrap() .unwrap()
.get_snapshot_hash_for_node(trusted_validator) .get_snapshot_hash_for_node(trusted_validator)
{ {
trusted_slots.union(&slot_hash.iter().collect()); for snapshot_hash in snapshot_hashes {
trusted_slots.insert(*snapshot_hash);
}
} }
} }
Some(trusted_slots) Some(trusted_slots)
@ -291,14 +293,16 @@ fn get_rpc_addr(
highest_slot.max(snapshot_hash.0) highest_slot.max(snapshot_hash.0)
}); });
if highest_snapshot_slot_for_node > highest_snapshot_slot { if highest_snapshot_slot_for_node > 0 {
// Found a higher snapshot, remove all rpc peers with a lower snapshot if highest_snapshot_slot_for_node > highest_snapshot_slot {
eligible_rpc_peers.clear(); // Found a higher snapshot, remove all rpc peers with a lower snapshot
highest_snapshot_slot = highest_snapshot_slot_for_node; eligible_rpc_peers.clear();
} highest_snapshot_slot = highest_snapshot_slot_for_node;
}
if highest_snapshot_slot_for_node == highest_snapshot_slot { if highest_snapshot_slot_for_node == highest_snapshot_slot {
eligible_rpc_peers.push(rpc_peer.clone()); eligible_rpc_peers.push(rpc_peer.clone());
}
} }
} }
} }