mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Implements FindAuthor<u32> for srml-aura (#3426)
* Implements `FindAuthor<u32>` for `srml-aura` * Update lib.rs * Build
This commit is contained in:
@@ -61,7 +61,7 @@ pub mod ed25519 {
|
||||
pub const AURA_ENGINE_ID: ConsensusEngineId = [b'a', b'u', b'r', b'a'];
|
||||
|
||||
/// The index of an authority.
|
||||
pub type AuthorityIndex = u64;
|
||||
pub type AuthorityIndex = u32;
|
||||
|
||||
/// An consensus log item for Aura.
|
||||
#[derive(Decode, Encode)]
|
||||
|
||||
@@ -48,8 +48,11 @@
|
||||
pub use timestamp;
|
||||
|
||||
use rstd::{result, prelude::*};
|
||||
use codec::Encode;
|
||||
use srml_support::{decl_storage, decl_module, Parameter, storage::StorageValue, traits::Get};
|
||||
use codec::{Encode, Decode};
|
||||
use srml_support::{
|
||||
decl_storage, decl_module, Parameter, storage::StorageValue, traits::{Get, FindAuthor},
|
||||
ConsensusEngineId,
|
||||
};
|
||||
use app_crypto::AppPublic;
|
||||
use sr_primitives::{
|
||||
traits::{SaturatedConversion, Saturating, Zero, Member, IsMember}, generic::DigestItem,
|
||||
@@ -60,9 +63,7 @@ use timestamp::TimestampInherentData;
|
||||
use inherents::{RuntimeString, InherentIdentifier, InherentData, ProvideInherent, MakeFatalError};
|
||||
#[cfg(feature = "std")]
|
||||
use inherents::{InherentDataProviders, ProvideInherentData};
|
||||
use substrate_consensus_aura_primitives::{AURA_ENGINE_ID, ConsensusLog};
|
||||
#[cfg(feature = "std")]
|
||||
use codec::Decode;
|
||||
use substrate_consensus_aura_primitives::{AURA_ENGINE_ID, ConsensusLog, AuthorityIndex};
|
||||
|
||||
mod mock;
|
||||
mod tests;
|
||||
@@ -215,13 +216,30 @@ impl<T: Trait> session::OneSessionHandler<T::AccountId> for Module<T> {
|
||||
fn on_disabled(i: usize) {
|
||||
let log: DigestItem<T::Hash> = DigestItem::Consensus(
|
||||
AURA_ENGINE_ID,
|
||||
ConsensusLog::<T::AuthorityId>::OnDisabled(i as u64).encode(),
|
||||
ConsensusLog::<T::AuthorityId>::OnDisabled(i as AuthorityIndex).encode(),
|
||||
);
|
||||
|
||||
<system::Module<T>>::deposit_log(log.into());
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> FindAuthor<u32> for Module<T> {
|
||||
fn find_author<'a, I>(digests: I) -> Option<u32> where
|
||||
I: 'a + IntoIterator<Item=(ConsensusEngineId, &'a [u8])>
|
||||
{
|
||||
for (id, mut data) in digests.into_iter() {
|
||||
if id == AURA_ENGINE_ID {
|
||||
if let Ok(slot_num) = u64::decode(&mut data) {
|
||||
let author_index = slot_num % Self::authorities().len() as u64;
|
||||
return Some(author_index as u32)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> IsMember<T::AuthorityId> for Module<T> {
|
||||
fn is_member(authority_id: &T::AuthorityId) -> bool {
|
||||
Self::authorities()
|
||||
|
||||
Reference in New Issue
Block a user