From f5ba8a2ad97c7a4e6ab947493e3c7d6d07bfee45 Mon Sep 17 00:00:00 2001
From: Pierre Krieger <pierre.krieger1708@gmail.com>
Date: Thu, 21 Feb 2019 10:03:47 +0100
Subject: [PATCH] Report the network PeerId to the telemetry (#1835)

* Report the network PeerId to the telemetry

* Fix accidental paste
---
 substrate/core/network/src/service.rs | 9 ++++++++-
 substrate/core/service/src/lib.rs     | 4 +++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/substrate/core/network/src/service.rs b/substrate/core/network/src/service.rs
index 81e79dbad9f..ac6789f718c 100644
--- a/substrate/core/network/src/service.rs
+++ b/substrate/core/network/src/service.rs
@@ -20,7 +20,7 @@ use std::{io, thread};
 use log::{warn, debug, error, trace};
 use futures::{Async, Future, Stream, stream, sync::oneshot};
 use parking_lot::Mutex;
-use network_libp2p::{ProtocolId, PeerId, NetworkConfiguration, NodeIndex, ErrorKind, Severity};
+use network_libp2p::{ProtocolId, NetworkConfiguration, NodeIndex, ErrorKind, Severity};
 use network_libp2p::{start_service, parse_str_addr, Service as NetworkService, ServiceEvent as NetworkServiceEvent};
 use network_libp2p::{Protocol as Libp2pProtocol, RegisteredProtocol};
 use consensus::import_queue::{ImportQueue, Link};
@@ -36,6 +36,8 @@ use crate::specialization::NetworkSpecialization;
 use tokio::prelude::task::AtomicTask;
 use tokio::runtime::Runtime;
 
+pub use network_libp2p::PeerId;
+
 /// Type that represents fetch completion future.
 pub type FetchFuture = oneshot::Receiver<Vec<u8>>;
 
@@ -180,6 +182,11 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>> Service<B, S> {
 		self.network.lock().average_upload_per_sec()
 	}
 
+	/// Returns the network identity of the node.
+	pub fn local_peer_id(&self) -> PeerId {
+		self.network.lock().peer_id().clone()
+	}
+
 	/// Called when a new block is imported by the client.
 	pub fn on_block_imported(&self, hash: B::Hash, header: B::Header) {
 		let _ = self
diff --git a/substrate/core/service/src/lib.rs b/substrate/core/service/src/lib.rs
index 6f7e5a5e9ca..efd86a4c791 100644
--- a/substrate/core/service/src/lib.rs
+++ b/substrate/core/service/src/lib.rs
@@ -271,6 +271,7 @@ impl<Components: components::Components> Service<Components> {
 		// Telemetry
 		let telemetry = config.telemetry_url.clone().map(|url| {
 			let is_authority = config.roles == Roles::AUTHORITY;
+			let network_id = network.local_peer_id().to_base58();
 			let pubkey = format!("{}", public_key);
 			let name = config.name.clone();
 			let impl_name = config.impl_name.to_owned();
@@ -286,7 +287,8 @@ impl<Components: components::Components> Service<Components> {
 						"config" => "",
 						"chain" => chain_name.clone(),
 						"pubkey" => &pubkey,
-						"authority" => is_authority
+						"authority" => is_authority,
+						"network_id" => network_id.clone()
 					);
 				}),
 			}))
-- 
GitLab