Refactor epoch changes to a separate crate (#4785)

* Init epoch changes module

* Initial integration of new epoch changes module for BABE

* Fix all initial compile errors

* rename: digest -> digests

* Fix babe tests

* Bump impl_version

* Fix more test issues

* Remove test flag for tree

It unfortunately won't work for multiple crates.

* Update cargo lock

* Fix duplicate parking_lot version

* Add missing license header
This commit is contained in:
Wei Tang
2020-02-06 16:48:38 +01:00
committed by GitHub
parent c7a7197f97
commit 4df27e760e
15 changed files with 265 additions and 218 deletions
+8 -7
View File
@@ -35,8 +35,9 @@ use sp_staking::{
use codec::{Encode, Decode};
use sp_inherents::{InherentIdentifier, InherentData, ProvideInherent, MakeFatalError};
use sp_consensus_babe::{
BABE_ENGINE_ID, ConsensusLog, BabeAuthorityWeight, NextEpochDescriptor, RawBabePreDigest,
SlotNumber, inherents::{INHERENT_IDENTIFIER, BabeInherentData}
BABE_ENGINE_ID, ConsensusLog, BabeAuthorityWeight, SlotNumber,
inherents::{INHERENT_IDENTIFIER, BabeInherentData},
digests::{NextEpochDescriptor, RawPreDigest},
};
pub use sp_consensus_babe::{AuthorityId, VRF_OUTPUT_LENGTH, PUBLIC_KEY_LENGTH};
@@ -205,11 +206,11 @@ impl<T: Trait> FindAuthor<u32> for Module<T> {
{
for (id, mut data) in digests.into_iter() {
if id == BABE_ENGINE_ID {
let pre_digest = RawBabePreDigest::decode(&mut data).ok()?;
let pre_digest = RawPreDigest::decode(&mut data).ok()?;
return Some(match pre_digest {
RawBabePreDigest::Primary { authority_index, .. } =>
RawPreDigest::Primary { authority_index, .. } =>
authority_index,
RawBabePreDigest::Secondary { authority_index, .. } =>
RawPreDigest::Secondary { authority_index, .. } =>
authority_index,
});
}
@@ -397,7 +398,7 @@ impl<T: Trait> Module<T> {
.iter()
.filter_map(|s| s.as_pre_runtime())
.filter_map(|(id, mut data)| if id == BABE_ENGINE_ID {
RawBabePreDigest::decode(&mut data).ok()
RawPreDigest::decode(&mut data).ok()
} else {
None
})
@@ -424,7 +425,7 @@ impl<T: Trait> Module<T> {
CurrentSlot::put(digest.slot_number());
if let RawBabePreDigest::Primary { vrf_output, .. } = digest {
if let RawPreDigest::Primary { vrf_output, .. } = digest {
// place the VRF output into the `Initialized` storage item
// and it'll be put onto the under-construction randomness
// later, once we've decided which epoch this block is in.
+2 -2
View File
@@ -34,7 +34,7 @@ fn make_pre_digest(
vrf_output: [u8; sp_consensus_babe::VRF_OUTPUT_LENGTH],
vrf_proof: [u8; sp_consensus_babe::VRF_PROOF_LENGTH],
) -> Digest {
let digest_data = sp_consensus_babe::RawBabePreDigest::Primary {
let digest_data = sp_consensus_babe::digests::RawPreDigest::Primary {
authority_index,
slot_number,
vrf_output,
@@ -110,7 +110,7 @@ fn first_block_epoch_zero_start() {
let authorities = Babe::authorities();
let consensus_log = sp_consensus_babe::ConsensusLog::NextEpochData(
sp_consensus_babe::NextEpochDescriptor {
sp_consensus_babe::digests::NextEpochDescriptor {
authorities,
randomness: Babe::randomness(),
}