mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 17:31:03 +00:00
Use BABE to author blocks on Rialto (previously: Aura) (#1050)
* use BABE to author blocks on Rialto (previously: Aura) * removed extra script * use bp_rialto::Moment * fix tests * Babe should control session end * test * Revert "test" This reverts commit 4bbbd76b1fe0aa65002fcfa600cfdc6d15c899e2. * clippy * fix test * Revert "Revert "test"" This reverts commit e9220184d4a14ef4f5a792b239e835528d3baa31. * Revert "Revert "Revert "test""" This reverts commit 9f56a5528945f1d8f82c6346826be68207bf9c75.
This commit is contained in:
committed by
Bastian Köcher
parent
e18844d1f4
commit
08fd53adef
@@ -45,7 +45,6 @@ use codec::Decode;
|
||||
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
|
||||
use pallet_transaction_payment::{FeeDetails, Multiplier, RuntimeDispatchInfo};
|
||||
use sp_api::impl_runtime_apis;
|
||||
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
||||
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
|
||||
use sp_runtime::traits::{Block as BlockT, IdentityLookup, NumberFor, OpaqueKeys};
|
||||
use sp_runtime::{
|
||||
@@ -127,7 +126,7 @@ pub mod opaque {
|
||||
|
||||
impl_opaque_keys! {
|
||||
pub struct SessionKeys {
|
||||
pub aura: Aura,
|
||||
pub babe: Babe,
|
||||
pub grandpa: Grandpa,
|
||||
}
|
||||
}
|
||||
@@ -214,8 +213,34 @@ impl frame_system::Config for Runtime {
|
||||
|
||||
impl pallet_randomness_collective_flip::Config for Runtime {}
|
||||
|
||||
impl pallet_aura::Config for Runtime {
|
||||
type AuthorityId = AuraId;
|
||||
/// The BABE epoch configuration at genesis.
|
||||
pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration =
|
||||
sp_consensus_babe::BabeEpochConfiguration {
|
||||
c: bp_rialto::time_units::PRIMARY_PROBABILITY,
|
||||
allowed_slots: sp_consensus_babe::AllowedSlots::PrimaryAndSecondaryVRFSlots,
|
||||
};
|
||||
|
||||
parameter_types! {
|
||||
pub const EpochDuration: u64 = bp_rialto::time_units::EPOCH_DURATION_IN_SLOTS as u64;
|
||||
pub const ExpectedBlockTime: bp_rialto::Moment = bp_rialto::time_units::MILLISECS_PER_BLOCK;
|
||||
}
|
||||
|
||||
impl pallet_babe::Config for Runtime {
|
||||
type EpochDuration = EpochDuration;
|
||||
type ExpectedBlockTime = ExpectedBlockTime;
|
||||
|
||||
// session module is the trigger
|
||||
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
|
||||
|
||||
// equivocation related configuration - we don't expect any equivocations in our testnets
|
||||
type KeyOwnerProofSystem = ();
|
||||
type KeyOwnerProof =
|
||||
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, pallet_babe::AuthorityId)>>::Proof;
|
||||
type KeyOwnerIdentification =
|
||||
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, pallet_babe::AuthorityId)>>::IdentificationTuple;
|
||||
type HandleEquivocation = ();
|
||||
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
type RialtoPoA = pallet_bridge_eth_poa::Instance1;
|
||||
@@ -347,8 +372,8 @@ parameter_types! {
|
||||
|
||||
impl pallet_timestamp::Config for Runtime {
|
||||
/// A timestamp: milliseconds since the unix epoch.
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = Aura;
|
||||
type Moment = bp_rialto::Moment;
|
||||
type OnTimestampSet = Babe;
|
||||
type MinimumPeriod = MinimumPeriod;
|
||||
// TODO: update me (https://github.com/paritytech/parity-bridges-common/issues/78)
|
||||
type WeightInfo = ();
|
||||
@@ -404,17 +429,12 @@ impl pallet_sudo::Config for Runtime {
|
||||
type Call = Call;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const Period: BlockNumber = bp_rialto::SESSION_LENGTH;
|
||||
pub const Offset: BlockNumber = 0;
|
||||
}
|
||||
|
||||
impl pallet_session::Config for Runtime {
|
||||
type Event = Event;
|
||||
type ValidatorId = <Self as frame_system::Config>::AccountId;
|
||||
type ValidatorIdOf = ();
|
||||
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
|
||||
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
|
||||
type ShouldEndSession = Babe;
|
||||
type NextSessionRotation = Babe;
|
||||
type SessionManager = pallet_shift_session_manager::Pallet<Runtime>;
|
||||
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
|
||||
type Keys = SessionKeys;
|
||||
@@ -513,23 +533,32 @@ construct_runtime!(
|
||||
NodeBlock = opaque::Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>},
|
||||
|
||||
// Must be before session.
|
||||
Babe: pallet_babe::{Pallet, Call, Storage, Config, ValidateUnsigned},
|
||||
|
||||
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
|
||||
|
||||
// Consensus support.
|
||||
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
|
||||
Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event},
|
||||
ShiftSessionManager: pallet_shift_session_manager::{Pallet},
|
||||
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage},
|
||||
|
||||
// Eth-PoA chains bridge modules.
|
||||
BridgeRialtoPoa: pallet_bridge_eth_poa::<Instance1>::{Pallet, Call, Config, Storage, ValidateUnsigned},
|
||||
BridgeKovan: pallet_bridge_eth_poa::<Instance2>::{Pallet, Call, Config, Storage, ValidateUnsigned},
|
||||
BridgeRialtoCurrencyExchange: pallet_bridge_currency_exchange::<Instance1>::{Pallet, Call},
|
||||
BridgeKovanCurrencyExchange: pallet_bridge_currency_exchange::<Instance2>::{Pallet, Call},
|
||||
|
||||
// Millau bridge modules.
|
||||
BridgeMillauGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage},
|
||||
BridgeDispatch: pallet_bridge_dispatch::{Pallet, Event<T>},
|
||||
BridgeMillauMessages: pallet_bridge_messages::{Pallet, Call, Storage, Event<T>},
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage},
|
||||
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
|
||||
Aura: pallet_aura::{Pallet, Config<T>},
|
||||
Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
|
||||
Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>},
|
||||
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
|
||||
ShiftSessionManager: pallet_shift_session_manager::{Pallet},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -690,13 +719,52 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
|
||||
fn slot_duration() -> sp_consensus_aura::SlotDuration {
|
||||
sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
|
||||
impl sp_consensus_babe::BabeApi<Block> for Runtime {
|
||||
fn configuration() -> sp_consensus_babe::BabeGenesisConfiguration {
|
||||
// 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>
|
||||
sp_consensus_babe::BabeGenesisConfiguration {
|
||||
slot_duration: Babe::slot_duration(),
|
||||
epoch_length: EpochDuration::get(),
|
||||
c: BABE_GENESIS_EPOCH_CONFIG.c,
|
||||
genesis_authorities: Babe::authorities(),
|
||||
randomness: Babe::randomness(),
|
||||
allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots,
|
||||
}
|
||||
}
|
||||
|
||||
fn authorities() -> Vec<AuraId> {
|
||||
Aura::authorities()
|
||||
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<sp_consensus_babe::OpaqueKeyOwnershipProof> {
|
||||
None
|
||||
}
|
||||
|
||||
fn submit_report_equivocation_unsigned_extrinsic(
|
||||
equivocation_proof: sp_consensus_babe::EquivocationProof<<Block as BlockT>::Header>,
|
||||
key_owner_proof: sp_consensus_babe::OpaqueKeyOwnershipProof,
|
||||
) -> Option<()> {
|
||||
let key_owner_proof = key_owner_proof.decode()?;
|
||||
|
||||
Babe::submit_unsigned_equivocation_report(
|
||||
equivocation_proof,
|
||||
key_owner_proof,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user