Decendent is not a word
This commit is contained in:
parent
da7e49c880
commit
ef111dcbe1
|
@ -45,8 +45,8 @@ impl BankForks {
|
|||
}
|
||||
|
||||
/// Create a map of bank slot id to the set of all of its descendants
|
||||
pub fn decendants(&self) -> HashMap<u64, HashSet<u64>> {
|
||||
let mut decendants = HashMap::new();
|
||||
pub fn descendants(&self) -> HashMap<u64, HashSet<u64>> {
|
||||
let mut descendants = HashMap::new();
|
||||
let mut pending: Vec<Arc<Bank>> = self.banks.values().cloned().collect();
|
||||
let mut done = HashSet::new();
|
||||
assert!(!pending.is_empty());
|
||||
|
@ -56,16 +56,16 @@ impl BankForks {
|
|||
continue;
|
||||
}
|
||||
done.insert(bank.slot());
|
||||
let _ = decendants.entry(bank.slot()).or_insert(HashSet::new());
|
||||
let _ = descendants.entry(bank.slot()).or_insert(HashSet::new());
|
||||
for parent in bank.parents() {
|
||||
decendants
|
||||
descendants
|
||||
.entry(parent.slot())
|
||||
.or_insert(HashSet::new())
|
||||
.insert(bank.slot());
|
||||
}
|
||||
pending.extend(bank.parents().into_iter());
|
||||
}
|
||||
decendants
|
||||
descendants
|
||||
}
|
||||
|
||||
pub fn frozen_banks(&self) -> HashMap<u64, Arc<Bank>> {
|
||||
|
@ -148,7 +148,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_bank_forks_decendants() {
|
||||
fn test_bank_forks_descendants() {
|
||||
let (genesis_block, _) = GenesisBlock::new(10_000);
|
||||
let bank = Bank::new(&genesis_block);
|
||||
let mut bank_forks = BankForks::new(0, bank);
|
||||
|
@ -157,11 +157,11 @@ mod tests {
|
|||
bank_forks.insert(1, bank);
|
||||
let bank = Bank::new_from_parent(&bank0, &Pubkey::default(), 2);
|
||||
bank_forks.insert(2, bank);
|
||||
let decendants = bank_forks.decendants();
|
||||
let children: Vec<u64> = decendants[&0].iter().cloned().collect();
|
||||
let descendants = bank_forks.descendants();
|
||||
let children: Vec<u64> = descendants[&0].iter().cloned().collect();
|
||||
assert_eq!(children, vec![1, 2]);
|
||||
assert!(decendants[&1].is_empty());
|
||||
assert!(decendants[&2].is_empty());
|
||||
assert!(descendants[&1].is_empty());
|
||||
assert!(descendants[&2].is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -177,19 +177,19 @@ impl Locktower {
|
|||
false
|
||||
}
|
||||
|
||||
pub fn is_locked_out(&self, slot: u64, decendants: &HashMap<u64, HashSet<u64>>) -> bool {
|
||||
pub fn is_locked_out(&self, slot: u64, descendants: &HashMap<u64, HashSet<u64>>) -> bool {
|
||||
let mut lockouts = self.lockouts.clone();
|
||||
lockouts.process_vote(Vote { slot });
|
||||
for vote in &lockouts.votes {
|
||||
if vote.slot == slot {
|
||||
continue;
|
||||
}
|
||||
if !decendants[&vote.slot].contains(&slot) {
|
||||
if !descendants[&vote.slot].contains(&slot) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if let Some(root) = lockouts.root_slot {
|
||||
decendants[&root].contains(&slot)
|
||||
descendants[&root].contains(&slot)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
@ -378,28 +378,28 @@ mod test {
|
|||
#[test]
|
||||
fn test_is_locked_out_empty() {
|
||||
let locktower = Locktower::new(EpochStakes::new_for_tests(2), 0, 0.67);
|
||||
let decendants = HashMap::new();
|
||||
assert!(locktower.is_locked_out(0, &decendants));
|
||||
let descendants = HashMap::new();
|
||||
assert!(locktower.is_locked_out(0, &descendants));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_locked_out_root_slot_child() {
|
||||
let mut locktower = Locktower::new(EpochStakes::new_for_tests(2), 0, 0.67);
|
||||
let decendants = vec![(0, vec![1].into_iter().collect())]
|
||||
let descendants = vec![(0, vec![1].into_iter().collect())]
|
||||
.into_iter()
|
||||
.collect();
|
||||
locktower.lockouts.root_slot = Some(0);
|
||||
assert!(locktower.is_locked_out(1, &decendants));
|
||||
assert!(locktower.is_locked_out(1, &descendants));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_locked_out_root_slot_sibling() {
|
||||
let mut locktower = Locktower::new(EpochStakes::new_for_tests(2), 0, 0.67);
|
||||
let decendants = vec![(0, vec![1].into_iter().collect())]
|
||||
let descendants = vec![(0, vec![1].into_iter().collect())]
|
||||
.into_iter()
|
||||
.collect();
|
||||
locktower.lockouts.root_slot = Some(0);
|
||||
assert!(!locktower.is_locked_out(2, &decendants));
|
||||
assert!(!locktower.is_locked_out(2, &descendants));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -413,28 +413,28 @@ mod test {
|
|||
#[test]
|
||||
fn test_is_locked_out_double_vote() {
|
||||
let mut locktower = Locktower::new(EpochStakes::new_for_tests(2), 0, 0.67);
|
||||
let decendants = vec![(0, vec![1].into_iter().collect()), (1, HashSet::new())]
|
||||
let descendants = vec![(0, vec![1].into_iter().collect()), (1, HashSet::new())]
|
||||
.into_iter()
|
||||
.collect();
|
||||
locktower.record_vote(0);
|
||||
locktower.record_vote(1);
|
||||
assert!(!locktower.is_locked_out(0, &decendants));
|
||||
assert!(!locktower.is_locked_out(0, &descendants));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_locked_out_child() {
|
||||
let mut locktower = Locktower::new(EpochStakes::new_for_tests(2), 0, 0.67);
|
||||
let decendants = vec![(0, vec![1].into_iter().collect())]
|
||||
let descendants = vec![(0, vec![1].into_iter().collect())]
|
||||
.into_iter()
|
||||
.collect();
|
||||
locktower.record_vote(0);
|
||||
assert!(locktower.is_locked_out(1, &decendants));
|
||||
assert!(locktower.is_locked_out(1, &descendants));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_locked_out_sibling() {
|
||||
let mut locktower = Locktower::new(EpochStakes::new_for_tests(2), 0, 0.67);
|
||||
let decendants = vec![
|
||||
let descendants = vec![
|
||||
(0, vec![1, 2].into_iter().collect()),
|
||||
(1, HashSet::new()),
|
||||
(2, HashSet::new()),
|
||||
|
@ -443,18 +443,18 @@ mod test {
|
|||
.collect();
|
||||
locktower.record_vote(0);
|
||||
locktower.record_vote(1);
|
||||
assert!(!locktower.is_locked_out(2, &decendants));
|
||||
assert!(!locktower.is_locked_out(2, &descendants));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_locked_out_last_vote_expired() {
|
||||
let mut locktower = Locktower::new(EpochStakes::new_for_tests(2), 0, 0.67);
|
||||
let decendants = vec![(0, vec![1, 4].into_iter().collect()), (1, HashSet::new())]
|
||||
let descendants = vec![(0, vec![1, 4].into_iter().collect()), (1, HashSet::new())]
|
||||
.into_iter()
|
||||
.collect();
|
||||
locktower.record_vote(0);
|
||||
locktower.record_vote(1);
|
||||
assert!(locktower.is_locked_out(4, &decendants));
|
||||
assert!(locktower.is_locked_out(4, &descendants));
|
||||
locktower.record_vote(4);
|
||||
assert_eq!(locktower.lockouts.votes[0].slot, 0);
|
||||
assert_eq!(locktower.lockouts.votes[0].confirmation_count, 2);
|
||||
|
|
|
@ -127,14 +127,14 @@ impl ReplayStage {
|
|||
|
||||
let locktower_start = Instant::now();
|
||||
// Locktower voting
|
||||
let decendants = bank_forks.read().unwrap().decendants();
|
||||
let descendants = bank_forks.read().unwrap().descendants();
|
||||
let ancestors = bank_forks.read().unwrap().ancestors();
|
||||
let frozen_banks = bank_forks.read().unwrap().frozen_banks();
|
||||
let mut votable: Vec<(u128, Arc<Bank>)> = frozen_banks
|
||||
.values()
|
||||
.filter(|b| b.is_votable())
|
||||
.filter(|b| !locktower.has_voted(b.slot()))
|
||||
.filter(|b| !locktower.is_locked_out(b.slot(), &decendants))
|
||||
.filter(|b| !locktower.is_locked_out(b.slot(), &descendants))
|
||||
.map(|bank| {
|
||||
(
|
||||
bank,
|
||||
|
|
Loading…
Reference in New Issue