Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Start switching grandpa to stable futures
Browse files Browse the repository at this point in the history
  • Loading branch information
expenses committed Jan 10, 2020
1 parent 4e29d08 commit 9c19763
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
5 changes: 2 additions & 3 deletions bin/node-template/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub use sc_executor::NativeExecutor;
use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair};
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
use sc_basic_authority;
use futures::{FutureExt, compat::Future01CompatExt};

// Our native executor instance.
native_executor_instance!(
Expand Down Expand Up @@ -164,7 +163,7 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
service.network(),
service.on_exit(),
service.spawn_task_handle(),
)?.compat().map(drop));
)?);
},
(true, false) => {
// start the full GRANDPA voter
Expand All @@ -181,7 +180,7 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon

// the GRANDPA voter task is considered infallible, i.e.
// if it fails we take down the service with it.
service.spawn_essential_task(grandpa::run_grandpa_voter(voter_config)?.compat().map(drop));
service.spawn_essential_task(grandpa::run_grandpa_voter(voter_config)?);
},
(_, true) => {
grandpa::setup_disabled_grandpa(
Expand Down
9 changes: 3 additions & 6 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ macro_rules! new_full_start {
/// concrete types instead.
macro_rules! new_full {
($config:expr, $with_startup_data: expr) => {{
use futures::{
prelude::*,
compat::Future01CompatExt
};
use futures::prelude::*;
use sc_network::Event;

let (
Expand Down Expand Up @@ -222,7 +219,7 @@ macro_rules! new_full {
service.network(),
service.on_exit(),
service.spawn_task_handle(),
)?.compat().map(drop));
)?);
},
(true, false) => {
// start the full GRANDPA voter
Expand All @@ -239,7 +236,7 @@ macro_rules! new_full {
// the GRANDPA voter task is considered infallible, i.e.
// if it fails we take down the service with it.
service.spawn_essential_task(
grandpa::run_grandpa_voter(grandpa_config)?.compat().map(drop)
grandpa::run_grandpa_voter(grandpa_config)?
);
},
(_, true) => {
Expand Down
8 changes: 4 additions & 4 deletions client/finality-grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ pub struct GrandpaParams<B, E, Block: BlockT, N, RA, SC, VR, X, Sp> {
/// block import worker that has already been instantiated with `block_import`.
pub fn run_grandpa_voter<B, E, Block: BlockT, N, RA, SC, VR, X, Sp>(
grandpa_params: GrandpaParams<B, E, Block, N, RA, SC, VR, X, Sp>,
) -> sp_blockchain::Result<impl Future<Item=(),Error=()> + Send + 'static> where
) -> sp_blockchain::Result<impl futures03::Future<Output=()> + Send + 'static> where
Block::Hash: Ord,
B: Backend<Block> + 'static,
E: CallExecutor<Block> + Send + Sync + 'static,
Expand Down Expand Up @@ -639,9 +639,9 @@ pub fn run_grandpa_voter<B, E, Block: BlockT, N, RA, SC, VR, X, Sp>(
let telemetry_task = telemetry_task
.then(|_| futures::future::empty::<(), ()>());

use futures03::{FutureExt, TryFutureExt};
use futures03::{FutureExt, TryFutureExt, future::select, compat::Future01CompatExt};

Ok(voter_work.select(on_exit.map(Ok).compat()).select2(telemetry_task).then(|_| Ok(())))
Ok(select(select(voter_work.compat(), telemetry_task.compat()), on_exit).map(drop))
}

/// Future that powers the voter.
Expand Down Expand Up @@ -885,7 +885,7 @@ where
#[deprecated(since = "1.1.0", note = "Please switch to run_grandpa_voter.")]
pub fn run_grandpa<B, E, Block: BlockT, N, RA, SC, VR, X, Sp>(
grandpa_params: GrandpaParams<B, E, Block, N, RA, SC, VR, X, Sp>,
) -> sp_blockchain::Result<impl Future<Item=(),Error=()> + Send + 'static> where
) -> sp_blockchain::Result<impl futures03::Future<Output=()> + Send + 'static> where
Block::Hash: Ord,
B: Backend<Block> + 'static,
E: CallExecutor<Block> + Send + Sync + 'static,
Expand Down
12 changes: 6 additions & 6 deletions client/finality-grandpa/src/observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub fn run_grandpa_observer<B, E, Block: BlockT, N, RA, SC, Sp>(
network: N,
on_exit: impl futures03::Future<Output=()> + Clone + Send + Unpin + 'static,
executor: Sp,
) -> sp_blockchain::Result<impl Future<Item=(), Error=()> + Send + 'static> where
) -> sp_blockchain::Result<impl futures03::Future<Output=()> + Send + 'static> where
B: Backend<Block> + 'static,
E: CallExecutor<Block> + Send + Sync + 'static,
N: NetworkT<Block> + Send + Clone + 'static,
Expand Down Expand Up @@ -195,9 +195,9 @@ pub fn run_grandpa_observer<B, E, Block: BlockT, N, RA, SC, Sp>(
warn!("GRANDPA Observer failed: {:?}", e);
});

use futures03::{FutureExt, TryFutureExt};
use futures03::{FutureExt, future::select, compat::Future01CompatExt};

Ok(observer_work.select(on_exit.map(Ok).compat()).map(|_| ()).map_err(|_| ()))
Ok(select(observer_work.compat(), on_exit).map(drop))
}

/// Future that powers the observer.
Expand Down Expand Up @@ -359,12 +359,12 @@ where
}

match self.voter_commands_rx.poll() {
Ok(Async::NotReady) => {}
Err(_) => {
Ok(Async::No{
// the `voter_commands_rx` stream should not fail.
return Ok(Async::Ready(()))
}
Ok(Async::Ready(None)) => {
Ok(Async::Ready(None)) => tReady) => {}
Err(_) => {
// the `voter_commands_rx` stream should never conclude since it's never closed.
return Ok(Async::Ready(()))
}
Expand Down
Binary file added utils/prometheus/README.pdf
Binary file not shown.

0 comments on commit 9c19763

Please sign in to comment.