From 1ce1209cf6571935815da66e59bf3b026bd28d83 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Thu, 31 Mar 2022 14:03:48 +0000 Subject: [PATCH] Use tokio instead of future-timer --- --- a/node/cli/Cargo.toml +++ b/node/cli/Cargo.toml @@ -294,13 +294,13 @@ [dependencies] futures = '0.3.17' -futures-timer = '3.0.2' log = '0.4.14' flexi_logger = "0.15.7" parking_lot = '0.11.2' clap = "3.1.2" jsonrpc-core = '18.0.0' jsonrpc-pubsub = "18.0.0" +tokio = { version = "1.17.0", features = ["time"] } fc-rpc-core = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" } fc-consensus = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" } --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -35,7 +35,7 @@ use crate::{ chain_spec::{self, RuntimeId, RuntimeIdentification, ServiceId, ServiceIdentification}, cli::{Cli, RelayChainCli, Subcommand}, - service::{new_partial, start_node, start_dev_node, AutosealInterval}, + service::{new_partial, start_node, start_dev_node}, }; #[cfg(feature = "unique-runtime")] @@ -405,8 +405,7 @@ if is_dev_service { info!("Running Dev service"); - let autoseal_interval = - AutosealInterval::new(Duration::from_millis(cli.idle_autoseal_interval))?; + let autoseal_interval = Duration::from_millis(cli.idle_autoseal_interval); return start_node_using_chain_runtime! { start_dev_node(config, autoseal_interval).map_err(Into::into) --- a/node/cli/src/service.rs +++ b/node/cli/src/service.rs @@ -23,13 +23,12 @@ use std::time::Duration; use std::pin::Pin; use fc_rpc_core::types::FeeHistoryCache; -use futures::Future; use futures::{ Stream, StreamExt, stream::select, task::{Context, Poll}, }; -use futures_timer::Delay; +use tokio::time::Interval; use unique_rpc::overrides_handle; @@ -119,36 +118,23 @@ } pub struct AutosealInterval { - duration: Duration, - delay_handle: Pin>, + interval: Interval, } impl AutosealInterval { - pub fn new(duration: Duration) -> Result { - if duration.is_zero() { - return Err("Invalid autoseal interval: 0 seconds".into()); - } + pub fn new(config: &Configuration, interval: Duration) -> Self { + let _tokio_runtime = config.tokio_handle.enter(); + let interval = tokio::time::interval(interval); - Ok(Self { - duration, - delay_handle: Box::pin(Delay::new(duration)), - }) + Self { interval } } } impl Stream for AutosealInterval { - type Item = (); + type Item = tokio::time::Instant; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - match self.delay_handle.as_mut().poll(cx) { - Poll::Ready(_) => { - let duration = self.duration; - self.delay_handle.reset(duration); - - Poll::Ready(Some(())) - } - Poll::Pending => Poll::Pending, - } + self.interval.poll_tick(cx).map(Some) } } @@ -753,7 +739,7 @@ /// the parachain inherent pub fn start_dev_node( config: Configuration, - autoseal_interval: AutosealInterval, + autoseal_interval: Duration, ) -> sc_service::error::Result where Runtime: RuntimeInstance + Send + Sync + 'static, @@ -855,7 +841,7 @@ }), ); - let autoseal_interval = Box::pin(autoseal_interval); + let autoseal_interval = Box::pin(AutosealInterval::new(&config, autoseal_interval)); let idle_commands_stream: Box< dyn Stream> + Send + Sync + Unpin, > = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock { -- gitstuff