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

Commit

Permalink
make helper error types generics (#7878)
Browse files Browse the repository at this point in the history
* make helper error types generics

* avoid From<io::Error> dep in runner helper logic

* slip of the pen, bump futures to 0.3.9

* more generics

* generic var spaces

Co-authored-by: Andronik Ordian <[email protected]>

* network-gossip: add metric for number of local messages (#7871)

* network-gossip: add metric for number of local messages

* grandpa: fix GossipEngine missing metrics registry parameter

* network-gossip: increase known messages cache size

* network-gossip: fix tests

* grandpa: remove unnecessary clone

Co-authored-by: Max Inden <[email protected]>

* network-gossip: count registered and expired messages separately

* network-gossip: add comment on known messages cache size

* network-gossip: extend comment with cache size in memory

Co-authored-by: Max Inden <[email protected]>

* Clean-up pass in network/src/protocol.rs (#7889)

* Remove statistics system

* Remove ContextData struct

* Remove next_request_id

* Some TryFrom nit-picking

* Use constants for peer sets

* contracts: Don't read the previous value when overwriting a storage item (#7879)

* Add `len` function that can return the length of a storage item efficiently

* Make use of the new len function in contracts

* Fix benchmarks

* cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_contracts --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/contracts/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* Remove unused imports

Co-authored-by: Parity Benchmarking Bot <[email protected]>

* Fix clear prefix check to avoid erasing child trie roots. (#7848)

* Fix clear prefix check to avoid erasing child trie roots.

* Renaming and extend existing test with check.

* last nitpicks.

* use follow paths to std standarad components

* line width

Co-authored-by: Bernhard Schuster <[email protected]>
Co-authored-by: Andronik Ordian <[email protected]>
Co-authored-by: André Silva <[email protected]>
Co-authored-by: Max Inden <[email protected]>
Co-authored-by: Pierre Krieger <[email protected]>
Co-authored-by: Alexander Theißen <[email protected]>
Co-authored-by: Parity Benchmarking Bot <[email protected]>
Co-authored-by: cheme <[email protected]>
  • Loading branch information
9 people authored Jan 13, 2021
1 parent 1334eb7 commit c2aa425
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion bin/node-template/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub fn run() -> sc_cli::Result<()> {
match config.role {
Role::Light => service::new_light(config),
_ => service::new_full(config),
}
}.map_err(sc_cli::Error::Service)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ crate-type = ["cdylib", "rlib"]
# third-party dependencies
codec = { package = "parity-scale-codec", version = "1.3.6" }
serde = { version = "1.0.102", features = ["derive"] }
futures = { version = "0.3.1", features = ["compat"] }
futures = { version = "0.3.9", features = ["compat"] }
hex-literal = "0.3.1"
log = "0.4.8"
rand = "0.7.2"
Expand Down
2 changes: 1 addition & 1 deletion bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn run() -> Result<()> {
match config.role {
Role::Light => service::new_light(config),
_ => service::new_full(config),
}
}.map_err(sc_cli::Error::Service)
})
}
Some(Subcommand::Inspect(cmd)) => {
Expand Down
55 changes: 34 additions & 21 deletions client/cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ use log::info;
use sc_service::{Configuration, TaskType, TaskManager};
use sp_utils::metrics::{TOKIO_THREADS_ALIVE, TOKIO_THREADS_TOTAL};
use std::marker::PhantomData;
use sc_service::Error as ServiceError;
use crate::error::Error as CliError;

#[cfg(target_family = "unix")]
async fn main<F, E>(func: F) -> std::result::Result<(), Box<dyn std::error::Error>>
async fn main<F, E>(func: F) -> std::result::Result<(), E>
where
F: Future<Output = std::result::Result<(), E>> + future::FusedFuture,
E: 'static + std::error::Error,
E: std::error::Error + Send + Sync + 'static + From<ServiceError>,
{
use tokio::signal::unix::{signal, SignalKind};

let mut stream_int = signal(SignalKind::interrupt())?;
let mut stream_term = signal(SignalKind::terminate())?;
let mut stream_int = signal(SignalKind::interrupt()).map_err(ServiceError::Io)?;
let mut stream_term = signal(SignalKind::terminate()).map_err(ServiceError::Io)?;

let t1 = stream_int.recv().fuse();
let t2 = stream_term.recv().fuse();
Expand All @@ -55,10 +57,10 @@ where
}

#[cfg(not(unix))]
async fn main<F, E>(func: F) -> std::result::Result<(), Box<dyn std::error::Error>>
async fn main<F, E>(func: F) -> std::result::Result<(), E>
where
F: Future<Output = std::result::Result<(), E>> + future::FusedFuture,
E: 'static + std::error::Error,
E: std::error::Error + Send + Sync + 'static + From<ServiceError>,
{
use tokio::signal::ctrl_c;

Expand Down Expand Up @@ -90,19 +92,19 @@ pub fn build_runtime() -> std::result::Result<tokio::runtime::Runtime, std::io::
.build()
}

fn run_until_exit<FUT, ERR>(
fn run_until_exit<F, E>(
mut tokio_runtime: tokio::runtime::Runtime,
future: FUT,
future: F,
task_manager: TaskManager,
) -> Result<()>
) -> std::result::Result<(), E>
where
FUT: Future<Output = std::result::Result<(), ERR>> + future::Future,
ERR: 'static + std::error::Error,
F: Future<Output = std::result::Result<(), E>> + future::Future,
E: std::error::Error + Send + Sync + 'static + From<ServiceError>,
{
let f = future.fuse();
pin_mut!(f);

tokio_runtime.block_on(main(f)).map_err(|e| e.to_string())?;
tokio_runtime.block_on(main(f))?;
tokio_runtime.block_on(task_manager.clean_shutdown());

Ok(())
Expand Down Expand Up @@ -172,32 +174,43 @@ impl<C: SubstrateCli> Runner<C> {

/// A helper function that runs a node with tokio and stops if the process receives the signal
/// `SIGTERM` or `SIGINT`.
pub fn run_node_until_exit<F: Future<Output = sc_service::error::Result<TaskManager>>>(
pub fn run_node_until_exit<F, E>(
mut self,
initialize: impl FnOnce(Configuration) -> F,
) -> Result<()> {
) -> std::result::Result<(), E>
where
F: Future<Output = std::result::Result<TaskManager, E>>,
E: std::error::Error + Send + Sync + 'static + From<ServiceError>,
{
self.print_node_infos();
let mut task_manager = self.tokio_runtime.block_on(initialize(self.config))?;
let res = self.tokio_runtime.block_on(main(task_manager.future().fuse()));
self.tokio_runtime.block_on(task_manager.clean_shutdown());
res.map_err(|e| e.to_string().into())
Ok(res?)
}

/// A helper function that runs a command with the configuration of this node.
pub fn sync_run(self, runner: impl FnOnce(Configuration) -> Result<()>) -> Result<()> {
pub fn sync_run<E>(
self,
runner: impl FnOnce(Configuration) -> std::result::Result<(), E>
) -> std::result::Result<(), E>
where
E: std::error::Error + Send + Sync + 'static + From<ServiceError>,
{
runner(self.config)
}

/// A helper function that runs a future with tokio and stops if the process receives
/// the signal `SIGTERM` or `SIGINT`.
pub fn async_run<FUT>(
self, runner: impl FnOnce(Configuration) -> Result<(FUT, TaskManager)>,
) -> Result<()>
pub fn async_run<F, E>(
self, runner: impl FnOnce(Configuration) -> std::result::Result<(F, TaskManager), E>,
) -> std::result::Result<(), E>
where
FUT: Future<Output = Result<()>>,
F: Future<Output = std::result::Result<(), E>>,
E: std::error::Error + Send + Sync + 'static + From<ServiceError> + From<CliError>,
{
let (future, task_manager) = runner(self.config)?;
run_until_exit(self.tokio_runtime, future, task_manager)
run_until_exit::<_, E>(self.tokio_runtime, future, task_manager)
}

/// Get an immutable reference to the node Configuration
Expand Down

0 comments on commit c2aa425

Please sign in to comment.