Skip to content

Commit

Permalink
Fix txpool status submit (paritytech#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
gguoss committed Sep 14, 2018
1 parent fa416d4 commit 46b1944
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ mod pool;
mod error;

pub use pool::TransactionPool;
pub use extrinsic_pool::Pool;
pub use pool::PoolApi;

6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod cli;
use substrate_client::BlockchainEvents;

use chainx_network::consensus::ConsensusNetwork;
use chainx_pool::{PoolApi, TransactionPool};
use chainx_pool::{PoolApi, TransactionPool, Pool};
use chainx_primitives::{Block, Hash, BlockId};
use chainx_api::TClient;
use cli::ChainSpec;
Expand Down Expand Up @@ -192,10 +192,10 @@ fn main() {
if matches.is_present("telemetry") {
let telemetry_url = match matches.value_of("telemetry_url") {
Some(url) => Some(url.to_owned()),
None => Some("http://aws.chainx.org:8888".to_owned()),
None => Some("ws://stats.chainx.org/submit/".to_owned()),
};
let _telemetry = telemetry::build_telemetry(telemetry_url, validator_mode);
telemetry::run_telemetry(network, client, extrinsic_pool, task_executor);
telemetry::run_telemetry(network, client, extrinsic_pool.inner(), task_executor);
let _ = runtime.block_on(exit.clone());
} else {
let _ = runtime.block_on(exit);
Expand Down
19 changes: 12 additions & 7 deletions src/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright 2018 chainpool

use substrate_network::{TransactionPool, SyncState, SyncProvider};
use substrate_network::{SyncState, SyncProvider};
use substrate_runtime_primitives::traits::{Header, As};
use substrate_client::BlockchainEvents;
use ::{PoolApi, Pool};
use ::TClient;
use tel;

use sysinfo::{get_current_pid, ProcessExt, System, SystemExt};
Expand All @@ -24,11 +26,11 @@ pub fn build_telemetry(
url: url,
on_connect: Box::new(move || {
telemetry!("system.connected";
"name" => "chainx",
"name" => "ChainX",
"implementation" => "chainx",
"version" => "0.1",
"config" => "",
"chain" => "chainx",
"chain" => "ChainX",
"authority" => is_authority
);
}),
Expand All @@ -42,7 +44,7 @@ pub fn build_telemetry(
pub fn run_telemetry(
network: ::Arc<::chainx_network::NetworkService>,
client: ::Arc<::client::TClient>,
_txpool: ::Arc<TransactionPool<::Hash, ::Block>>,
txpool: ::Arc<Pool<PoolApi<TClient>>>,
handle: TaskExecutor,
) {
let interval = Interval::new(Instant::now(), Duration::from_millis(TIMER_INTERVAL_MS));
Expand All @@ -51,6 +53,7 @@ pub fn run_telemetry(
let mut sys = System::new();
let self_pid = get_current_pid();
let client1 = client.clone();
let txpool1 = txpool.clone();
let display_notifications = interval.map_err(|e| debug!("Timer error: {:?}", e)).for_each(move |_| {
let sync_status = network.status();
if let Ok(best_block) = client1.best_block_header() {
Expand All @@ -66,6 +69,7 @@ pub fn run_telemetry(
(format!("Syncing{}", speed()), format!(", target=#{}", n)),
};
last_number = Some(best_number);
let txpool_status = txpool1.light_status();
info!(
target: "substrate",
"{}{} ({} peers), best: #{} ({})",
Expand All @@ -87,6 +91,7 @@ pub fn run_telemetry(
"peers" => num_peers,
"height" => best_number,
"best" => ?hash,
"txcount" => txpool_status.transaction_count,
"cpu" => cpu_usage,
"memory" => memory
);
Expand All @@ -101,16 +106,16 @@ pub fn run_telemetry(
Ok(())
});

/*let display_txpool_import = txpool.import_notification_stream().for_each(move |_| {
let display_txpool_import = txpool.import_notification_stream().for_each(move |_| {
let status = txpool.light_status();
telemetry!("txpool.import";
"mem_usage" => status.mem_usage,
"count" => status.transaction_count,
"sender" => status.senders);
Ok(())
});*/
});

let informant_work = display_notifications.join(display_block_import);
let informant_work = display_notifications.join3(display_block_import, display_txpool_import);
handle.spawn(informant_work.map(|_| ()));
}

Expand Down

0 comments on commit 46b1944

Please sign in to comment.