Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit a467bb2

Browse files
andresilvagavofyork
andcommitted
service: don't use the grandpa observer (#494)
* service: don't use the grandpa observer * service: remove unnecessary boxing * service: fix indentation * service: remove unnecessary on_exit tasks spawned with `spawn_task`/`spawn_essential_task` are already guarded by `on_exit`. * Update service/src/lib.rs Co-Authored-By: Gavin Wood <[email protected]>
1 parent 1f576dd commit a467bb2

File tree

1 file changed

+45
-48
lines changed

1 file changed

+45
-48
lines changed

service/src/lib.rs

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use polkadot_runtime::GenesisConfig;
2727
use polkadot_network::{gossip::{self as network_gossip, Known}, validation::ValidationNetwork};
2828
use service::{error::{Error as ServiceError}, Configuration, ServiceBuilder};
2929
use transaction_pool::txpool::{Pool as TransactionPool};
30-
use babe::{import_queue, start_babe};
3130
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
3231
use inherents::InherentDataProviders;
3332
use log::info;
@@ -98,20 +97,20 @@ macro_rules! new_full_start {
9897
let justification_import = grandpa_block_import.clone();
9998

10099
let (block_import, babe_link) = babe::block_import(
101-
babe::Config::get_or_compute(&*client)?,
102-
grandpa_block_import,
103-
client.clone(),
104-
client.clone(),
100+
babe::Config::get_or_compute(&*client)?,
101+
grandpa_block_import,
102+
client.clone(),
103+
client.clone(),
105104
)?;
106105

107106
let import_queue = babe::import_queue(
108-
babe_link.clone(),
109-
block_import.clone(),
110-
Some(Box::new(justification_import)),
111-
None,
112-
client.clone(),
113-
client,
114-
inherent_data_providers.clone(),
107+
babe_link.clone(),
108+
block_import.clone(),
109+
Some(Box::new(justification_import)),
110+
None,
111+
client.clone(),
112+
client,
113+
inherent_data_providers.clone(),
115114
)?;
116115

117116
import_setup = Some((block_import, grandpa_link, babe_link));
@@ -258,49 +257,48 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
258257
babe_link,
259258
};
260259

261-
let babe = start_babe(babe_config)?;
262-
let select = babe.select(service.on_exit()).then(|_| Ok(()));
263-
service.spawn_essential_task(Box::new(select));
260+
let babe = babe::start_babe(babe_config)?;
261+
service.spawn_essential_task(babe);
264262
}
265263

264+
let keystore = if is_authority {
265+
Some(service.keystore())
266+
} else {
267+
None
268+
};
269+
266270
let config = grandpa::Config {
267271
// FIXME substrate#1578 make this available through chainspec
268272
gossip_duration: Duration::from_millis(333),
269273
justification_period: 512,
270274
name: Some(name),
271-
keystore: Some(service.keystore()),
275+
keystore,
272276
};
273277

274-
match (is_authority, disable_grandpa) {
275-
(false, false) => {
276-
// start the lightweight GRANDPA observer
277-
service.spawn_task(Box::new(grandpa::run_grandpa_observer(
278-
config,
279-
link_half,
280-
service.network(),
281-
service.on_exit(),
282-
)?));
283-
},
284-
(true, false) => {
285-
// start the full GRANDPA voter
286-
let grandpa_config = grandpa::GrandpaParams {
287-
config: config,
288-
link: link_half,
289-
network: service.network(),
290-
inherent_data_providers: inherent_data_providers.clone(),
291-
on_exit: service.on_exit(),
292-
telemetry_on_connect: Some(service.telemetry_on_connect_stream()),
293-
voting_rule: grandpa::VotingRulesBuilder::default().build(),
294-
};
295-
service.spawn_essential_task(Box::new(grandpa::run_grandpa_voter(grandpa_config)?));
296-
},
297-
(_, true) => {
298-
grandpa::setup_disabled_grandpa(
299-
service.client(),
300-
&inherent_data_providers,
301-
service.network(),
302-
)?;
303-
},
278+
let enable_grandpa = !disable_grandpa;
279+
if enable_grandpa {
280+
// start the full GRANDPA voter
281+
// NOTE: unlike in polkadot/master we are currently running the full
282+
// GRANDPA voter protocol for all full nodes (regardless of whether
283+
// they're validators or not). at this point the full voter should
284+
// provide better guarantees of block and vote data availability than
285+
// the observer.
286+
let grandpa_config = grandpa::GrandpaParams {
287+
config: config,
288+
link: link_half,
289+
network: service.network(),
290+
inherent_data_providers: inherent_data_providers.clone(),
291+
on_exit: service.on_exit(),
292+
telemetry_on_connect: Some(service.telemetry_on_connect_stream()),
293+
voting_rule: grandpa::VotingRulesBuilder::default().build(),
294+
};
295+
service.spawn_essential_task(grandpa::run_grandpa_voter(grandpa_config)?);
296+
} else {
297+
grandpa::setup_disabled_grandpa(
298+
service.client(),
299+
&inherent_data_providers,
300+
service.network(),
301+
)?;
304302
}
305303

306304
Ok(service)
@@ -336,7 +334,6 @@ pub fn new_light(config: Configuration<CustomConfiguration, GenesisConfig>)
336334
let finality_proof_request_builder =
337335
finality_proof_import.create_finality_proof_request_builder();
338336

339-
340337
let (babe_block_import, babe_link) = babe::block_import(
341338
babe::Config::get_or_compute(&*client)?,
342339
grandpa_block_import,
@@ -345,7 +342,7 @@ pub fn new_light(config: Configuration<CustomConfiguration, GenesisConfig>)
345342
)?;
346343

347344
// FIXME: pruning task isn't started since light client doesn't do `AuthoritySetup`.
348-
let import_queue = import_queue(
345+
let import_queue = babe::import_queue(
349346
babe_link,
350347
babe_block_import,
351348
None,

0 commit comments

Comments
 (0)