diff --git a/Cargo.lock b/Cargo.lock index 1480550..07d7d89 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7157,6 +7157,7 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-consensus-aura", + "sp-consensus-babe", "sp-core", "sp-genesis-builder", "sp-inherents", diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index c9701c5..c682b6e 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -1,5 +1,5 @@ use cumulus_primitives_core::ParaId; -use parachain_template_runtime::{AccountId, AuraId, Signature, EXISTENTIAL_DEPOSIT}; +use parachain_template_runtime::{AccountId, AuraId, BabeId, Signature, EXISTENTIAL_DEPOSIT}; use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; use sc_service::ChainType; use serde::{Deserialize, Serialize}; @@ -41,8 +41,8 @@ type AccountPublic = ::Signer; /// Generate collator keys from seed. /// /// This function's return type must always match the session keys of the chain in tuple format. -pub fn get_collator_keys_from_seed(seed: &str) -> AuraId { - get_from_seed::(seed) +pub fn get_collator_keys_from_seed(seed: &str) -> ::Public { + get_from_seed::(seed) } /// Helper function to generate an account ID from seed @@ -56,8 +56,11 @@ where /// Generate the session keys from individual elements. /// /// The input must be a tuple of individual keys (a single arg for now since we have just one key). -pub fn template_session_keys(keys: AuraId) -> parachain_template_runtime::SessionKeys { - parachain_template_runtime::SessionKeys { aura: keys } +pub fn template_session_keys( + aura: AuraId, + babe: BabeId, +) -> parachain_template_runtime::SessionKeys { + parachain_template_runtime::SessionKeys { aura, babe } } pub fn development_config() -> ChainSpec { @@ -84,11 +87,13 @@ pub fn development_config() -> ChainSpec { vec![ ( get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), + get_collator_keys_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), ), ( get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed("Bob"), + get_collator_keys_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), ), ], vec![ @@ -136,11 +141,13 @@ pub fn local_testnet_config() -> ChainSpec { vec![ ( get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), + get_collator_keys_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), ), ( get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed("Bob"), + get_collator_keys_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), ), ], vec![ @@ -166,7 +173,7 @@ pub fn local_testnet_config() -> ChainSpec { } fn testnet_genesis( - invulnerables: Vec<(AccountId, AuraId)>, + invulnerables: Vec<(AccountId, AuraId, BabeId)>, endowed_accounts: Vec, root: AccountId, id: ParaId, @@ -179,17 +186,17 @@ fn testnet_genesis( "parachainId": id, }, "collatorSelection": { - "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), + "invulnerables": invulnerables.iter().cloned().map(|(acc, _collator_aura, _collator_babe)| acc).collect::>(), "candidacyBond": EXISTENTIAL_DEPOSIT * 16, }, "session": { "keys": invulnerables .into_iter() - .map(|(acc, aura)| { + .map(|x| { ( - acc.clone(), // account id - acc, // validator id - template_session_keys(aura), // session keys + x.0.clone(), // account id + x.0.clone(), // validator id + template_session_keys(x.1.clone(), x.2.clone()), // session keys ) }) .collect::>(), diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 32a912d..f969de0 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -44,6 +44,7 @@ pallet-transaction-payment-rpc-runtime-api = { workspace = true } sp-api = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } +sp-consensus-babe = { workspace = true } sp-core = { workspace = true } sp-genesis-builder = { workspace = true } sp-inherents = { workspace = true } @@ -118,6 +119,7 @@ std = [ "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", + "sp-consensus-babe/std", "sp-core/std", "sp-genesis-builder/std", "sp-inherents/std", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 096d118..b6f9dc5 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -49,6 +49,7 @@ use frame_system::{ use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; +pub use sp_consensus_babe::AuthorityId as BabeId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; use xcm_config::{RelayLocation, XcmOriginToTransactDispatchOrigin}; @@ -178,6 +179,7 @@ pub mod opaque { impl_opaque_keys! { pub struct SessionKeys { pub aura: Aura, + pub babe: Babe, } } @@ -635,6 +637,38 @@ impl_runtime_apis! { } } + impl sp_consensus_babe::BabeApi for Runtime { + fn configuration() -> sp_consensus_babe::BabeConfiguration { + unimplemented!(); + } + + fn current_epoch_start() -> sp_consensus_babe::Slot { + Babe::current_epoch_start() + } + + fn current_epoch() -> sp_consensus_babe::Epoch { + Babe::current_epoch() + } + + fn next_epoch() -> sp_consensus_babe::Epoch { + Babe::next_epoch() + } + + fn generate_key_ownership_proof( + _slot: sp_consensus_babe::Slot, + authority_id: sp_consensus_babe::AuthorityId, + ) -> Option { + unimplemented!(); + } + + fn submit_report_equivocation_unsigned_extrinsic( + equivocation_proof: sp_consensus_babe::EquivocationProof<::Header>, + key_owner_proof: sp_consensus_babe::OpaqueKeyOwnershipProof, + ) -> Option<()> { + None + } + } + impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { VERSION