node: use BABE predigest data to find authorship (#3293)

* node: use BABE predigest data to find authorship

* node: bump spec_version

* babe: use u32 for authority index
This commit is contained in:
André Silva
2019-08-02 18:52:36 +01:00
committed by Gavin Wood
parent da8b91ae7b
commit aa86185648
4 changed files with 8 additions and 9 deletions
@@ -53,7 +53,7 @@ pub const VRF_PROOF_LENGTH: usize = 64;
pub const PUBLIC_KEY_LENGTH: usize = 32;
/// The index of an authority.
pub type AuthorityIndex = u64;
pub type AuthorityIndex = u32;
/// A slot number.
pub type SlotNumber = u64;
+3 -3
View File
@@ -321,7 +321,7 @@ impl<Hash, H, B, C, E, I, Error, SO> SlotWorker<B> for BabeWorker<C, E, I, SO> w
let inherent_digest = BabePreDigest {
vrf_proof,
vrf_output: inout.to_output(),
authority_index: authority_index as u64,
authority_index: authority_index as u32,
slot_number,
};
@@ -491,7 +491,7 @@ fn check_header<B: BlockT + Sized, C: AuxStore>(
if slot_number > slot_now {
header.digest_mut().push(seal);
Ok(CheckedHeader::Deferred(header, slot_number))
} else if authority_index > authorities.len() as u64 {
} else if authority_index > authorities.len() as u32 {
Err(babe_err!("Slot author not found"))
} else {
let (pre_hash, author) = (header.hash(), &authorities[authority_index as usize].0);
@@ -1219,7 +1219,7 @@ pub mod test_helpers {
BabePreDigest {
vrf_proof,
vrf_output: inout.to_output(),
authority_index: authority_index as u64,
authority_index: authority_index as u32,
slot_number,
}
})
+1 -2
View File
@@ -180,9 +180,8 @@ parameter_types! {
pub const UncleGenerations: u64 = 0;
}
// TODO: #2986 implement this properly
impl authorship::Trait for Runtime {
type FindAuthor = ();
type FindAuthor = session::FindAccountFromAuthorIndex<Self, Babe>;
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
type EventHandler = Staking;
+3 -3
View File
@@ -202,8 +202,8 @@ impl<T: Trait> RandomnessBeacon for Module<T> {
/// A BABE public key
pub type BabeKey = [u8; PUBLIC_KEY_LENGTH];
impl<T: Trait> FindAuthor<u64> for Module<T> {
fn find_author<'a, I>(digests: I) -> Option<u64> where
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() {
@@ -341,7 +341,7 @@ impl<T: Trait + staking::Trait> session::OneSessionHandler<T::AccountId> for Mod
}
fn on_disabled(i: usize) {
Self::deposit_consensus(ConsensusLog::OnDisabled(i as u64))
Self::deposit_consensus(ConsensusLog::OnDisabled(i as u32))
}
}