git.delta.rocks / unique-network / refs/commits / 1ce1209cf657

difftreelog

Use tokio instead of future-timer

Daniel Shiposha2022-03-31parent: #2d2fd30.patch.diff
in: master

3 files changed

modifiednode/cli/Cargo.tomldiffbeforeafterboth
--- 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" }
modifiednode/cli/src/command.rsdiffbeforeafterboth
--- 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)
modifiednode/cli/src/service.rsdiffbeforeafterboth
23use 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;
3332
34use unique_rpc::overrides_handle;33use unique_rpc::overrides_handle;
3534
119}118}
120119
121pub struct AutosealInterval {120pub struct AutosealInterval {
122 duration: Duration,121 interval: Interval,
123 delay_handle: Pin<Box<Delay>>,
124}122}
125123
126impl 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 }
131
132 Ok(Self {
133 duration,
134 delay_handle: Box::pin(Delay::new(duration)),127 let interval = tokio::time::interval(interval);
135 })128
129 Self { interval }
136 }130 }
137}131}
138132
139impl Stream for AutosealInterval {133impl Stream for AutosealInterval {
140 type Item = ();134 type Item = tokio::time::Instant;
141135
142 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);
147
148 Poll::Ready(Some(()))
149 }
150 Poll::Pending => Poll::Pending,
151 }
152 }138 }
153}139}
154140
753/// the parachain inherent739/// the parachain inherent
754pub 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>
758where744where
759 Runtime: RuntimeInstance + Send + Sync + 'static,745 Runtime: RuntimeInstance + Send + Sync + 'static,
855 }),841 }),
856 );842 );
857843
858 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 {