mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 13:57:58 +00:00
Switch node template to use AuRa (#3790)
* Stuck on service * Make service compile * Remove Grandpa dependency * Update node-template/runtime/Cargo.toml Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fix build * Update crypto import * Update node-template/src/service.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/src/service.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/src/service.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/src/service.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/runtime/src/lib.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Fix macro dependency * Trying to add grandpa back * Update node-template/src/chain_spec.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/src/chain_spec.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/src/chain_spec.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/src/service.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/src/service.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Unused import * Use grandpa block import
This commit is contained in:
committed by
André Silva
parent
bf1786b628
commit
c1a24fb537
@@ -16,13 +16,13 @@ use sr_primitives::{
|
||||
};
|
||||
use sr_primitives::traits::{NumberFor, BlakeTwo256, Block as BlockT, StaticLookup, Verify, ConvertInto};
|
||||
use sr_primitives::weights::Weight;
|
||||
use babe::{AuthorityId as BabeId};
|
||||
use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
|
||||
use grandpa::fg_primitives;
|
||||
use client::{
|
||||
block_builder::api::{CheckInherentsResult, InherentData, self as block_builder_api},
|
||||
runtime_api as client_api, impl_runtime_apis
|
||||
};
|
||||
use aura_primitives::sr25519::AuthorityId as AuraId;
|
||||
use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
|
||||
use grandpa::fg_primitives;
|
||||
use version::RuntimeVersion;
|
||||
#[cfg(feature = "std")]
|
||||
use version::NativeVersion;
|
||||
@@ -80,14 +80,12 @@ pub mod opaque {
|
||||
/// Opaque block identifier type.
|
||||
pub type BlockId = generic::BlockId<Block>;
|
||||
|
||||
pub type SessionHandlers = (Grandpa, Babe);
|
||||
|
||||
impl_opaque_keys! {
|
||||
pub struct SessionKeys {
|
||||
#[id(key_types::AURA)]
|
||||
pub aura: AuraId,
|
||||
#[id(key_types::GRANDPA)]
|
||||
pub grandpa: GrandpaId,
|
||||
#[id(key_types::BABE)]
|
||||
pub babe: BabeId,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,20 +100,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
|
||||
/// Constants for Babe.
|
||||
|
||||
/// Since BABE is probabilistic this is the average expected block time that
|
||||
/// we are targetting. Blocks will be produced at a minimum duration defined
|
||||
/// by `SLOT_DURATION`, but some slots will not be allocated to any
|
||||
/// authority and hence no block will be produced. We expect to have this
|
||||
/// block time on average following the defined slot duration and the value
|
||||
/// of `c` configured for BABE (where `1 - c` represents the probability of
|
||||
/// a slot being empty).
|
||||
/// This value is only used indirectly to define the unit constants below
|
||||
/// that are expressed in blocks. The rest of the code should use
|
||||
/// `SLOT_DURATION` instead (like the timestamp module for calculating the
|
||||
/// minimum period).
|
||||
/// <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results>
|
||||
pub const MILLISECS_PER_BLOCK: u64 = 6000;
|
||||
|
||||
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
|
||||
@@ -180,15 +164,8 @@ impl system::Trait for Runtime {
|
||||
type Version = Version;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const EpochDuration: u64 = EPOCH_DURATION_IN_BLOCKS as u64;
|
||||
pub const ExpectedBlockTime: u64 = MILLISECS_PER_BLOCK;
|
||||
}
|
||||
|
||||
impl babe::Trait for Runtime {
|
||||
type EpochDuration = EpochDuration;
|
||||
type ExpectedBlockTime = ExpectedBlockTime;
|
||||
type EpochChangeTrigger = babe::SameAuthoritiesForever;
|
||||
impl aura::Trait for Runtime {
|
||||
type AuthorityId = AuraId;
|
||||
}
|
||||
|
||||
impl grandpa::Trait for Runtime {
|
||||
@@ -214,7 +191,7 @@ parameter_types! {
|
||||
impl timestamp::Trait for Runtime {
|
||||
/// A timestamp: milliseconds since the unix epoch.
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = Babe;
|
||||
type OnTimestampSet = Aura;
|
||||
type MinimumPeriod = MinimumPeriod;
|
||||
}
|
||||
|
||||
@@ -272,7 +249,7 @@ construct_runtime!(
|
||||
{
|
||||
System: system::{Module, Call, Storage, Config, Event},
|
||||
Timestamp: timestamp::{Module, Call, Storage, Inherent},
|
||||
Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
|
||||
Aura: aura::{Module, Config<T>, Inherent(Timestamp)},
|
||||
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
|
||||
Indices: indices::{default, Config<T>},
|
||||
Balances: balances::{default, Error},
|
||||
@@ -365,27 +342,13 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl fg_primitives::GrandpaApi<Block> for Runtime {
|
||||
fn grandpa_authorities() -> Vec<(GrandpaId, GrandpaWeight)> {
|
||||
Grandpa::grandpa_authorities()
|
||||
impl aura_primitives::AuraApi<Block, AuraId> for Runtime {
|
||||
fn slot_duration() -> u64 {
|
||||
Aura::slot_duration()
|
||||
}
|
||||
}
|
||||
|
||||
impl babe_primitives::BabeApi<Block> for Runtime {
|
||||
fn configuration() -> babe_primitives::BabeConfiguration {
|
||||
// The choice of `c` parameter (where `1 - c` represents the
|
||||
// probability of a slot being empty), is done in accordance to the
|
||||
// slot duration and expected target block time, for safely
|
||||
// resisting network delays of maximum two seconds.
|
||||
// <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results>
|
||||
babe_primitives::BabeConfiguration {
|
||||
slot_duration: Babe::slot_duration(),
|
||||
epoch_length: EpochDuration::get(),
|
||||
c: PRIMARY_PROBABILITY,
|
||||
genesis_authorities: Babe::authorities(),
|
||||
randomness: Babe::randomness(),
|
||||
secondary_slots: true,
|
||||
}
|
||||
|
||||
fn authorities() -> Vec<AuraId> {
|
||||
Aura::authorities()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,4 +358,10 @@ impl_runtime_apis! {
|
||||
opaque::SessionKeys::generate(seed)
|
||||
}
|
||||
}
|
||||
|
||||
impl fg_primitives::GrandpaApi<Block> for Runtime {
|
||||
fn grandpa_authorities() -> Vec<(GrandpaId, GrandpaWeight)> {
|
||||
Grandpa::grandpa_authorities()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user