Remove client.backend (#2960)

* generalize tree_root to remove client.backend dependency

* replace client.backend.blockchain.header with client.header

* move used_state_cache_size into client info

* Create intermediate Setup State. Fixes #1134

* remove client.backend from finality proof

* update node-template

* move memory backend into test helper mode

* move test helper into client

* starting the big refactor, remove unused functions

* apply_finality

* apply_finality

* replacing more .backend from environment with client directly

* remove .backend from grandpa by using traits

* remove .backend from babe

* remove .backend from tests where it is not needed

* remove .backend from tests

* fixing tests

* fixing tests

* fixing more tests

* fixing tests

* fix all forks test

* fix style

* fixing unnecessary allocation

* remove old test.

* fix service docs

* apply suggestion

* minor clean ups

* turns out the test-helper features actually is being used!

* fixing line length.

* fix line length

* minor cleaning

* Apply suggestions from code review

thanks, @Basti

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* address grumbles

* simplify finalize block on client

* move block back into inner function

* Apply suggestions from code review

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* use as.ref instead of match

* Update core/client/src/backend.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>
This commit is contained in:
Benjamin Kampmann
2019-08-30 02:20:26 +02:00
committed by GitHub
parent 26202c66f7
commit 0cae7217d8
30 changed files with 626 additions and 571 deletions
+17 -36
View File
@@ -66,7 +66,7 @@ pub use futures::future::Executor;
const DEFAULT_PROTOCOL_ID: &str = "sup";
/// Substrate service.
pub struct NewService<TCfg, TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> {
pub struct NewService<TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> {
client: Arc<TCl>,
select_chain: Option<TSc>,
network: Arc<TNet>,
@@ -91,8 +91,6 @@ pub struct NewService<TCfg, TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> {
/// If spawning a background task is not possible, we instead push the task into this `Vec`.
/// The elements must then be polled manually.
to_poll: Vec<Box<dyn Future<Item = (), Error = ()> + Send>>,
/// Configuration of this Service
config: TCfg,
rpc_handlers: rpc_servers::RpcHandler<rpc::Metadata>,
_rpc: Box<dyn std::any::Any + Send + Sync>,
_telemetry: Option<tel::Telemetry>,
@@ -148,6 +146,7 @@ macro_rules! new_impl {
let (
client,
on_demand,
backend,
keystore,
select_chain,
import_queue,
@@ -156,7 +155,7 @@ macro_rules! new_impl {
network_protocol,
transaction_pool,
rpc_extensions
) = $build_components(&mut $config)?;
) = $build_components(&$config)?;
let import_queue = Box::new(import_queue);
let chain_info = client.info().chain;
@@ -206,8 +205,7 @@ macro_rules! new_impl {
let network = network_mut.service().clone();
let network_status_sinks = Arc::new(Mutex::new(Vec::new()));
#[allow(deprecated)]
let offchain_storage = client.backend().offchain_storage();
let offchain_storage = backend.offchain_storage();
let offchain_workers = match ($config.offchain_worker, offchain_storage) {
(true, Some(db)) => {
Some(Arc::new(offchain::OffchainWorkers::new(client.clone(), db)))
@@ -301,9 +299,7 @@ macro_rules! new_impl {
let bandwidth_download = net_status.average_download_per_sec;
let bandwidth_upload = net_status.average_upload_per_sec;
#[allow(deprecated)]
let backend = (*client_).backend();
let used_state_cache_size = match backend.used_state_cache_size(){
let used_state_cache_size = match info.used_state_cache_size {
Some(size) => size,
None => 0,
};
@@ -426,7 +422,6 @@ macro_rules! new_impl {
to_spawn_tx,
to_spawn_rx,
to_poll: Vec::new(),
$config,
rpc_handlers,
_rpc: rpc,
_telemetry: telemetry,
@@ -451,8 +446,6 @@ pub trait AbstractService: 'static + Future<Item = (), Error = Error> +
type CallExecutor: 'static + client::CallExecutor<Self::Block, Blake2Hasher> + Send + Sync + Clone;
/// API that the runtime provides.
type RuntimeApi: Send + Sync;
/// Configuration struct of the service.
type Config;
/// Chain selection algorithm.
type SelectChain: consensus_common::SelectChain<Self::Block>;
/// API of the transaction pool.
@@ -463,12 +456,6 @@ pub trait AbstractService: 'static + Future<Item = (), Error = Error> +
/// Get event stream for telemetry connection established events.
fn telemetry_on_connect_stream(&self) -> mpsc::UnboundedReceiver<()>;
/// Returns the configuration passed on construction.
fn config(&self) -> &Self::Config;
/// Returns the configuration passed on construction.
fn config_mut(&mut self) -> &mut Self::Config;
/// return a shared instance of Telemetry (if enabled)
fn telemetry(&self) -> Option<tel::Telemetry>;
@@ -516,10 +503,10 @@ pub trait AbstractService: 'static + Future<Item = (), Error = Error> +
fn on_exit(&self) -> ::exit_future::Exit;
}
impl<TCfg, TBl, TBackend, TExec, TRtApi, TSc, TNetSpec, TExPoolApi, TOc> AbstractService for
NewService<TCfg, TBl, Client<TBackend, TExec, TBl, TRtApi>, TSc, NetworkStatus<TBl>,
impl<TBl, TBackend, TExec, TRtApi, TSc, TNetSpec, TExPoolApi, TOc> AbstractService for
NewService<TBl, Client<TBackend, TExec, TBl, TRtApi>, TSc, NetworkStatus<TBl>,
NetworkService<TBl, TNetSpec, H256>, TransactionPool<TExPoolApi>, TOc>
where TCfg: 'static + Send,
where
TBl: BlockT<Hash = H256>,
TBackend: 'static + client::backend::Backend<TBl, Blake2Hasher>,
TExec: 'static + client::CallExecutor<TBl, Blake2Hasher> + Send + Sync + Clone,
@@ -533,19 +520,10 @@ where TCfg: 'static + Send,
type Backend = TBackend;
type CallExecutor = TExec;
type RuntimeApi = TRtApi;
type Config = TCfg;
type SelectChain = TSc;
type TransactionPoolApi = TExPoolApi;
type NetworkSpecialization = TNetSpec;
fn config(&self) -> &Self::Config {
&self.config
}
fn config_mut(&mut self) -> &mut Self::Config {
&mut self.config
}
fn telemetry_on_connect_stream(&self) -> mpsc::UnboundedReceiver<()> {
let (sink, stream) = mpsc::unbounded();
self._telemetry_on_connect_sinks.lock().push(sink);
@@ -611,8 +589,9 @@ where TCfg: 'static + Send,
}
}
impl<TCfg, TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> Future for
NewService<TCfg, TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> {
impl<TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> Future for
NewService<TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc>
{
type Item = ();
type Error = Error;
@@ -643,8 +622,9 @@ NewService<TCfg, TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> {
}
}
impl<TCfg, TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> Executor<Box<dyn Future<Item = (), Error = ()> + Send>> for
NewService<TCfg, TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> {
impl<TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> Executor<Box<dyn Future<Item = (), Error = ()> + Send>> for
NewService<TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc>
{
fn execute(
&self,
future: Box<dyn Future<Item = (), Error = ()> + Send>
@@ -787,8 +767,9 @@ pub struct NetworkStatus<B: BlockT> {
pub average_upload_per_sec: u64,
}
impl<TCfg, TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> Drop for
NewService<TCfg, TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> {
impl<TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> Drop for
NewService<TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc>
{
fn drop(&mut self) {
debug!(target: "service", "Substrate service shutdown");
if let Some(signal) = self.signal.take() {