Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
More timely block import notifications (#306)
Browse files Browse the repository at this point in the history
* More timely block import notifications

* Grumbles.

* More wrapping

* Fix build

* Fixes
  • Loading branch information
gavofyork authored Jul 13, 2018
1 parent 32cec9b commit 42550d0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ substrate/pwasm-alloc/Cargo.lock
substrate/pwasm-libc/Cargo.lock
demo/runtime/wasm/target/
**/._*
.vscode
.vscode
polkadot.*
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion polkadot/cli/src/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExe
let client = service.client();
let display_block_import = client.import_notification_stream().for_each(|n| {
info!(target: "polkadot", "Imported #{} ({})", n.header.number, n.hash);
telemetry!("block.import"; "height" => n.header.number, "best" => ?n.hash);
Ok(())
});

Expand Down
2 changes: 2 additions & 0 deletions substrate/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ triehash = "0.1"
hex-literal = "0.1"
futures = "0.1.17"
ed25519 = { path = "../ed25519" }
slog = "^2"
substrate-bft = { path = "../bft" }
substrate-codec = { path = "../codec" }
substrate-executor = { path = "../executor" }
Expand All @@ -20,6 +21,7 @@ substrate-runtime-support = { path = "../runtime-support" }
substrate-runtime-primitives = { path = "../runtime/primitives" }
substrate-state-machine = { path = "../state-machine" }
substrate-keyring = { path = "../../substrate/keyring" }
substrate-telemetry = { path = "../telemetry" }

[dev-dependencies]
substrate-test-client = { path = "../test-client" }
10 changes: 8 additions & 2 deletions substrate/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use futures::sync::mpsc;
use parking_lot::{Mutex, RwLock};
use primitives::AuthorityId;
use runtime_primitives::{bft::Justification, generic::{BlockId, SignedBlock, Block as RuntimeBlock}};
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, One};
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, One, As};
use runtime_primitives::BuildStorage;
use primitives::storage::{StorageKey, StorageData};
use codec::Slicable;
Expand Down Expand Up @@ -98,7 +98,7 @@ pub enum BlockStatus {
}

/// Block data origin.
#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum BlockOrigin {
/// Genesis block built into the client.
Genesis,
Expand Down Expand Up @@ -297,9 +297,15 @@ impl<B, E, Block> Client<B, E, Block> where
}
let hash = header.hash();
let _import_lock = self.import_lock.lock();
let height: u64 = header.number().as_();
*self.importing_block.write() = Some(hash);
let result = self.execute_and_import_block(origin, hash, header, justification, body);
*self.importing_block.write() = None;
telemetry!("block.import";
"height" => height,
"best" => ?hash,
"origin" => ?origin
);
result
}

Expand Down
2 changes: 2 additions & 0 deletions substrate/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ extern crate substrate_runtime_primitives as runtime_primitives;
extern crate substrate_state_machine as state_machine;
#[cfg(test)] extern crate substrate_keyring as keyring;
#[cfg(test)] extern crate substrate_test_client as test_client;
#[macro_use] extern crate substrate_telemetry;
#[macro_use] extern crate slog; // needed until we can reexport `slog_info` from `substrate_telemetry`

extern crate ed25519;
extern crate futures;
Expand Down
7 changes: 6 additions & 1 deletion substrate/telemetry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub struct TelemetryConfig {
pub on_connect: Box<Fn() + Send + 'static>,
}

/// Size of the channel for passing messages to telemetry thread.
const CHANNEL_SIZE: usize = 262144;

/// Initialise telemetry.
pub fn init_telemetry(config: TelemetryConfig) -> slog_scope::GlobalLoggerGuard {
let log = slog::Logger::root(
Expand All @@ -58,7 +61,9 @@ pub fn init_telemetry(config: TelemetryConfig) -> slog_scope::GlobalLoggerGuard
first_time: true, // ensures that on_connect will be called.
}
).fuse()
).build().fuse(), o!()
).chan_size(CHANNEL_SIZE)
.overflow_strategy(slog_async::OverflowStrategy::DropAndReport)
.build().fuse(), o!()
);
slog_scope::set_global_logger(log)
}
Expand Down

0 comments on commit 42550d0

Please sign in to comment.