difftreelog
Use tokio instead of future-timer
in: master
3 files changed
node/cli/Cargo.tomldiffbeforeafterboth294294295[dependencies]295[dependencies]296futures = '0.3.17'296futures = '0.3.17'297futures-timer = '3.0.2'298log = '0.4.14'297log = '0.4.14'299flexi_logger = "0.15.7"298flexi_logger = "0.15.7"300parking_lot = '0.11.2'299parking_lot = '0.11.2'301clap = "3.1.2"300clap = "3.1.2"302jsonrpc-core = '18.0.0'301jsonrpc-core = '18.0.0'303jsonrpc-pubsub = "18.0.0"302jsonrpc-pubsub = "18.0.0"303tokio = { version = "1.17.0", features = ["time"] }304304305fc-rpc-core = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }305fc-rpc-core = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }306fc-consensus = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }306fc-consensus = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }node/cli/src/command.rsdiffbeforeafterboth35use crate::{35use crate::{36 chain_spec::{self, RuntimeId, RuntimeIdentification, ServiceId, ServiceIdentification},36 chain_spec::{self, RuntimeId, RuntimeIdentification, ServiceId, ServiceIdentification},37 cli::{Cli, RelayChainCli, Subcommand},37 cli::{Cli, RelayChainCli, Subcommand},38 service::{new_partial, start_node, start_dev_node, AutosealInterval},38 service::{new_partial, start_node, start_dev_node},39};39};404041#[cfg(feature = "unique-runtime")]41#[cfg(feature = "unique-runtime")]406 info!("Running Dev service");406 info!("Running Dev service");407407408 let autoseal_interval =408 let autoseal_interval = Duration::from_millis(cli.idle_autoseal_interval);409 AutosealInterval::new(Duration::from_millis(cli.idle_autoseal_interval))?;410409411 return start_node_using_chain_runtime! {410 return start_node_using_chain_runtime! {412 start_dev_node(config, autoseal_interval).map_err(Into::into)411 start_dev_node(config, autoseal_interval).map_err(Into::into)node/cli/src/service.rsdiffbeforeafterboth23use std::time::Duration;23use std::time::Duration;24use std::pin::Pin;24use std::pin::Pin;25use fc_rpc_core::types::FeeHistoryCache;25use fc_rpc_core::types::FeeHistoryCache;26use futures::Future;27use futures::{26use futures::{28 Stream, StreamExt,27 Stream, StreamExt,29 stream::select,28 stream::select,30 task::{Context, Poll},29 task::{Context, Poll},31};30};32use futures_timer::Delay;31use tokio::time::Interval;333234use unique_rpc::overrides_handle;33use unique_rpc::overrides_handle;3534119}118}120119121pub struct AutosealInterval {120pub struct AutosealInterval {122 duration: Duration,121 interval: Interval,123 delay_handle: Pin<Box<Delay>>,124}122}125123126impl AutosealInterval {124impl AutosealInterval {127 pub fn new(duration: Duration) -> Result<Self, String> {125 pub fn new(config: &Configuration, interval: Duration) -> Self {128 if duration.is_zero() {126 let _tokio_runtime = config.tokio_handle.enter();129 return Err("Invalid autoseal interval: 0 seconds".into());130 }131132 Ok(Self {133 duration,134 delay_handle: Box::pin(Delay::new(duration)),127 let interval = tokio::time::interval(interval);135 })128129 Self { interval }136 }130 }137}131}138132139impl Stream for AutosealInterval {133impl Stream for AutosealInterval {140 type Item = ();134 type Item = tokio::time::Instant;141135142 fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {136 fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {143 match self.delay_handle.as_mut().poll(cx) {137 self.interval.poll_tick(cx).map(Some)144 Poll::Ready(_) => {145 let duration = self.duration;146 self.delay_handle.reset(duration);147148 Poll::Ready(Some(()))149 }150 Poll::Pending => Poll::Pending,151 }152 }138 }153}139}154140753/// the parachain inherent739/// the parachain inherent754pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(740pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(755 config: Configuration,741 config: Configuration,756 autoseal_interval: AutosealInterval,742 autoseal_interval: Duration,757) -> sc_service::error::Result<TaskManager>743) -> sc_service::error::Result<TaskManager>758where744where759 Runtime: RuntimeInstance + Send + Sync + 'static,745 Runtime: RuntimeInstance + Send + Sync + 'static,855 }),841 }),856 );842 );857843858 let autoseal_interval = Box::pin(autoseal_interval);844 let autoseal_interval = Box::pin(AutosealInterval::new(&config, autoseal_interval));859 let idle_commands_stream: Box<845 let idle_commands_stream: Box<860 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,846 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,861 > = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {847 > = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {