Send local GRANDPA authority id to telemetry (#3646)

* Fix indentation

There is a space between the tabs.

* Send local GRANDPA authority id to telemetry

* Update core/finality-grandpa/src/lib.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Generalize authority_id()

* Shorten code

* Do not send unfinalized authority sets to telemetry

`update_authority_set()` is called from, among others,
import side. These updates only track a pending change
and may or may not happen, hence it's wrong to send
this set to telemetry (which would assume that this is
the current, finalized authority set).

* Send current authority set and local authority id on set change
This commit is contained in:
Michael Müller
2019-09-23 17:48:09 +02:00
committed by Robert Habermeier
parent 82e7f9e423
commit 2d6e617309
2 changed files with 51 additions and 22 deletions
@@ -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<Block: BlockT, F, R>(
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<String> =
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.
+51 -10
View File
@@ -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<B, E, Block: BlockT<Hash=H256>, 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<String> =
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<String> = 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<String> = 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<KeyStorePtr>,
) -> Option<AuthorityId> where
I: Iterator<Item = &'a AuthorityId>,
{
match keystore {
Some(keystore) => {
authorities
.find_map(|p| {
keystore.read().key_pair::<AuthorityPair>(&p)
.ok()
.map(|ap| ap.public())
})
}
None => None,
}
}