mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 01:07:57 +00:00
make helper error types generics (#7878)
* 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 <write@reusable.software> * 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 <mail@max-inden.de> * 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 <mail@max-inden.de> * 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 <admin@parity.io> * 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 <bernhard@parity.io> Co-authored-by: Andronik Ordian <write@reusable.software> Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> Co-authored-by: Max Inden <mail@max-inden.de> Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com> Co-authored-by: Alexander Theißen <alex.theissen@me.com> Co-authored-by: Parity Benchmarking Bot <admin@parity.io> Co-authored-by: cheme <emericchevalier.pro@gmail.com>
This commit is contained in:
committed by
GitHub
parent
9383f7a01a
commit
f7fccb3122
@@ -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();
|
||||
@@ -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;
|
||||
|
||||
@@ -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(())
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user