Skip to content

Commit 55d372c

Browse files
committed
Feature/telemetry (paritytech#28)
* Add telemetry thread * Run telemetry * Format code
1 parent fd6a5df commit 55d372c

8 files changed

+236
-29
lines changed

Cargo.lock

+33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ substrate-client-db = { git = "https://github.com/chainx-org/substrate" }
1414
substrate-keyring = { git = "https://github.com/chainx-org/substrate" }
1515
substrate-state-db = { git = "https://github.com/chainx-org/substrate" }
1616
substrate-state-machine = { git = "https://github.com/chainx-org/substrate" }
17+
substrate-telemetry = { git = "https://github.com/chainx-org/substrate" }
1718
substrate-codec = { git = "https://github.com/chainx-org/substrate", default_features = false }
1819
substrate-bft = { git = "https://github.com/chainx-org/substrate", default_features = false }
1920
substrate-rpc-servers = { git = "https://github.com/chainx-org/substrate" }
@@ -38,8 +39,11 @@ rhododendron = "0.3"
3839
hex-literal = "0.1"
3940
exit-future = "0.1"
4041
futures = "0.1.17"
42+
ansi_term = "0.10"
43+
sysinfo = "0.5.7"
4144
tokio = "0.1.7"
4245
clap = "2.30.0"
46+
slog = "^2"
4347
log = "0.3"
4448

4549
[workspace]

src/cli.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ pub fn build_cli() -> App<'static, 'static> {
2828
.help("Specify p2p protocol TCP port")
2929
.takes_value(true),
3030
)
31+
.arg(
32+
Arg::with_name("telemetry-url")
33+
.long("telemetry-url")
34+
.value_name("TELEMETRY_URL")
35+
.help("The URL of the telemetry server. Implies --telemetry")
36+
.takes_value(true),
37+
)
38+
.arg(
39+
Arg::with_name("telemetry")
40+
.long("telemetry")
41+
.value_name("TELEMETRY")
42+
.help("Should connect telemetry")
43+
.takes_value(false),
44+
)
3145
.arg(
3246
Arg::with_name("bootnodes")
3347
.long("bootnodes")
@@ -73,7 +87,7 @@ pub fn parse_address(
7387
default: &str,
7488
port_param: &str,
7589
matches: &ArgMatches,
76-
) -> Result<SocketAddr, String> {
90+
) -> Result<SocketAddr, String> {
7791
let mut address: SocketAddr = default.parse().ok().ok_or_else(|| {
7892
format!("Invalid address specified for --{}.", port_param)
7993
})?;

src/client.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ pub fn build_client(db_path: &str, chainspec: ChainSpec) -> Arc<TClient> {
2323
pruning: state_db::PruningMode::default(),
2424
},
2525
FINALIZATION_WINDOW,
26-
).unwrap(),
27-
);
26+
).unwrap(),
27+
);
2828

29-
let executor = substrate_client::LocalCallExecutor::new(
30-
backend.clone(),
31-
NativeExecutor::new());
29+
let executor = substrate_client::LocalCallExecutor::new(backend.clone(), NativeExecutor::new());
3230

3331
let genesis_config = super::genesis_config::testnet_genesis(chainspec);
3432

@@ -39,6 +37,6 @@ pub fn build_client(db_path: &str, chainspec: ChainSpec) -> Arc<TClient> {
3937
executor,
4038
genesis_config,
4139
ExecutionStrategy::NativeWhenPossible,
42-
).unwrap(),
43-
)
40+
).unwrap(),
41+
)
4442
}

src/genesis_config.rs

+28-14
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
// Copyright 2018 chainpool
22

3-
use chainx_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,SessionConfig, StakingConfig, TimestampConfig,BalancesConfig};
3+
use chainx_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
4+
SessionConfig, StakingConfig, TimestampConfig, BalancesConfig};
45
use super::cli::ChainSpec;
56
use keyring::Keyring;
67
use ed25519;
78

89

