cargo fmt

This commit is contained in:
James Wilson
2021-08-06 17:44:26 +01:00
parent 74cf55174e
commit 88c3db3562
17 changed files with 134 additions and 120 deletions
+13 -12
View File
@@ -1,9 +1,9 @@
use std::time::Duration;
use std::future::Future;
use serde_json::json;
use ::time::{format_description::well_known::Rfc3339, OffsetDateTime};
use common::node_types::BlockHash;
use serde_json::json;
use std::future::Future;
use std::time::Duration;
use tokio::time::{self, MissedTickBehavior};
use ::time::{ OffsetDateTime, format_description::well_known::Rfc3339 };
/// This emits fake but realistic looking telemetry messages.
/// Can be connected to a telemetry server to emit realistic messages.
@@ -11,7 +11,7 @@ pub struct FakeTelemetry {
block_time: Duration,
node_name: String,
chain: String,
message_id: usize
message_id: usize,
}
impl FakeTelemetry {
@@ -20,7 +20,7 @@ impl FakeTelemetry {
block_time,
node_name,
chain,
message_id
message_id,
}
}
@@ -33,9 +33,8 @@ impl FakeTelemetry {
where
Func: Send + FnMut(Vec<u8>) -> Fut,
Fut: Future<Output = Result<(), E>>,
E: Into<anyhow::Error>
E: Into<anyhow::Error>,
{
let id = self.message_id;
let name = self.node_name;
let chain = self.chain;
@@ -94,10 +93,12 @@ impl FakeTelemetry {
let mut new_block_every = time::interval_at(now + block_time, block_time);
new_block_every.set_missed_tick_behavior(MissedTickBehavior::Burst);
let mut system_interval_every = time::interval_at(now + Duration::from_secs(2), block_time * 2);
let mut system_interval_every =
time::interval_at(now + Duration::from_secs(2), block_time * 2);
new_block_every.set_missed_tick_behavior(MissedTickBehavior::Burst);
let mut finalised_every = time::interval_at(now + Duration::from_secs(1) + block_time * 3, block_time);
let mut finalised_every =
time::interval_at(now + Duration::from_secs(1) + block_time * 3, block_time);
new_block_every.set_missed_tick_behavior(MissedTickBehavior::Burst);
// Send messages every interval:
@@ -192,6 +193,6 @@ fn now_iso() -> String {
/// Spread the u64 across the resulting u256 hash so that it's
/// more visible in the UI.
fn block_hash(n: u64) -> BlockHash {
let a: [u8; 32] = unsafe { std::mem::transmute([n,n,n,n]) };
let a: [u8; 32] = unsafe { std::mem::transmute([n, n, n, n]) };
BlockHash::from(a)
}
}
+1 -1
View File
@@ -30,4 +30,4 @@ pub mod contains_matches;
pub mod workspace;
/// A utility to generate fake telemetry messages at realistic intervals.
pub mod fake_telemetry;
pub mod fake_telemetry;
+10 -7
View File
@@ -70,7 +70,7 @@ pub struct Server {
/// Core process that we can connect to.
core: CoreProcess,
/// Things that vary based on the mode we are in.
mode: ServerMode
mode: ServerMode,
}
pub enum ServerMode {
SingleProcessMode {
@@ -258,7 +258,10 @@ impl Server {
/// Start a server.
pub async fn start(opts: StartOpts) -> Result<Server, Error> {
let server = match opts {
StartOpts::SingleProcess { command, log_output } => {
StartOpts::SingleProcess {
command,
log_output,
} => {
let core_process = Server::start_core(log_output, command).await?;
let virtual_shard_host = core_process.host.clone();
Server {
@@ -271,13 +274,13 @@ impl Server {
handle: None,
_channel_type: PhantomData,
},
}
},
}
}
StartOpts::ShardAndCore {
core_command,
shard_command,
log_output
log_output,
} => {
let core_process = Server::start_core(log_output, core_command).await?;
Server {
@@ -286,13 +289,13 @@ impl Server {
mode: ServerMode::ShardAndCoreMode {
shard_command,
shards: DenseMap::new(),
}
},
}
}
StartOpts::ConnectToExisting {
feed_host,
submit_hosts,
log_output
log_output,
} => Server {
log_output,
core: Process {
@@ -305,7 +308,7 @@ impl Server {
submit_hosts,
next_submit_host_idx: 0,
shards: DenseMap::new(),
}
},
},
};
@@ -20,14 +20,14 @@ use crate::server::{self, Command, Server};
/// Options for the server
pub struct ServerOpts {
pub release_mode: bool,
pub log_output: bool
pub log_output: bool,
}
impl Default for ServerOpts {
fn default() -> Self {
Self {
release_mode: false,
log_output: true,
log_output: false,
}
}
}
@@ -42,7 +42,7 @@ impl Default for CoreOpts {
fn default() -> Self {
Self {
feed_timeout: None,
worker_threads: None
worker_threads: None,
}
}
}
@@ -61,7 +61,7 @@ impl Default for ShardOpts {
max_nodes_per_connection: None,
max_node_data_per_second: None,
node_block_seconds: None,
worker_threads: None
worker_threads: None,
}
}
}
@@ -92,7 +92,7 @@ pub async fn start_server(
if let Ok(bin) = std::env::var("TELEMETRY_BIN") {
return Server::start(server::StartOpts::SingleProcess {
command: Command::new(bin),
log_output: server_opts.log_output
log_output: server_opts.log_output,
})
.await
.unwrap();
@@ -107,7 +107,7 @@ pub async fn start_server(
return Server::start(server::StartOpts::ConnectToExisting {
feed_host,
submit_hosts,
log_output: server_opts.log_output
log_output: server_opts.log_output,
})
.await
.unwrap();
@@ -138,9 +138,7 @@ pub async fn start_server(
.arg(val.to_string());
}
if let Some(val) = shard_opts.worker_threads {
shard_command = shard_command
.arg("--worker-threads")
.arg(val.to_string());
shard_command = shard_command.arg("--worker-threads").arg(val.to_string());
}
// Build the core command
@@ -163,7 +161,7 @@ pub async fn start_server(
Server::start(server::StartOpts::ShardAndCore {
shard_command,
core_command,
log_output: server_opts.log_output
log_output: server_opts.log_output,
})
.await
.unwrap()
@@ -171,10 +169,20 @@ pub async fn start_server(
/// Start a telemetry core server in debug mode. see [`start_server`] for details.
pub async fn start_server_debug() -> Server {
start_server(ServerOpts::default(), CoreOpts::default(), ShardOpts::default()).await
start_server(
ServerOpts::default(),
CoreOpts::default(),
ShardOpts::default(),
)
.await
}
/// Start a telemetry core server in release mode. see [`start_server`] for details.
pub async fn start_server_release() -> Server {
start_server(ServerOpts::default(), CoreOpts::default(), ShardOpts::default()).await
start_server(
ServerOpts::default(),
CoreOpts::default(),
ShardOpts::default(),
)
.await
}