Skip to content

Commit 6105325

Browse files
committed
use babe
1 parent 84aa542 commit 6105325

File tree

6 files changed

+171
-60
lines changed

6 files changed

+171
-60
lines changed

Cargo.lock

Lines changed: 83 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ git = 'https://github.com/paritytech/substrate.git'
5050
tag = 'v2.0.0-rc3'
5151
version = '0.8.0-rc3'
5252

53-
[dependencies.sc-consensus-aura]
53+
[dependencies.sc-consensus-babe]
5454
git = 'https://github.com/paritytech/substrate.git'
5555
tag = 'v2.0.0-rc3'
5656
version = '0.8.0-rc3'
@@ -85,7 +85,7 @@ git = 'https://github.com/paritytech/substrate.git'
8585
tag = 'v2.0.0-rc3'
8686
version = '0.8.0-rc3'
8787

88-
[dependencies.sp-consensus-aura]
88+
[dependencies.sp-consensus-babe]
8989
git = 'https://github.com/paritytech/substrate.git'
9090
tag = 'v2.0.0-rc3'
9191
version = '0.8.0-rc3'

node/src/chain_spec.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use sp_core::{Pair, Public, sr25519};
22
use node_template_runtime::{
3-
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig,
3+
AccountId, BabeConfig, BalancesConfig, GenesisConfig, GrandpaConfig,
44
SudoConfig, SystemConfig, WASM_BINARY, Signature
55
};
6-
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
6+
use sp_consensus_babe::{AuthorityId as BabeId};
77
use sp_finality_grandpa::AuthorityId as GrandpaId;
88
use sp_runtime::traits::{Verify, IdentifyAccount};
99
use sc_service::ChainType;
@@ -30,10 +30,12 @@ pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId where
3030
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
3131
}
3232

33-
/// Helper function to generate an authority key for Aura
34-
pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
33+
/// Helper function to generate an authority key for Babe
34+
pub fn authority_keys_from_seed(s: &str) -> (AccountId, AccountId, BabeId, GrandpaId) {
3535
(
36-
get_from_seed::<AuraId>(s),
36+
get_account_id_from_seed::<sr25519::Public>(&format!("{}//stash", s)),
37+
get_account_id_from_seed::<sr25519::Public>(s),
38+
get_from_seed::<BabeId>(s),
3739
get_from_seed::<GrandpaId>(s),
3840
)
3941
}
@@ -99,7 +101,7 @@ pub fn local_testnet_config() -> ChainSpec {
99101
)
100102
}
101103