910
pub fn testnet_genesis(chainspec: ChainSpec) -> GenesisConfig {
10-
let auth1 = ed25519::Pair::from_seed(b"Alice ").public().into();
11-
let auth2 = ed25519::Pair::from_seed(b"Bob ").public().into();
12-
let auth3 = ed25519::Pair::from_seed(b"Gavin ").public().into();
13-
let auth4 = ed25519::Pair::from_seed(b"Satoshi ").public().into();
11+
let auth1 = ed25519::Pair::from_seed(b"Alice ")
12+
.public()
13+
.into();
14+
let auth2 = ed25519::Pair::from_seed(b"Bob ")
15+
.public()
16+
.into();
17+
let auth3 = ed25519::Pair::from_seed(b"Gavin ")
18+
.public()
19+
.into();
20+
let auth4 = ed25519::Pair::from_seed(b"Satoshi ")
21+
.public()
22+
.into();
1423
let initial_authorities = match chainspec {
15-
ChainSpec::Dev => vec![auth1,],
16-
ChainSpec::Local => vec![auth1, auth2,],
24+
ChainSpec::Dev => vec![auth1],
25+
ChainSpec::Local => vec![auth1, auth2],
1726
ChainSpec::Multi => vec![auth1, auth2, auth3, auth4],
1827
};
1928
GenesisConfig {
2029
consensus: Some(ConsensusConfig {
2130
code: include_bytes!(
22-
"../runtime/wasm/target/wasm32-unknown-unknown/release/chainx_runtime.compact.wasm"
23-
).to_vec(),
24-
authorities: initial_authorities.clone(),
31+
"../runtime/wasm/target/wasm32-unknown-unknown/release/chainx_runtime.compact.wasm"
32+
).to_vec(),
33+
authorities: initial_authorities.clone(),
2534
}),
2635
system: None,
2736
balances: Some(BalancesConfig {
@@ -32,13 +41,18 @@ pub fn testnet_genesis(chainspec: ChainSpec) -> GenesisConfig {
3241
creation_fee: 0,
3342
reclaim_rebate: 0,
3443
balances: vec![
35-
(Keyring::Alice.to_raw_public().into(),10000),
36-
(Keyring::Bob.to_raw_public().into(),10000),
37-
(Keyring::Charlie.to_raw_public().into(),10000)],
44+
(Keyring::Alice.to_raw_public().into(), 10000),
45+
(Keyring::Bob.to_raw_public().into(), 10000),
46+
(Keyring::Charlie.to_raw_public().into(), 10000),
47+
],
3848
}),
3949

4050
session: Some(SessionConfig {
41-
validators: initial_authorities.iter().cloned().map(Into::into).collect(),
51+
validators: initial_authorities
52+
.iter()
53+
.cloned()
54+
.map(Into::into)
55+
.collect(),
4256
session_length: 720, // that's 1 hour per session.
4357
}),
4458
staking: Some(StakingConfig {

src/main.rs

+23-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extern crate substrate_network;
88
extern crate substrate_network_libp2p;
99
extern crate substrate_primitives;
1010
extern crate substrate_rpc_servers as rpc_server;
11+
#[macro_use]
12+
extern crate substrate_telemetry as tel;
1113
extern crate substrate_runtime_primitives;
1214
extern crate substrate_state_db as state_db;
1315
extern crate substrate_state_machine as state_machine;
@@ -31,15 +33,20 @@ extern crate hex_literal;
3133
extern crate jsonrpc_http_server;
3234
extern crate jsonrpc_ws_server;
3335
extern crate rhododendron;
36+
extern crate ansi_term;
37+
extern crate sysinfo;
3438
extern crate tokio;
3539
#[macro_use]
40+
extern crate slog;
41+
#[macro_use]
3642
extern crate log;
3743

38-
mod cli;
39-
mod client;
4044
mod genesis_config;
45+
mod telemetry;
4146
mod network;
47+
mod client;
4248
mod rpc;
49+
mod cli;
4350

4451
use substrate_client::BlockchainEvents;
4552

@@ -74,7 +81,7 @@ fn main() {
7481
let port = match matches.value_of("port") {
7582
Some(port) => port
7683
.parse()
77-
.map_err(|_| "Invalid p2p port value specified.")
84+
.map_err(|_| "invalid p2p port value specified.")
7885
.unwrap(),
7986
None => 20222,
8087
};
@@ -147,7 +154,7 @@ fn main() {
147154
}
148155
};
149156

150-
let consensus_net = ConsensusNetwork::new(network, client.clone());
157+
let consensus_net = ConsensusNetwork::new(network.clone(), client.clone());
151158
Some(consensus::Service::new(
152159
client.clone(),
153160
client.clone(),
@@ -162,6 +169,17 @@ fn main() {
162169

163170
let (_rpc_http, _rpc_ws) = rpc::start(&client, &task_executor, &matches, &extrinsic_pool);
164171

165-
let _ = runtime.block_on(exit);
172+
if matches.is_present("telemetry") {
173+
let telemetry_url = match matches.value_of("telemetry_url") {
174+
Some(url) => Some(url.to_owned()),
175+
None => Some("http://aws.chainx.org:8888".to_owned()),
176+
};
177+
let _telemetry = telemetry::build_telemetry(telemetry_url, validator_mode);
178+
telemetry::run_telemetry(network, client, extrinsic_pool, task_executor);
179+
let _ = runtime.block_on(exit.clone());
180+
} else {
181+
let _ = runtime.block_on(exit);
182+
}
183+
166184
exit_send.fire();
167185
}

src/rpc.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
use jsonrpc_http_server::Server as HttpServer;
44
use jsonrpc_ws_server::Server as WsServer;
5-
use chainx_rpc::chainext::ChainExt;
6-
use rpc_server::apis::chain::Chain;
75
use chainx_pool::TransactionPool;
86
use tokio::runtime::TaskExecutor;
97
use chainx_api::ChainXApi;

0 commit comments

Comments
 (0)