Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions node/network/gossip-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,10 @@ where
}
}

// Gossip topology is only relevant for authorities in the current session.
let our_index =
ensure_i_am_an_authority(&self.keystore, &session_info.discovery_keys).await?;

if is_new_session {
self.update_authority_status_metrics(&session_info).await;
// Gossip topology is only relevant for authorities in the current session.
let our_index =
self.check_authority_status_and_update_metrics(&session_info).await?;

update_gossip_topology(
sender,
Expand All @@ -277,21 +275,31 @@ where
Ok(())
}

async fn update_authority_status_metrics(&mut self, session_info: &SessionInfo) {
let maybe_index =
match ensure_i_am_an_authority(&self.keystore, &session_info.discovery_keys).await {
Ok(index) => {
self.metrics.on_is_authority();
Some(index)
},
Err(util::Error::NotAValidator) => {
self.metrics.on_is_not_authority();
self.metrics.on_is_not_parachain_validator();
None
},
// Don't update on runtime errors.
Err(_) => None,
};
// Checks if the node is an authority and also updates `polkadot_node_is_authority` and
// `polkadot_node_is_parachain_validator` metrics accordingly.
// On success, returns the index of our keys in `session_info.discovery_keys`.
async fn check_authority_status_and_update_metrics(
&mut self,
session_info: &SessionInfo,
) -> Result<usize, util::Error> {
let authority_check_result =
ensure_i_am_an_authority(&self.keystore, &session_info.discovery_keys).await;

let maybe_index = match authority_check_result.as_ref() {
Ok(index) => {
gum::trace!(target: LOG_TARGET, "We are now an authority",);
self.metrics.on_is_authority();
Some(*index)
},
Err(util::Error::NotAValidator) => {
gum::trace!(target: LOG_TARGET, "We are no longer an authority",);
self.metrics.on_is_not_authority();
self.metrics.on_is_not_parachain_validator();
None
},
// Don't update on runtime errors.
Err(_) => None,
};

if let Some(validator_index) = maybe_index {
// The subset of authorities participating in parachain consensus.
Expand All @@ -301,11 +309,15 @@ where
// if our index is in this set to avoid searching for the keys.
// https://github.com/paritytech/polkadot/blob/a52dca2be7840b23c19c153cf7e110b1e3e475f8/runtime/parachains/src/configuration.rs#L148
if validator_index < parachain_validators_this_session {
gum::trace!(target: LOG_TARGET, "We are now a parachain validator",);
self.metrics.on_is_parachain_validator();
} else {
gum::trace!(target: LOG_TARGET, "We are no longer a parachain validator",);
self.metrics.on_is_not_parachain_validator();
}
}

authority_check_result
}

async fn issue_connection_request<Sender>(
Expand Down