Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Some fixes the compiler pointed out to me (#4482)
Browse files Browse the repository at this point in the history
* Fix bug in availability-distribution.

Old fetches would not get cancelled as intended.

* Fix a few more warnings.
  • Loading branch information
eskimor authored Dec 7, 2021
1 parent 52ab0e4 commit a6e1f37
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ impl FetchTask {
/// Remove leaves and cancel the task, if it was the last one and the task has still been
/// fetching.
pub fn remove_leaves(&mut self, leaves: &HashSet<Hash>) {
self.live_in.difference(leaves);
for leaf in leaves {
self.live_in.remove(leaf);
}
if self.live_in.is_empty() && !self.is_finished() {
self.state = FetchedState::Canceled
}
Expand Down
33 changes: 12 additions & 21 deletions node/network/collator-protocol/src/collator_side/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use polkadot_node_subsystem_util::{
};
use polkadot_primitives::v1::{
AuthorityDiscoveryId, CandidateHash, CandidateReceipt, CollatorPair, CoreIndex, CoreState,
GroupIndex, Hash, Id as ParaId,
Hash, Id as ParaId,
};
use polkadot_subsystem::{
jaeger,
Expand Down Expand Up @@ -148,20 +148,23 @@ impl metrics::Metrics for Metrics {
}
}

/// The group of validators that is assigned to our para at a given point of time.
/// Info about validators we are currently connected to.
///
/// This structure is responsible for keeping track of which validators belong to a certain group for a para. It also
/// stores a mapping from [`PeerId`] to [`ValidatorId`] as we learn about it over the lifetime of this object. Besides
/// that it also keeps track to which validators we advertised our collation.
/// It keeps track to which validators we advertised our collation.
#[derive(Debug)]
struct ValidatorGroup {
/// All [`AuthorityDiscoveryId`]'s that are assigned to us in this group.
discovery_ids: HashSet<AuthorityDiscoveryId>,
/// All [`ValidatorId`]'s of the current group to that we advertised our collation.
advertised_to: HashSet<AuthorityDiscoveryId>,
}

impl ValidatorGroup {
/// Create a new `ValidatorGroup`
///
/// without any advertisements.
fn new() -> Self {
Self { advertised_to: HashSet::new() }
}

/// Returns `true` if we should advertise our collation to the given peer.
fn should_advertise_to(
&self,
Expand All @@ -188,12 +191,6 @@ impl ValidatorGroup {
}
}

impl From<HashSet<AuthorityDiscoveryId>> for ValidatorGroup {
fn from(discovery_ids: HashSet<AuthorityDiscoveryId>) -> Self {
Self { discovery_ids, advertised_to: HashSet::new() }
}
}

/// The status of a collation as seen from the collator.
enum CollationStatus {
/// The collation was created, but we did not advertise it to any validator.
Expand Down Expand Up @@ -406,13 +403,10 @@ where
"Accepted collation, connecting to validators."
);

let validator_group: HashSet<_> =
current_validators.validators.iter().map(Clone::clone).collect();

// Issue a discovery request for the validators of the current group:
connect_to_validators(ctx, current_validators.validators.into_iter().collect()).await;

state.our_validators_groups.insert(relay_parent, validator_group.into());
state.our_validators_groups.insert(relay_parent, ValidatorGroup::new());

if let Some(result_sender) = result_sender {
state.collation_result_senders.insert(receipt.hash(), result_sender);
Expand Down Expand Up @@ -458,8 +452,6 @@ where
/// Validators of a particular group index.
#[derive(Debug)]
struct GroupValidators {
/// The group those validators belong to.
group: GroupIndex,
/// The validators of above group (their discovery keys).
validators: Vec<AuthorityDiscoveryId>,
}
Expand Down Expand Up @@ -498,8 +490,7 @@ where
let current_validators =
current_validators.iter().map(|i| validators[i.0 as usize].clone()).collect();

let current_validators =
GroupValidators { group: current_group_index, validators: current_validators };
let current_validators = GroupValidators { validators: current_validators };

Ok(current_validators)
}
Expand Down
2 changes: 0 additions & 2 deletions node/network/collator-protocol/src/collator_side/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ impl TestCandidateBuilder {
#[derive(Clone)]
struct TestState {
para_id: ParaId,
validators: Vec<Sr25519Keyring>,
session_info: SessionInfo,
group_rotation_info: GroupRotationInfo,
validator_peer_id: Vec<PeerId>,
Expand Down Expand Up @@ -121,7 +120,6 @@ impl Default for TestState {

Self {
para_id,
validators,
session_info: SessionInfo {
validators: validator_public,
discovery_keys,
Expand Down
2 changes: 0 additions & 2 deletions node/network/collator-protocol/src/validator_side/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ struct TestState {
chain_ids: Vec<ParaId>,
relay_parent: Hash,
collators: Vec<CollatorPair>,
validators: Vec<Sr25519Keyring>,
validator_public: Vec<ValidatorId>,
validator_groups: Vec<Vec<ValidatorIndex>>,
group_rotation_info: GroupRotationInfo,
Expand Down Expand Up @@ -102,7 +101,6 @@ impl Default for TestState {
chain_ids,
relay_parent,
collators,
validators,
validator_public,
validator_groups,
group_rotation_info,
Expand Down

0 comments on commit a6e1f37

Please sign in to comment.