102-
fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,
104+
fn testnet_genesis(initial_authorities: Vec<(AccountId, AccountId, BabeId, GrandpaId)>,
103105
root_key: AccountId,
104106
endowed_accounts: Vec<AccountId>,
105107
_enable_println: bool) -> GenesisConfig {
@@ -111,11 +113,11 @@ fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,
111113
balances: Some(BalancesConfig {
112114
balances: endowed_accounts.iter().cloned().map(|k|(k, 1 << 60)).collect(),
113115
}),
114-
aura: Some(AuraConfig {
115-
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
116+
babe: Some(BabeConfig {
117+
authorities: initial_authorities.iter().map(|x| (x.2.clone(), 1)).collect(),
116118
}),
117119
grandpa: Some(GrandpaConfig {
118-
authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),
120+
authorities: initial_authorities.iter().map(|x| (x.3.clone(), 1)).collect(),
119121
}),
120122
sudo: Some(SudoConfig {
121123
key: root_key,

node/src/service.rs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use sc_service::{error::{Error as ServiceError}, AbstractService, Configuration,
99
use sp_inherents::InherentDataProviders;
1010
use sc_executor::native_executor_instance;
1111
pub use sc_executor::NativeExecutor;
12-
use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair};
1312
use sc_finality_grandpa::{
1413
FinalityProofProvider as GrandpaFinalityProofProvider, StorageAndProofProvider, SharedVoterState,
1514
};
@@ -28,7 +27,6 @@ native_executor_instance!(
2827
macro_rules! new_full_start {
2928
($config:expr) => {{
3029
use std::sync::Arc;
31-
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
3230

3331
let mut import_setup = None;
3432
let inherent_data_providers = sp_inherents::InherentDataProviders::new();
@@ -68,22 +66,25 @@ macro_rules! new_full_start {
6866
select_chain,
6967
)?;
7068

71-
let aura_block_import = sc_consensus_aura::AuraBlockImport::<_, _, _, AuraPair>::new(
72-
grandpa_block_import.clone(), client.clone(),
73-
);
69+
let (block_import, babe_link) = sc_consensus_babe::block_import(
70+
sc_consensus_babe::Config::get_or_compute(&*client)?,
71+
grandpa_block_import.clone(),
72+
client.clone(),
73+
)?;
7474

75-
let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _>(
76-
sc_consensus_aura::slot_duration(&*client)?,
77-
aura_block_import,
78-
Some(Box::new(grandpa_block_import.clone())),
75+
let justification_import = grandpa_block_import.clone();
76+
let import_queue = sc_consensus_babe::import_queue(
77+
babe_link.clone(),
78+
block_import.clone(),
79+
Some(Box::new(justification_import)),
7980
None,
8081
client,
8182
inherent_data_providers.clone(),
8283
spawn_task_handle,
8384
registry,
8485
)?;
8586

86-
import_setup = Some((grandpa_block_import, grandpa_link));
87+
import_setup = Some((block_import, grandpa_link, babe_link));
8788

8889
Ok(import_queue)
8990
})?;
@@ -101,7 +102,7 @@ pub fn new_full(config: Configuration) -> Result<impl AbstractService, ServiceEr
101102

102103
let (builder, mut import_setup, inherent_data_providers) = new_full_start!(config);
103104

104-
let (block_import, grandpa_link) =
105+
let (block_import, grandpa_link, babe_link) =
105106
import_setup.take()
106107
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");
107108

@@ -127,22 +128,23 @@ pub fn new_full(config: Configuration) -> Result<impl AbstractService, ServiceEr
127128
let can_author_with =
128129
sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone());
129130

130-
let aura = sc_consensus_aura::start_aura::<_, _, _, _, _, AuraPair, _, _, _>(
131-
sc_consensus_aura::slot_duration(&*client)?,
131+
let babe_config = sc_consensus_babe::BabeParams {
132+
keystore: service.keystore(),
132133
client,
133134
select_chain,
135+
env: proposer,
134136
block_import,
135-
proposer,
136-
service.network(),
137-
inherent_data_providers.clone(),
137+
sync_oracle: service.network(),
138+
inherent_data_providers: inherent_data_providers.clone(),
138139
force_authoring,
139-
service.keystore(),
140+
babe_link,
140141
can_author_with,
141-
)?;
142+
};
142143

143-
// the AURA authoring task is considered essential, i.e. if it
144+
let babe = sc_consensus_babe::start_babe(babe_config)?;
145+
// the BABE authoring task is considered infallible, i.e. if it
144146
// fails we take down the service with it.
145-
service.spawn_essential_task("aura", aura);
147+
service.spawn_essential_task("babe-proposer", babe);
146148
}
147149

148150
// if the node isn't actively participating in consensus then it doesn't
@@ -246,12 +248,18 @@ pub fn new_light(config: Configuration) -> Result<impl AbstractService, ServiceE
246248
let finality_proof_request_builder =
247249
finality_proof_import.create_finality_proof_request_builder();
248250

249-
let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _>(
250-
sc_consensus_aura::slot_duration(&*client)?,
251+
let (babe_block_import, babe_link) = sc_consensus_babe::block_import(
252+
sc_consensus_babe::Config::get_or_compute(&*client)?,
251253
grandpa_block_import,
254+
client.clone(),
255+
)?;
256+
257+
let import_queue = sc_consensus_babe::import_queue(
258+
babe_link,
259+
babe_block_import,
252260
None,
253261
Some(Box::new(finality_proof_import)),
254-
client,
262+
client.clone(),
255263
inherent_data_providers.clone(),
256264
spawn_task_handle,
257265
prometheus_registry,

0 commit comments

Comments
 (0)