diff --git a/substrate/core/finality-grandpa/src/aux_schema.rs b/substrate/core/finality-grandpa/src/aux_schema.rs index 599604c1d3..a2b05a0cd6 100644 --- a/substrate/core/finality-grandpa/src/aux_schema.rs +++ b/substrate/core/finality-grandpa/src/aux_schema.rs @@ -25,7 +25,6 @@ use fork_tree::ForkTree; use grandpa::round::State as RoundState; use sr_primitives::traits::{Block as BlockT, NumberFor}; use log::{info, warn}; -use substrate_telemetry::{telemetry, CONSENSUS_INFO}; use fg_primitives::{AuthorityId, AuthorityWeight, SetId, RoundNumber}; use crate::authorities::{AuthoritySet, SharedAuthoritySet, PendingChange, DelayKind}; @@ -376,17 +375,6 @@ pub(crate) fn update_authority_set( let encoded_set = set.encode(); if let Some(new_set) = new_set { - telemetry!(CONSENSUS_INFO; "afg.authority_set"; - "hash" => ?new_set.canon_hash, - "number" => ?new_set.canon_number, - "authority_set_id" => ?new_set.set_id, - "authorities" => { - let authorities: Vec = - new_set.authorities.iter().map(|(id, _)| format!("{}", id)).collect(); - format!("{:?}", authorities) - } - ); - // we also overwrite the "last completed round" entry with a blank slate // because from the perspective of the finality gadget, the chain has // reset. diff --git a/substrate/core/finality-grandpa/src/lib.rs b/substrate/core/finality-grandpa/src/lib.rs index 36af66af22..7f71bfadb3 100644 --- a/substrate/core/finality-grandpa/src/lib.rs +++ b/substrate/core/finality-grandpa/src/lib.rs @@ -68,7 +68,7 @@ use fg_primitives::{GrandpaApi, AuthorityPair}; use keystore::KeyStorePtr; use inherents::InherentDataProviders; use consensus_common::SelectChain; -use primitives::{H256, Blake2Hasher}; +use primitives::{H256, Blake2Hasher, Pair}; use substrate_telemetry::{telemetry, CONSENSUS_INFO, CONSENSUS_DEBUG, CONSENSUS_WARN}; use serde_json; @@ -523,20 +523,25 @@ pub fn run_grandpa_voter, N, RA, SC, X>( register_finality_tracker_inherent_data_provider(client.clone(), &inherent_data_providers)?; + let conf = config.clone(); let telemetry_task = if let Some(telemetry_on_connect) = telemetry_on_connect { let authorities = persistent_data.authority_set.clone(); let events = telemetry_on_connect .for_each(move |_| { + let curr = authorities.current_authorities(); + let mut auths = curr.voters().into_iter().map(|(p, _)| p); + let maybe_authority_id = authority_id(&mut auths, &conf.keystore) + .unwrap_or(Default::default()); + telemetry!(CONSENSUS_INFO; "afg.authority_set"; - "authority_set_id" => ?authorities.set_id(), - "authorities" => { - let curr = authorities.current_authorities(); - let voters = curr.voters(); - let authorities: Vec = - voters.iter().map(|(id, _)| id.to_string()).collect(); + "authority_id" => maybe_authority_id.to_string(), + "authority_set_id" => ?authorities.set_id(), + "authorities" => { + let authorities: Vec = curr.voters() + .iter().map(|(id, _)| id.to_string()).collect(); serde_json::to_string(&authorities) .expect("authorities is always at least an empty vector; elements are always of type string") - } + } ); Ok(()) }) @@ -632,10 +637,26 @@ where "name" => ?self.env.config.name(), "set_id" => ?self.env.set_id ); + let chain_info = self.env.inner.info(); + + let maybe_authority_id = is_voter(&self.env.voters, &self.env.config.keystore) + .map(|ap| ap.public()) + .unwrap_or(Default::default()); + telemetry!(CONSENSUS_INFO; "afg.authority_set"; + "number" => ?chain_info.chain.finalized_number, + "hash" => ?chain_info.chain.finalized_hash, + "authority_id" => maybe_authority_id.to_string(), + "authority_set_id" => ?self.env.set_id, + "authorities" => { + let authorities: Vec = self.env.voters.voters() + .iter().map(|(id, _)| id.to_string()).collect(); + serde_json::to_string(&authorities) + .expect("authorities is always at least an empty vector; elements are always of type string") + }, + ); + match &*self.env.voter_set_state.read() { VoterSetState::Live { completed_rounds, .. } => { - let chain_info = self.env.inner.info(); - let last_finalized = ( chain_info.chain.finalized_hash, chain_info.chain.finalized_number, @@ -842,3 +863,23 @@ fn is_voter( None => None, } } + +/// Returns the authority id of this node, if available. +fn authority_id<'a, I>( + authorities: &mut I, + keystore: &Option, +) -> Option where + I: Iterator, +{ + match keystore { + Some(keystore) => { + authorities + .find_map(|p| { + keystore.read().key_pair::(&p) + .ok() + .map(|ap| ap.public()) + }) + } + None => None, + } +}