babe: pass epoch data via intermediates (#4807)

* babe: pass epoch data via intermediates

* Switch to use Box<dyn Any> for intermediates

* Set intermediate.epoch to be Option

* Fix proposer should put out an empty intermediate

* Remove unnecessary encode/decode

* Add EpochData to block_import_params in slot worker

* Fix aura compile

* Fix integration test
This commit is contained in:
Wei Tang
2020-02-06 18:52:30 +01:00
committed by GitHub
parent 4df27e760e
commit 14b0c9a746
7 changed files with 106 additions and 34 deletions
+24 -4
View File
@@ -371,8 +371,11 @@ pub fn new_light(config: NodeConfiguration)
#[cfg(test)]
mod tests {
use std::sync::Arc;
use sc_consensus_babe::CompatibleDigestItem;
use std::{sync::Arc, collections::HashMap, borrow::Cow, any::Any};
use sc_consensus_babe::{
CompatibleDigestItem, BabeIntermediate, INTERMEDIATE_KEY
};
use sc_consensus_epochs::descendent_query;
use sp_consensus::{
Environment, Proposer, BlockImportParams, BlockOrigin, ForkChoiceStrategy, BlockImport,
RecordProof,
@@ -384,7 +387,7 @@ mod tests {
use sp_core::{crypto::Pair as CryptoPair, H256};
use sp_runtime::{
generic::{BlockId, Era, Digest, SignedPayload},
traits::Block as BlockT,
traits::{Block as BlockT, Header as HeaderT},
traits::Verify,
OpaqueExtrinsic,
};
@@ -499,11 +502,21 @@ mod tests {
let parent_id = BlockId::number(service.client().chain_info().best_number);
let parent_header = service.client().header(&parent_id).unwrap().unwrap();
let parent_hash = parent_header.hash();
let parent_number = *parent_header.number();
let mut proposer_factory = sc_basic_authorship::ProposerFactory {
client: service.client(),
transaction_pool: service.transaction_pool(),
};
let epoch = babe_link.epoch_changes().lock().epoch_for_child_of(
descendent_query(&*service.client()),
&parent_hash,
parent_number,
slot_num,
|slot| babe_link.config().genesis_epoch(slot)
).unwrap().unwrap();
let mut digest = Digest::<H256>::default();
// even though there's only one authority some slots might be empty,
@@ -555,7 +568,14 @@ mod tests {
storage_changes: None,
finalized: false,
auxiliary: Vec::new(),
intermediates: Default::default(),
intermediates: {
let mut intermediates = HashMap::new();
intermediates.insert(
Cow::from(INTERMEDIATE_KEY),
Box::new(BabeIntermediate { epoch }) as Box<dyn Any>,
);
intermediates
},
fork_choice: Some(ForkChoiceStrategy::LongestChain),
allow_missing_state: false,
import_existing: false,