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

Commit

Permalink
Update metric before bailing out (#5706)
Browse files Browse the repository at this point in the history
* Update authority metrics before bailing out

Signed-off-by: Andrei Sandu <[email protected]>

* remove redundant call

Signed-off-by: Andrei Sandu <[email protected]>

* doc

Signed-off-by: Andrei Sandu <[email protected]>

* review feedback

Signed-off-by: Andrei Sandu <[email protected]>
  • Loading branch information
sandreim authored Jun 22, 2022
1 parent 130b0e2 commit 5a619f0
Showing 1 changed file with 39 additions and 32 deletions.
71 changes: 39 additions & 32 deletions node/network/gossip-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,9 @@ 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.get_key_index_and_update_metrics(&session_info).await?;

update_gossip_topology(
sender,
Expand All @@ -277,35 +274,45 @@ 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();
// 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 get_key_index_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;

match authority_check_result.as_ref() {
Ok(index) => {
gum::trace!(target: LOG_TARGET, "We are now an authority",);
self.metrics.on_is_authority();

// The subset of authorities participating in parachain consensus.
let parachain_validators_this_session = session_info.validators.len();

// First `maxValidators` entries are the parachain validators. We'll check
// 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 *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();
None
},
// Don't update on runtime errors.
Err(_) => None,
};

if let Some(validator_index) = maybe_index {
// The subset of authorities participating in parachain consensus.
let parachain_validators_this_session = session_info.validators.len();

// First `maxValidators` entries are the parachain validators. We'll check
// 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 {
self.metrics.on_is_parachain_validator();
} else {
}
},
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();
}
}
},
// Don't update on runtime errors.
Err(_) => {},
};

authority_check_result
}

async fn issue_connection_request<Sender>(
Expand Down

0 comments on commit 5a619f0

Please sign in to comment.