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.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)
node/cli/src/service.rsdiffbeforeafterboth--- 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<Box<Delay>>,
+ interval: Interval,
}
impl AutosealInterval {
- pub fn new(duration: Duration) -> Result<Self, String> {
- 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<Option<Self::Item>> {
- 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<Runtime, RuntimeApi, ExecutorDispatch>(
config: Configuration,
- autoseal_interval: AutosealInterval,
+ autoseal_interval: Duration,
) -> sc_service::error::Result<TaskManager>
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<Item = EngineCommand<Hash>> + Send + Sync + Unpin,
> = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {