mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 03:31:10 +00:00
Update the service to std futures (#4447)
* Switch service to futures03 * Fix tests * Fix service test and cli * Re-add Executor trait to SpawnTaskHandle * Fix node-service * Update babe * Fix browser node * Update aura * Revert back to tokio-executor to fix runtime panic * Add todo item * Fix service tests again * Timeout test futures * Fix tests * nits * Fix service test * Remove zstd patch * Re-add futures01 to aura and babe tests as a dev-dep * Change failing test to tee * Fix node * Upgrade tokio * fix society * Start switching grandpa to stable futures * Revert "Start switching grandpa to stable futures" This reverts commit 9c1976346237637effc07c13f7d0403daf5e71cf. * Fix utils * Revert substrate service test * Revert gitlab Co-authored-by: thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
@@ -27,12 +27,10 @@ use sc_client_api::{
|
||||
use sc_client::Client;
|
||||
use sc_chain_spec::{RuntimeGenesis, Extension};
|
||||
use sp_consensus::import_queue::ImportQueue;
|
||||
use futures::{prelude::*, sync::mpsc};
|
||||
use futures03::{
|
||||
compat::Compat,
|
||||
FutureExt as _, TryFutureExt as _,
|
||||
StreamExt as _, TryStreamExt as _,
|
||||
future::{select, Either}
|
||||
use futures::{
|
||||
Future, FutureExt, StreamExt,
|
||||
channel::mpsc,
|
||||
future::{select, ready}
|
||||
};
|
||||
use sc_keystore::{Store as Keystore};
|
||||
use log::{info, warn, error};
|
||||
@@ -47,7 +45,7 @@ use sp_api::ProvideRuntimeApi;
|
||||
use sc_executor::{NativeExecutor, NativeExecutionDispatch};
|
||||
use std::{
|
||||
io::{Read, Write, Seek},
|
||||
marker::PhantomData, sync::Arc, time::SystemTime
|
||||
marker::PhantomData, sync::Arc, time::SystemTime, pin::Pin
|
||||
};
|
||||
use sysinfo::{get_current_pid, ProcessExt, System, SystemExt};
|
||||
use sc_telemetry::{telemetry, SUBSTRATE_INFO};
|
||||
@@ -682,7 +680,7 @@ pub trait ServiceBuilderCommand {
|
||||
self,
|
||||
input: impl Read + Seek + Send + 'static,
|
||||
force: bool,
|
||||
) -> Box<dyn Future<Item = (), Error = Error> + Send>;
|
||||
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>;
|
||||
|
||||
/// Performs the blocks export.
|
||||
fn export_blocks(
|
||||
@@ -691,7 +689,7 @@ pub trait ServiceBuilderCommand {
|
||||
from: NumberFor<Self::Block>,
|
||||
to: Option<NumberFor<Self::Block>>,
|
||||
json: bool
|
||||
) -> Box<dyn Future<Item = (), Error = Error>>;
|
||||
) -> Pin<Box<dyn Future<Output = Result<(), Error>>>>;
|
||||
|
||||
/// Performs a revert of `blocks` blocks.
|
||||
fn revert_chain(
|
||||
@@ -703,7 +701,7 @@ pub trait ServiceBuilderCommand {
|
||||
fn check_block(
|
||||
self,
|
||||
block: BlockId<Self::Block>
|
||||
) -> Box<dyn Future<Item = (), Error = Error> + Send>;
|
||||
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>;
|
||||
}
|
||||
|
||||
impl<TBl, TRtApi, TCfg, TGen, TCSExt, TBackend, TExec, TSc, TImpQu, TNetP, TExPool, TRpc>
|
||||
@@ -795,7 +793,7 @@ ServiceBuilder<
|
||||
|
||||
// List of asynchronous tasks to spawn. We collect them, then spawn them all at once.
|
||||
let (to_spawn_tx, to_spawn_rx) =
|
||||
mpsc::unbounded::<Box<dyn Future<Item = (), Error = ()> + Send>>();
|
||||
mpsc::unbounded::<Pin<Box<dyn Future<Output = ()> + Send>>>();
|
||||
|
||||
// A side-channel for essential tasks to communicate shutdown.
|
||||
let (essential_failed_tx, essential_failed_rx) = mpsc::unbounded();
|
||||
@@ -879,7 +877,6 @@ ServiceBuilder<
|
||||
let is_validator = config.roles.is_authority();
|
||||
|
||||
let events = client.import_notification_stream()
|
||||
.map(|v| Ok::<_, ()>(v)).compat()
|
||||
.for_each(move |notification| {
|
||||
let txpool = txpool.upgrade();
|
||||
|
||||
@@ -887,8 +884,8 @@ ServiceBuilder<
|
||||
let future = txpool.maintain(
|
||||
&BlockId::hash(notification.hash),
|
||||
¬ification.retracted,
|
||||
).map(|_| Ok(())).compat();
|
||||
let _ = to_spawn_tx_.unbounded_send(Box::new(future));
|
||||
);
|
||||
let _ = to_spawn_tx_.unbounded_send(Box::pin(future));
|
||||
}
|
||||
|
||||
let offchain = offchain.as_ref().and_then(|o| o.upgrade());
|
||||
@@ -897,15 +894,13 @@ ServiceBuilder<
|
||||
¬ification.header,
|
||||
network_state_info.clone(),
|
||||
is_validator
|
||||
).map(|()| Ok(()));
|
||||
let _ = to_spawn_tx_.unbounded_send(Box::new(Compat::new(future)));
|
||||
);
|
||||
let _ = to_spawn_tx_.unbounded_send(Box::pin(future));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.select(exit.clone().map(Ok).compat())
|
||||
.then(|_| Ok(()));
|
||||
let _ = to_spawn_tx.unbounded_send(Box::new(events));
|
||||
ready(())
|
||||
});
|
||||
let _ = to_spawn_tx.unbounded_send(Box::pin(select(events, exit.clone()).map(drop)));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -913,7 +908,6 @@ ServiceBuilder<
|
||||
let network = Arc::downgrade(&network);
|
||||
let transaction_pool_ = transaction_pool.clone();
|
||||
let events = transaction_pool.import_notification_stream()
|
||||
.map(|v| Ok::<_, ()>(v)).compat()
|
||||
.for_each(move |_| {
|
||||
if let Some(network) = network.upgrade() {
|
||||
network.trigger_repropagate();
|
||||
@@ -923,12 +917,10 @@ ServiceBuilder<
|
||||
"ready" => status.ready,
|
||||
"future" => status.future
|
||||
);
|
||||
Ok(())
|
||||
})
|
||||
.select(exit.clone().map(Ok).compat())
|
||||
.then(|_| Ok(()));
|
||||
ready(())
|
||||
});
|
||||
|
||||
let _ = to_spawn_tx.unbounded_send(Box::new(events));
|
||||
let _ = to_spawn_tx.unbounded_send(Box::pin(select(events, exit.clone()).map(drop)));
|
||||
}
|
||||
|
||||
// Periodically notify the telemetry.
|
||||
@@ -990,9 +982,9 @@ ServiceBuilder<
|
||||
"disk_write_per_sec" => info.usage.as_ref().map(|usage| usage.io.bytes_written).unwrap_or(0),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}).select(exit.clone().map(Ok).compat()).then(|_| Ok(()));
|
||||
let _ = to_spawn_tx.unbounded_send(Box::new(tel_task));
|
||||
ready(())
|
||||
});
|
||||
let _ = to_spawn_tx.unbounded_send(Box::pin(select(tel_task, exit.clone()).map(drop)));
|
||||
|
||||
// Periodically send the network state to the telemetry.
|
||||
let (netstat_tx, netstat_rx) = mpsc::unbounded::<(NetworkStatus<_>, NetworkState)>();
|
||||
@@ -1003,12 +995,12 @@ ServiceBuilder<
|
||||
"system.network_state";
|
||||
"state" => network_state,
|
||||
);
|
||||
Ok(())
|
||||
}).select(exit.clone().map(Ok).compat()).then(|_| Ok(()));
|
||||
let _ = to_spawn_tx.unbounded_send(Box::new(tel_task_2));
|
||||
ready(())
|
||||
});
|
||||
let _ = to_spawn_tx.unbounded_send(Box::pin(select(tel_task_2, exit.clone()).map(drop)));
|
||||
|
||||
// RPC
|
||||
let (system_rpc_tx, system_rpc_rx) = futures03::channel::mpsc::unbounded();
|
||||
let (system_rpc_tx, system_rpc_rx) = mpsc::unbounded();
|
||||
let gen_handler = || {
|
||||
use sc_rpc::{chain, state, author, system};
|
||||
|
||||
@@ -1068,17 +1060,14 @@ ServiceBuilder<
|
||||
let rpc = start_rpc_servers(&config, gen_handler)?;
|
||||
|
||||
|
||||
let _ = to_spawn_tx.unbounded_send(Box::new(build_network_future(
|
||||
let _ = to_spawn_tx.unbounded_send(Box::pin(select(build_network_future(
|
||||
config.roles,
|
||||
network_mut,
|
||||
client.clone(),
|
||||
network_status_sinks.clone(),
|
||||
system_rpc_rx,
|
||||
has_bootnodes,
|
||||
)
|
||||
.map_err(|_| ())
|
||||
.select(exit.clone().map(Ok).compat())
|
||||
.then(|_| Ok(()))));
|
||||
), exit.clone()).map(drop)));
|
||||
|
||||
let telemetry_connection_sinks: Arc<Mutex<Vec<mpsc::UnboundedSender<()>>>> = Default::default();
|
||||
|
||||
@@ -1099,8 +1088,6 @@ ServiceBuilder<
|
||||
.map(|dur| dur.as_millis())
|
||||
.unwrap_or(0);
|
||||
let future = telemetry.clone()
|
||||
.map(|ev| Ok::<_, ()>(ev))
|
||||
.compat()
|
||||
.for_each(move |event| {
|
||||
// Safe-guard in case we add more events in the future.
|
||||
let sc_telemetry::TelemetryEvent::Connected = event;
|
||||
@@ -1119,11 +1106,11 @@ ServiceBuilder<
|
||||
telemetry_connection_sinks_.lock().retain(|sink| {
|
||||
sink.unbounded_send(()).is_ok()
|
||||
});
|
||||
Ok(())
|
||||
ready(())
|
||||
});
|
||||
let _ = to_spawn_tx.unbounded_send(Box::new(future
|
||||
.select(exit.clone().map(Ok).compat())
|
||||
.then(|_| Ok(()))));
|
||||
let _ = to_spawn_tx.unbounded_send(Box::pin(select(
|
||||
future, exit.clone()
|
||||
).map(drop)));
|
||||
telemetry
|
||||
});
|
||||
|
||||
@@ -1132,13 +1119,10 @@ ServiceBuilder<
|
||||
let future = select(
|
||||
grafana_data_source::run_server(port).boxed(),
|
||||
exit.clone()
|
||||
).map(|either| match either {
|
||||
Either::Left((result, _)) => result.map_err(|_| ()),
|
||||
Either::Right(_) => Ok(())
|
||||
}).compat();
|
||||
).map(drop);
|
||||
|
||||
let _ = to_spawn_tx.unbounded_send(Box::new(future));
|
||||
}
|
||||
let _ = to_spawn_tx.unbounded_send(Box::pin(future));
|
||||
}
|
||||
|
||||
// Instrumentation
|
||||
if let Some(tracing_targets) = config.tracing_targets.as_ref() {
|
||||
|
||||
Reference in New Issue
Block a user