@@ -5,7 +5,10 @@ use std::time::Duration;
5
5
use sc_client_api:: ExecutorProvider ;
6
6
use sc_consensus:: LongestChain ;
7
7
use node_template_runtime:: { self , opaque:: Block , RuntimeApi } ;
8
- use sc_service:: { error:: { Error as ServiceError } , AbstractService , Configuration , ServiceBuilder } ;
8
+ use sc_service:: {
9
+ error:: { Error as ServiceError } , Configuration , ServiceBuilder , ServiceComponents ,
10
+ TaskManager ,
11
+ } ;
9
12
use sp_inherents:: InherentDataProviders ;
10
13
use sc_executor:: native_executor_instance;
11
14
pub use sc_executor:: NativeExecutor ;
@@ -93,7 +96,7 @@ macro_rules! new_full_start {
93
96
}
94
97
95
98
/// Builds a new service for a full client.
96
- pub fn new_full ( config : Configuration ) -> Result < impl AbstractService , ServiceError > {
99
+ pub fn new_full ( config : Configuration ) -> Result < TaskManager , ServiceError > {
97
100
let role = config. role . clone ( ) ;
98
101
let force_authoring = config. force_authoring ;
99
102
let name = config. network . node_name . clone ( ) ;
@@ -105,7 +108,10 @@ pub fn new_full(config: Configuration) -> Result<impl AbstractService, ServiceEr
105
108
import_setup. take ( )
106
109
. expect ( "Link Half and Block Import are present for Full Services or setup failed before. qed" ) ;
107
110
108
- let service = builder
111
+ let ServiceComponents {
112
+ client, transaction_pool, task_manager, keystore, network, select_chain,
113
+ prometheus_registry, telemetry_on_connect_sinks, ..
114
+ } = builder
109
115
. with_finality_proof_provider ( |client, backend| {
110
116
// GenesisAuthoritySetProvider is implemented for StorageAndProofProvider
111
117
let provider = client as Arc < dyn StorageAndProofProvider < _ , _ > > ;
@@ -115,40 +121,39 @@ pub fn new_full(config: Configuration) -> Result<impl AbstractService, ServiceEr
115
121
116
122
if role. is_authority ( ) {
117
123
let proposer = sc_basic_authorship:: ProposerFactory :: new (
118
- service . client ( ) ,
119
- service . transaction_pool ( ) ,
120
- service . prometheus_registry ( ) . as_ref ( ) ,
124
+ client. clone ( ) ,
125
+ transaction_pool,
126
+ prometheus_registry. as_ref ( ) ,
121
127
) ;
122
128
123
- let client = service. client ( ) ;
124
- let select_chain = service. select_chain ( )
129
+ let select_chain = select_chain
125
130
. ok_or ( ServiceError :: SelectChainRequired ) ?;
126
131
127
132
let can_author_with =
128
133
sp_consensus:: CanAuthorWithNativeVersion :: new ( client. executor ( ) . clone ( ) ) ;
129
134
130
135
let aura = sc_consensus_aura:: start_aura :: < _ , _ , _ , _ , _ , AuraPair , _ , _ , _ > (
131
136
sc_consensus_aura:: slot_duration ( & * client) ?,
132
- client,
137
+ client. clone ( ) ,
133
138
select_chain,
134
139
block_import,
135
140
proposer,
136
- service . network ( ) ,
141
+ network. clone ( ) ,
137
142
inherent_data_providers. clone ( ) ,
138
143
force_authoring,
139
- service . keystore ( ) ,
144
+ keystore. clone ( ) ,
140
145
can_author_with,
141
146
) ?;
142
147
143
148
// the AURA authoring task is considered essential, i.e. if it
144
149
// fails we take down the service with it.
145
- service . spawn_essential_task_handle ( ) . spawn_blocking ( "aura" , aura) ;
150
+ task_manager . spawn_essential_handle ( ) . spawn_blocking ( "aura" , aura) ;
146
151
}
147
152
148
153
// if the node isn't actively participating in consensus then it doesn't
149
154
// need a keystore, regardless of which protocol we use below.
150
155
let keystore = if role. is_authority ( ) {
151
- Some ( service . keystore ( ) as sp_core:: traits:: BareCryptoStorePtr )
156
+ Some ( keystore. clone ( ) as sp_core:: traits:: BareCryptoStorePtr )
152
157
} else {
153
158
None
154
159
} ;
@@ -174,33 +179,33 @@ pub fn new_full(config: Configuration) -> Result<impl AbstractService, ServiceEr
174
179
let grandpa_config = sc_finality_grandpa:: GrandpaParams {
175
180
config : grandpa_config,
176
181
link : grandpa_link,
177
- network : service . network ( ) ,
182
+ network : network. clone ( ) ,
178
183
inherent_data_providers : inherent_data_providers. clone ( ) ,
179
- telemetry_on_connect : Some ( service . telemetry_on_connect_stream ( ) ) ,
184
+ telemetry_on_connect : Some ( telemetry_on_connect_sinks . on_connect_stream ( ) ) ,
180
185
voting_rule : sc_finality_grandpa:: VotingRulesBuilder :: default ( ) . build ( ) ,
181
- prometheus_registry : service . prometheus_registry ( ) ,
186
+ prometheus_registry : prometheus_registry. clone ( ) ,
182
187
shared_voter_state : SharedVoterState :: empty ( ) ,
183
188
} ;
184
189
185
190
// the GRANDPA voter task is considered infallible, i.e.
186
191
// if it fails we take down the service with it.
187
- service . spawn_essential_task_handle ( ) . spawn_blocking (
192
+ task_manager . spawn_essential_handle ( ) . spawn_blocking (
188
193
"grandpa-voter" ,
189
194
sc_finality_grandpa:: run_grandpa_voter ( grandpa_config) ?
190
195
) ;
191
196
} else {
192
197
sc_finality_grandpa:: setup_disabled_grandpa (
193
- service . client ( ) ,
198
+ client,
194
199
& inherent_data_providers,
195
- service . network ( ) ,
200
+ network. clone ( ) ,
196
201
) ?;
197
202
}
198
203
199
- Ok ( service )
204
+ Ok ( task_manager )
200
205
}
201
206
202
207
/// Builds a new service for a light client.
203
- pub fn new_light ( config : Configuration ) -> Result < impl AbstractService , ServiceError > {
208
+ pub fn new_light ( config : Configuration ) -> Result < TaskManager , ServiceError > {
204
209
let inherent_data_providers = InherentDataProviders :: new ( ) ;
205
210
206
211
ServiceBuilder :: new_light :: < Block , RuntimeApi , Executor > ( config) ?
@@ -265,4 +270,5 @@ pub fn new_light(config: Configuration) -> Result<impl AbstractService, ServiceE
265
270
Ok ( Arc :: new( GrandpaFinalityProofProvider :: new( backend, provider) ) as _)
266
271
} ) ?
267
272
. build_light( )
273
+ . map( |ServiceComponents { task_manager, .. } | task_manager)
268
274
}
0 commit comments