Clean up the basic-authorship crate (#3206)

* Switch consensus-common to new futures

* Fix tests

* More tests fixing

* Make Proposer, OnSlot and SyncOracle mut

* Make the Environment mut as well

* Fix test

* Fix Babe tests

* Babe fixes

* Fix CLI service tests

* Fix Babe tests

* Remove unnecessary trait bound

* Inline the code of BlockBuilder and AuthoringApi

* Remove warning lint

* Bounds simplification

* Imports simplification

* Don't panic on bad generated block

* Code style

* Add doc example

* Remove dependency on aura

* Order dependencies alphabetically

* Minor style
This commit is contained in:
Pierre Krieger
2019-07-28 02:24:51 +02:00
committed by DemiMarie-parity
parent ba55d31d44
commit 9370a4a6b6
13 changed files with 203 additions and 219 deletions
+4 -5
View File
@@ -154,7 +154,7 @@ pub struct BabeParams<C, E, I, SO, SC> {
pub block_import: I,
/// The environment
pub env: Arc<E>,
pub env: E,
/// A sync oracle
pub sync_oracle: SO,
@@ -220,7 +220,7 @@ pub fn start_babe<B, C, SC, E, I, SO, Error, H>(BabeParams {
struct BabeWorker<C, E, I, SO> {
client: Arc<C>,
block_import: Arc<Mutex<I>>,
env: Arc<E>,
env: E,
local_key: Arc<sr25519::Pair>,
sync_oracle: SO,
force_authoring: bool,
@@ -245,14 +245,13 @@ impl<Hash, H, B, C, E, I, Error, SO> SlotWorker<B> for BabeWorker<C, E, I, SO> w
type OnSlot = Pin<Box<dyn Future<Output = Result<(), consensus_common::Error>> + Send>>;
fn on_slot(
&self,
&mut self,
chain_head: B::Header,
slot_info: SlotInfo,
) -> Self::OnSlot {
let pair = self.local_key.clone();
let ref client = self.client;
let block_import = self.block_import.clone();
let ref env = self.env;
let (timestamp, slot_number, slot_duration) =
(slot_info.timestamp, slot_info.number, slot_info.duration);
@@ -305,7 +304,7 @@ impl<Hash, H, B, C, E, I, Error, SO> SlotWorker<B> for BabeWorker<C, E, I, SO> w
);
// we are the slot author. make a block and sign it.
let proposer = match env.init(&chain_head) {
let mut proposer = match self.env.init(&chain_head) {
Ok(p) => p,
Err(e) => {
warn!(target: "babe",
+5 -5
View File
@@ -52,7 +52,7 @@ impl Environment<TestBlock> for DummyFactory {
type Proposer = DummyProposer;
type Error = Error;
fn init(&self, parent_header: &<TestBlock as BlockT>::Header)
fn init(&mut self, parent_header: &<TestBlock as BlockT>::Header)
-> Result<DummyProposer, Error>
{
Ok(DummyProposer(parent_header.number + 1, self.0.clone()))
@@ -64,7 +64,7 @@ impl Proposer<TestBlock> for DummyProposer {
type Create = future::Ready<Result<TestBlock, Error>>;
fn propose(
&self,
&mut self,
_: InherentData,
digests: DigestFor<TestBlock>,
_: Duration,
@@ -199,7 +199,7 @@ fn run_one_test() {
let mut runtime = current_thread::Runtime::new().unwrap();
for (peer_id, key) in peers {
let client = net.lock().peer(*peer_id).client().as_full().unwrap();
let environ = Arc::new(DummyFactory(client.clone()));
let environ = DummyFactory(client.clone());
import_notifications.push(
client.import_notification_stream()
.take_while(|n| future::ready(!(n.origin != BlockOrigin::Own && n.header.number() < &5)))
@@ -224,7 +224,7 @@ fn run_one_test() {
block_import: client.clone(),
select_chain,
client,
env: environ.clone(),
env: environ,
sync_oracle: DummyOracle,
inherent_data_providers,
force_authoring: false,
@@ -236,7 +236,7 @@ fn run_one_test() {
net.lock().poll();
Ok::<_, ()>(futures01::Async::NotReady::<()>)
}));
runtime.block_on(future::join_all(import_notifications)
.map(|_| Ok::<(), ()>(())).compat()).unwrap();
}