mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 07:01:05 +00:00
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:
committed by
GitHub
parent
26202c66f7
commit
0cae7217d8
@@ -57,9 +57,12 @@ use transaction_pool::txpool::{self, ChainApi, Pool as TransactionPool};
|
||||
/// The order in which the `with_*` methods are called doesn't matter, as the correct binding of
|
||||
/// generics is done when you call `build`.
|
||||
///
|
||||
pub struct ServiceBuilder<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc> {
|
||||
pub struct ServiceBuilder<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp,
|
||||
TNetP, TExPool, TRpc, Backend>
|
||||
{
|
||||
config: Configuration<TCfg, TGen>,
|
||||
client: Arc<TCl>,
|
||||
backend: Arc<Backend>,
|
||||
keystore: Arc<RwLock<Keystore>>,
|
||||
fetcher: Option<TFchr>,
|
||||
select_chain: Option<TSc>,
|
||||
@@ -72,7 +75,7 @@ pub struct ServiceBuilder<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFpr
|
||||
marker: PhantomData<(TBl, TRtApi)>,
|
||||
}
|
||||
|
||||
impl<TCfg, TGen> ServiceBuilder<(), (), TCfg, TGen, (), (), (), (), (), (), (), (), ()>
|
||||
impl<TCfg, TGen> ServiceBuilder<(), (), TCfg, TGen, (), (), (), (), (), (), (), (), (), ()>
|
||||
where TGen: Serialize + DeserializeOwned + BuildStorage {
|
||||
/// Start the service builder with a configuration.
|
||||
pub fn new_full<TBl: BlockT<Hash=H256>, TRtApi, TExecDisp: NativeExecutionDispatch>(
|
||||
@@ -95,7 +98,8 @@ where TGen: Serialize + DeserializeOwned + BuildStorage {
|
||||
(),
|
||||
(),
|
||||
(),
|
||||
()
|
||||
(),
|
||||
client_db::Backend<TBl>,
|
||||
>, Error> {
|
||||
let keystore = Keystore::open(config.keystore_path.clone(), config.keystore_password.clone())?;
|
||||
|
||||
@@ -110,17 +114,20 @@ where TGen: Serialize + DeserializeOwned + BuildStorage {
|
||||
|
||||
let executor = NativeExecutor::<TExecDisp>::new(config.default_heap_pages);
|
||||
|
||||
let client = Arc::new(client_db::new_client(
|
||||
let (client, backend) = client_db::new_client(
|
||||
db_settings,
|
||||
executor,
|
||||
&config.chain_spec,
|
||||
config.execution_strategies.clone(),
|
||||
Some(keystore.clone()),
|
||||
)?);
|
||||
)?;
|
||||
|
||||
let client = Arc::new(client);
|
||||
|
||||
Ok(ServiceBuilder {
|
||||
config,
|
||||
client,
|
||||
backend,
|
||||
keystore,
|
||||
fetcher: None,
|
||||
select_chain: None,
|
||||
@@ -177,7 +184,8 @@ where TGen: Serialize + DeserializeOwned + BuildStorage {
|
||||
(),
|
||||
(),
|
||||
(),
|
||||
()
|
||||
(),
|
||||
client::light::backend::Backend<client_db::light::LightStorage<TBl>, network::OnDemand<TBl>, Blake2Hasher>,
|
||||
>, Error> {
|
||||
let keystore = Keystore::open(config.keystore_path.clone(), config.keystore_password.clone())?;
|
||||
|
||||
@@ -196,12 +204,13 @@ where TGen: Serialize + DeserializeOwned + BuildStorage {
|
||||
let light_blockchain = client::light::new_light_blockchain(db_storage);
|
||||
let fetch_checker = Arc::new(client::light::new_fetch_checker(light_blockchain.clone(), executor.clone()));
|
||||
let fetcher = Arc::new(network::OnDemand::new(fetch_checker));
|
||||
let client_backend = client::light::new_light_backend(light_blockchain, fetcher.clone());
|
||||
let client = client::light::new_light(client_backend, fetcher.clone(), &config.chain_spec, executor)?;
|
||||
let backend = client::light::new_light_backend(light_blockchain, fetcher.clone());
|
||||
let client = client::light::new_light(backend.clone(), fetcher.clone(), &config.chain_spec, executor)?;
|
||||
|
||||
Ok(ServiceBuilder {
|
||||
config,
|
||||
client: Arc::new(client),
|
||||
backend,
|
||||
keystore,
|
||||
fetcher: Some(fetcher),
|
||||
select_chain: None,
|
||||
@@ -216,14 +225,19 @@ where TGen: Serialize + DeserializeOwned + BuildStorage {
|
||||
}
|
||||
}
|
||||
|
||||
impl<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc>
|
||||
ServiceBuilder<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc> {
|
||||
impl<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc, Backend>
|
||||
ServiceBuilder<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc, Backend> {
|
||||
|
||||
/// Returns a reference to the client that was stored in this builder.
|
||||
pub fn client(&self) -> &Arc<TCl> {
|
||||
&self.client
|
||||
}
|
||||
|
||||
/// Returns a reference to the backend that was used in this builder.
|
||||
pub fn backend(&self) -> &Arc<Backend> {
|
||||
&self.backend
|
||||
}
|
||||
|
||||
/// Returns a reference to the select-chain that was stored in this builder.
|
||||
pub fn select_chain(&self) -> Option<&TSc> {
|
||||
self.select_chain.as_ref()
|
||||
@@ -231,15 +245,16 @@ impl<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPo
|
||||
|
||||
/// Defines which head-of-chain strategy to use.
|
||||
pub fn with_opt_select_chain<USc>(
|
||||
mut self,
|
||||
select_chain_builder: impl FnOnce(&mut Configuration<TCfg, TGen>, Arc<TCl>) -> Result<Option<USc>, Error>
|
||||
self,
|
||||
select_chain_builder: impl FnOnce(&Configuration<TCfg, TGen>, &Arc<Backend>) -> Result<Option<USc>, Error>
|
||||
) -> Result<ServiceBuilder<TBl, TRtApi, TCfg, TGen, TCl, TFchr, USc, TImpQu, TFprb, TFpp,
|
||||
TNetP, TExPool, TRpc>, Error> {
|
||||
let select_chain = select_chain_builder(&mut self.config, self.client.clone())?;
|
||||
TNetP, TExPool, TRpc, Backend>, Error> {
|
||||
let select_chain = select_chain_builder(&self.config, &self.backend)?;
|
||||
|
||||
Ok(ServiceBuilder {
|
||||
config: self.config,
|
||||
client: self.client,
|
||||
backend: self.backend,
|
||||
keystore: self.keystore,
|
||||
fetcher: self.fetcher,
|
||||
select_chain,
|
||||
@@ -256,22 +271,22 @@ impl<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPo
|
||||
/// Defines which head-of-chain strategy to use.
|
||||
pub fn with_select_chain<USc>(
|
||||
self,
|
||||
builder: impl FnOnce(&mut Configuration<TCfg, TGen>, Arc<TCl>) -> Result<USc, Error>
|
||||
builder: impl FnOnce(&Configuration<TCfg, TGen>, &Arc<Backend>) -> Result<USc, Error>
|
||||
) -> Result<ServiceBuilder<TBl, TRtApi, TCfg, TGen, TCl, TFchr, USc, TImpQu, TFprb, TFpp,
|
||||
TNetP, TExPool, TRpc>, Error> {
|
||||
self.with_opt_select_chain(|cfg, cl| builder(cfg, cl).map(Option::Some))
|
||||
TNetP, TExPool, TRpc, Backend>, Error> {
|
||||
self.with_opt_select_chain(|cfg, b| builder(cfg, b).map(Option::Some))
|
||||
}
|
||||
|
||||
/// Defines which import queue to use.
|
||||
pub fn with_import_queue<UImpQu>(
|
||||
mut self,
|
||||
builder: impl FnOnce(&mut Configuration<TCfg, TGen>, Arc<TCl>, Option<TSc>, Arc<TExPool>)
|
||||
self,
|
||||
builder: impl FnOnce(&Configuration<TCfg, TGen>, Arc<TCl>, Option<TSc>, Arc<TExPool>)
|
||||
-> Result<UImpQu, Error>
|
||||
) -> Result<ServiceBuilder<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, UImpQu, TFprb, TFpp,
|
||||
TNetP, TExPool, TRpc>, Error>
|
||||
TNetP, TExPool, TRpc, Backend>, Error>
|
||||
where TSc: Clone {
|
||||
let import_queue = builder(
|
||||
&mut self.config,
|
||||
&self.config,
|
||||
self.client.clone(),
|
||||
self.select_chain.clone(),
|
||||
self.transaction_pool.clone()
|
||||
@@ -280,6 +295,7 @@ impl<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPo
|
||||
Ok(ServiceBuilder {
|
||||
config: self.config,
|
||||
client: self.client,
|
||||
backend: self.backend,
|
||||
keystore: self.keystore,
|
||||
fetcher: self.fetcher,
|
||||
select_chain: self.select_chain,
|
||||
@@ -298,12 +314,13 @@ impl<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPo
|
||||
self,
|
||||
network_protocol_builder: impl FnOnce(&Configuration<TCfg, TGen>) -> Result<UNetP, Error>
|
||||
) -> Result<ServiceBuilder<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp,
|
||||
UNetP, TExPool, TRpc>, Error> {
|
||||
UNetP, TExPool, TRpc, Backend>, Error> {
|
||||
let network_protocol = network_protocol_builder(&self.config)?;
|
||||
|
||||
Ok(ServiceBuilder {
|
||||
config: self.config,
|
||||
client: self.client,
|
||||
backend: self.backend,
|
||||
keystore: self.keystore,
|
||||
fetcher: self.fetcher,
|
||||
select_chain: self.select_chain,
|
||||
@@ -320,7 +337,7 @@ impl<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPo
|
||||
/// Defines which strategy to use for providing finality proofs.
|
||||
pub fn with_opt_finality_proof_provider(
|
||||
self,
|
||||
builder: impl FnOnce(Arc<TCl>) -> Result<Option<Arc<FinalityProofProvider<TBl>>>, Error>
|
||||
builder: impl FnOnce(Arc<TCl>, Arc<Backend>) -> Result<Option<Arc<dyn FinalityProofProvider<TBl>>>, Error>
|
||||
) -> Result<ServiceBuilder<
|
||||
TBl,
|
||||
TRtApi,
|
||||
@@ -331,16 +348,18 @@ impl<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPo
|
||||
TSc,
|
||||
TImpQu,
|
||||
TFprb,
|
||||
Arc<FinalityProofProvider<TBl>>,
|
||||
Arc<dyn FinalityProofProvider<TBl>>,
|
||||
TNetP,
|
||||
TExPool,
|
||||
TRpc
|
||||
TRpc,
|
||||
Backend,
|
||||
>, Error> {
|
||||
let finality_proof_provider = builder(self.client.clone())?;
|
||||
let finality_proof_provider = builder(self.client.clone(), self.backend.clone())?;
|
||||
|
||||
Ok(ServiceBuilder {
|
||||
config: self.config,
|
||||
client: self.client,
|
||||
backend: self.backend,
|
||||
keystore: self.keystore,
|
||||
fetcher: self.fetcher,
|
||||
select_chain: self.select_chain,
|
||||
@@ -357,7 +376,7 @@ impl<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPo
|
||||
/// Defines which strategy to use for providing finality proofs.
|
||||
pub fn with_finality_proof_provider(
|
||||
self,
|
||||
build: impl FnOnce(Arc<TCl>) -> Result<Arc<FinalityProofProvider<TBl>>, Error>
|
||||
build: impl FnOnce(Arc<TCl>, Arc<Backend>) -> Result<Arc<dyn FinalityProofProvider<TBl>>, Error>
|
||||
) -> Result<ServiceBuilder<
|
||||
TBl,
|
||||
TRtApi,
|
||||
@@ -368,25 +387,27 @@ impl<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPo
|
||||
TSc,
|
||||
TImpQu,
|
||||
TFprb,
|
||||
Arc<FinalityProofProvider<TBl>>,
|
||||
Arc<dyn FinalityProofProvider<TBl>>,
|
||||
TNetP,
|
||||
TExPool,
|
||||
TRpc
|
||||
TRpc,
|
||||
Backend,
|
||||
>, Error> {
|
||||
self.with_opt_finality_proof_provider(|client| build(client).map(Option::Some))
|
||||
self.with_opt_finality_proof_provider(|client, backend| build(client, backend).map(Option::Some))
|
||||
}
|
||||
|
||||
/// Defines which import queue to use.
|
||||
pub fn with_import_queue_and_opt_fprb<UImpQu, UFprb>(
|
||||
mut self,
|
||||
builder: impl FnOnce(&mut Configuration<TCfg, TGen>, Arc<TCl>, Option<TSc>, Arc<TExPool>)
|
||||
self,
|
||||
builder: impl FnOnce(&Configuration<TCfg, TGen>, Arc<TCl>, Arc<Backend>, Option<TSc>, Arc<TExPool>)
|
||||
-> Result<(UImpQu, Option<UFprb>), Error>
|
||||
) -> Result<ServiceBuilder<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, UImpQu, UFprb, TFpp,
|
||||
TNetP, TExPool, TRpc>, Error>
|
||||
TNetP, TExPool, TRpc, Backend>, Error>
|
||||
where TSc: Clone {
|
||||
let (import_queue, fprb) = builder(
|
||||
&mut self.config,
|
||||
&self.config,
|
||||
self.client.clone(),
|
||||
self.backend.clone(),
|
||||
self.select_chain.clone(),
|
||||
self.transaction_pool.clone()
|
||||
)?;
|
||||
@@ -394,6 +415,7 @@ impl<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPo
|
||||
Ok(ServiceBuilder {
|
||||
config: self.config,
|
||||
client: self.client,
|
||||
backend: self.backend,
|
||||
keystore: self.keystore,
|
||||
fetcher: self.fetcher,
|
||||
select_chain: self.select_chain,
|
||||
@@ -410,12 +432,12 @@ impl<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPo
|
||||
/// Defines which import queue to use.
|
||||
pub fn with_import_queue_and_fprb<UImpQu, UFprb>(
|
||||
self,
|
||||
builder: impl FnOnce(&mut Configuration<TCfg, TGen>, Arc<TCl>, Option<TSc>, Arc<TExPool>)
|
||||
builder: impl FnOnce(&Configuration<TCfg, TGen>, Arc<TCl>, Arc<Backend>, Option<TSc>, Arc<TExPool>)
|
||||
-> Result<(UImpQu, UFprb), Error>
|
||||
) -> Result<ServiceBuilder<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, UImpQu, UFprb, TFpp,
|
||||
TNetP, TExPool, TRpc>, Error>
|
||||
TNetP, TExPool, TRpc, Backend>, Error>
|
||||
where TSc: Clone {
|
||||
self.with_import_queue_and_opt_fprb(|cfg, cl, sc, tx| builder(cfg, cl, sc, tx).map(|(q, f)| (q, Some(f))))
|
||||
self.with_import_queue_and_opt_fprb(|cfg, cl, b, sc, tx| builder(cfg, cl, b, sc, tx).map(|(q, f)| (q, Some(f))))
|
||||
}
|
||||
|
||||
/// Defines which transaction pool to use.
|
||||
@@ -423,12 +445,13 @@ impl<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPo
|
||||
self,
|
||||
transaction_pool_builder: impl FnOnce(transaction_pool::txpool::Options, Arc<TCl>) -> Result<UExPool, Error>
|
||||
) -> Result<ServiceBuilder<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp,
|
||||
TNetP, UExPool, TRpc>, Error> {
|
||||
TNetP, UExPool, TRpc, Backend>, Error> {
|
||||
let transaction_pool = transaction_pool_builder(self.config.transaction_pool.clone(), self.client.clone())?;
|
||||
|
||||
Ok(ServiceBuilder {
|
||||
config: self.config,
|
||||
client: self.client,
|
||||
backend: self.backend,
|
||||
keystore: self.keystore,
|
||||
fetcher: self.fetcher,
|
||||
select_chain: self.select_chain,
|
||||
@@ -447,12 +470,13 @@ impl<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPo
|
||||
self,
|
||||
rpc_ext_builder: impl FnOnce(Arc<TCl>, Arc<TExPool>) -> URpc
|
||||
) -> Result<ServiceBuilder<TBl, TRtApi, TCfg, TGen, TCl, TFchr, TSc, TImpQu, TFprb, TFpp,
|
||||
TNetP, TExPool, URpc>, Error> {
|
||||
TNetP, TExPool, URpc, Backend>, Error> {
|
||||
let rpc_extensions = rpc_ext_builder(self.client.clone(), self.transaction_pool.clone());
|
||||
|
||||
Ok(ServiceBuilder {
|
||||
config: self.config,
|
||||
client: self.client,
|
||||
backend: self.backend,
|
||||
keystore: self.keystore,
|
||||
fetcher: self.fetcher,
|
||||
select_chain: self.select_chain,
|
||||
@@ -508,9 +532,9 @@ pub trait ServiceBuilderRevert {
|
||||
) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
impl<TBl, TRtApi, TCfg, TGen, TBackend, TExec, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc>
|
||||
impl<TBl, TRtApi, TCfg, TGen, TBackend, TExec, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc, Backend>
|
||||
ServiceBuilderImport for ServiceBuilder<TBl, TRtApi, TCfg, TGen, Client<TBackend, TExec, TBl, TRtApi>,
|
||||
TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc>
|
||||
TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc, Backend>
|
||||
where
|
||||
TBl: BlockT<Hash = <Blake2Hasher as Hasher>::Out>,
|
||||
TBackend: 'static + client::backend::Backend<TBl, Blake2Hasher> + Send,
|
||||
@@ -532,7 +556,7 @@ where
|
||||
|
||||
impl<TBl, TRtApi, TCfg, TGen, TBackend, TExec, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc>
|
||||
ServiceBuilderExport for ServiceBuilder<TBl, TRtApi, TCfg, TGen, Client<TBackend, TExec, TBl, TRtApi>,
|
||||
TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc>
|
||||
TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc, TBackend>
|
||||
where
|
||||
TBl: BlockT<Hash = <Blake2Hasher as Hasher>::Out>,
|
||||
TBackend: 'static + client::backend::Backend<TBl, Blake2Hasher> + Send,
|
||||
@@ -555,7 +579,7 @@ where
|
||||
|
||||
impl<TBl, TRtApi, TCfg, TGen, TBackend, TExec, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc>
|
||||
ServiceBuilderRevert for ServiceBuilder<TBl, TRtApi, TCfg, TGen, Client<TBackend, TExec, TBl, TRtApi>,
|
||||
TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc>
|
||||
TFchr, TSc, TImpQu, TFprb, TFpp, TNetP, TExPool, TRpc, TBackend>
|
||||
where
|
||||
TBl: BlockT<Hash = <Blake2Hasher as Hasher>::Out>,
|
||||
TBackend: 'static + client::backend::Backend<TBl, Blake2Hasher> + Send,
|
||||
@@ -583,10 +607,11 @@ ServiceBuilder<
|
||||
TSc,
|
||||
TImpQu,
|
||||
BoxFinalityProofRequestBuilder<TBl>,
|
||||
Arc<FinalityProofProvider<TBl>>,
|
||||
Arc<dyn FinalityProofProvider<TBl>>,
|
||||
TNetP,
|
||||
TransactionPool<TExPoolApi>,
|
||||
TRpc
|
||||
TRpc,
|
||||
TBackend
|
||||
> where
|
||||
Client<TBackend, TExec, TBl, TRtApi>: ProvideRuntimeApi,
|
||||
<Client<TBackend, TExec, TBl, TRtApi> as ProvideRuntimeApi>::Api:
|
||||
@@ -608,7 +633,6 @@ ServiceBuilder<
|
||||
{
|
||||
/// Builds the service.
|
||||
pub fn build(self) -> Result<NewService<
|
||||
Configuration<TCfg, TGen>,
|
||||
TBl,
|
||||
Client<TBackend, TExec, TBl, TRtApi>,
|
||||
TSc,
|
||||
@@ -629,6 +653,7 @@ ServiceBuilder<
|
||||
let (
|
||||
client,
|
||||
fetcher,
|
||||
backend,
|
||||
keystore,
|
||||
select_chain,
|
||||
import_queue,
|
||||
@@ -640,6 +665,7 @@ ServiceBuilder<
|
||||
) = (
|
||||
self.client,
|
||||
self.fetcher,
|
||||
self.backend,
|
||||
self.keystore,
|
||||
self.select_chain,
|
||||
self.import_queue,
|
||||
@@ -657,6 +683,7 @@ ServiceBuilder<
|
||||
Ok((
|
||||
client,
|
||||
fetcher,
|
||||
backend,
|
||||
keystore,
|
||||
select_chain,
|
||||
import_queue,
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user