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