Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Prev Previous commit
Next Next commit
ensure disconnected backup collator is removed from pool
  • Loading branch information
rphmeier committed Jul 11, 2018
commit 43e7f916653cc89146b0d7802a36d877460301db
17 changes: 17 additions & 0 deletions polkadot/network/src/collator_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ impl CollatorPool {
Some(collators.primary)
}
} else {
let pos = occ.get().backup.iter().position(|a| a == &account_id)
.expect("registered collator always present in backup if not primary; qed");

occ.get_mut().backup.remove(pos);
None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not removing it from backup? That seems weird, because that would mean our backup contains disconnected AccountIds and thus the lines above could assign a disconnected AccountId as primary. Is that intentional?

}
}
Expand Down Expand Up @@ -232,6 +236,19 @@ mod tests {
assert_eq!(pool.on_disconnect(good_backup), None);
}

#[test]
fn disconnect_backup_removes_from_pool() {
let mut pool = CollatorPool::new();
let para_id: ParaId = 5.into();
let primary = [0; 32].into();
let backup = [1; 32].into();

assert_eq!(pool.on_new_collator(primary, para_id.clone()), Role::Primary);
assert_eq!(pool.on_new_collator(backup, para_id.clone()), Role::Backup);
assert_eq!(pool.on_disconnect(backup), None);
assert!(pool.parachain_collators.get(&para_id).unwrap().backup.is_empty());
}

#[test]
fn await_before_collation() {
let mut pool = CollatorPool::new();
Expand Down