Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Prev Previous commit
Next Next commit
Fix line widths
  • Loading branch information
expenses committed Jun 10, 2020
commit f1d6035299ed3f044690a4c0ba72ecd2f671597c
24 changes: 13 additions & 11 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ macro_rules! new_full {

// GenesisAuthoritySetProvider is implemented for StorageAndProofProvider
let provider = client.clone() as Arc<dyn grandpa::StorageAndProofProvider<_, _>>;
let finality_proof_provider = Arc::new(grandpa::FinalityProofProvider::new(backend.clone(), provider)) as _;
let finality_proof_provider =
Arc::new(grandpa::FinalityProofProvider::new(backend.clone(), provider));

let service = sc_service::build(sc_service::ServiceParams {
config: $config,
Expand Down Expand Up @@ -333,9 +334,8 @@ pub fn new_light(config: Configuration)
-> Result<impl AbstractService, ServiceError> {
let inherent_data_providers = InherentDataProviders::new();

let ((client, backend, keystore, task_manager), fetcher, remote_blockchain) = sc_service::new_light_parts::<
Block, RuntimeApi, node_executor::Executor
>(&config)?;
let ((client, backend, keystore, task_manager), fetcher, remote_blockchain) =
sc_service::new_light_parts::<Block, RuntimeApi, node_executor::Executor>(&config)?;
let client = Arc::new(client);

let registry = config.prometheus_config.as_ref().map(|cfg| cfg.registry.clone());
Expand All @@ -348,12 +348,13 @@ pub fn new_light(config: Configuration)
let pool_api = sc_transaction_pool::FullChainApi::new(
client.clone(),
);
let (transaction_pool, transaction_pool_task) = sc_transaction_pool::BasicPool::with_revalidation_type(
config.transaction_pool.clone(),
std::sync::Arc::new(pool_api),
registry.as_ref(),
sc_transaction_pool::RevalidationType::Light,
);
let (transaction_pool, transaction_pool_task) =
sc_transaction_pool::BasicPool::with_revalidation_type(
config.transaction_pool.clone(),
std::sync::Arc::new(pool_api),
registry.as_ref(),
sc_transaction_pool::RevalidationType::Light,
);
let transaction_pool = Arc::new(transaction_pool);

if let Some(task) = transaction_pool_task {
Expand Down Expand Up @@ -392,7 +393,8 @@ pub fn new_light(config: Configuration)

// GenesisAuthoritySetProvider is implemented for StorageAndProofProvider
let provider = client.clone() as Arc<dyn StorageAndProofProvider<_, _>>;
let finality_proof_provider = Arc::new(GrandpaFinalityProofProvider::new(backend.clone(), provider)) as _;
let finality_proof_provider =
Arc::new(GrandpaFinalityProofProvider::new(backend.clone(), provider));

let rpc_client = client.clone();
let rpc_transaction_pool = transaction_pool.clone();
Expand Down
6 changes: 5 additions & 1 deletion client/cli/src/commands/build_spec_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ pub struct BuildSpecCmd {

impl BuildSpecCmd {
/// Run the build-spec command
pub fn run(&self, mut spec: Box<dyn ChainSpec>, network_config: NetworkConfiguration) -> error::Result<()> {
pub fn run(
&self,
mut spec: Box<dyn ChainSpec>,
network_config: NetworkConfiguration
) -> error::Result<()> {
info!("Building chain spec");
let raw_output = self.raw;

Expand Down
4 changes: 3 additions & 1 deletion client/cli/src/commands/revert_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ pub struct RevertCmd {

impl RevertCmd {
/// Run the revert command
pub fn run<B, BA, CE, RA>(&self, client: std::sync::Arc<sc_service::Client<BA, CE, B, RA>>) -> error::Result<()>
pub fn run<B, BA, CE, RA>(
&self, client: std::sync::Arc<sc_service::Client<BA, CE, B, RA>>
) -> error::Result<()>
where
B: BlockT,
BA: sc_client_api::backend::Backend<B> + 'static,
Expand Down
8 changes: 4 additions & 4 deletions client/cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use futures::select;
use futures::{future, future::FutureExt, Future};
use log::info;
use sc_service::{AbstractService, Configuration, Role, config::TaskType};
use sp_runtime::traits::{Block as BlockT};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use sp_utils::metrics::{TOKIO_THREADS_ALIVE, TOKIO_THREADS_TOTAL};
use sp_version::RuntimeVersion;
use std::{fmt::Debug, marker::PhantomData, str::FromStr, sync::Arc};
Expand Down Expand Up @@ -241,9 +241,9 @@ impl<C: SubstrateCli> Runner<C> {
CE: sc_client_api::call_executor::CallExecutor<B> + Send + Sync + 'static,
IQ: sc_service::ImportQueue<B> + 'static,
RA: Send + Sync + 'static,
<B as sp_runtime::traits::Block>::Hash: std::str::FromStr,
<<B as sp_runtime::traits::Block>::Hash as FromStr>::Err: Debug,
<<<B as sp_runtime::traits::Block>::Header as sp_runtime::traits::Header>::Number as std::str::FromStr>::Err: std::fmt::Debug,
<B as BlockT>::Hash: FromStr,
<<B as BlockT>::Hash as FromStr>::Err: Debug,
<<<B as BlockT>::Header as HeaderT>::Number as FromStr>::Err: Debug,
{
let chain_spec = self.config.chain_spec.cloned_box();
let network_config = self.config.network.clone();
Expand Down
1 change: 1 addition & 0 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ use sp_core::traits::CodeExecutor;
use sp_runtime::BuildStorage;
use sc_client_api::execution_extensions::ExecutionExtensions;

/// A background task that is passed into `build` in `background_tasks`.
pub type BackgroundTask = Pin<Box<dyn Future<Output=()> + Send>>;

/// A utility trait for building an RPC extension given a `DenyUnsafe` instance.
Expand Down
46 changes: 32 additions & 14 deletions client/service/src/chain_ops/import_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ pub fn build_spec(spec: &dyn ChainSpec, raw: bool) -> error::Result<String> {
}


/// Helper enum that wraps either a binary decoder (from parity-scale-codec), or a JSON decoder (from serde_json).
/// Implements the Iterator Trait, calling `next()` will decode the next SignedBlock and return it.
/// Helper enum that wraps either a binary decoder (from parity-scale-codec), or a JSON decoder
/// (from serde_json). Implements the Iterator Trait, calling `next()` will decode the next
/// SignedBlock and return it.
enum BlockIter<R, B> where
R: std::io::Read + std::io::Seek,
{
Expand Down Expand Up @@ -132,7 +133,7 @@ impl<R, B> Iterator for BlockIter<R, B> where
match self {
BlockIter::Binary { num_expected_blocks, read_block_count, reader } => {
if read_block_count < num_expected_blocks {
let block_result: Result<SignedBlock::<B>, _> = SignedBlock::<B>::decode(reader)
let block_result: Result<SignedBlock::<B>, _> = SignedBlock::<B>::decode(reader)
.map_err(|e| e.to_string());
*read_block_count += 1;
Some(block_result)
Expand Down Expand Up @@ -267,7 +268,8 @@ enum ImportState<R, B> where
{
/// We are reading from the BlockIter structure, adding those blocks to the queue if possible.
Reading{block_iter: BlockIter<R, B>},
/// The queue is full (contains at least MAX_PENDING_BLOCKS blocks) and we are waiting for it to catch up.
/// The queue is full (contains at least MAX_PENDING_BLOCKS blocks) and we are waiting for it to
/// catch up.
WaitingForImportQueueToCatchUp{
block_iter: BlockIter<R, B>,
delay: Delay,
Expand Down Expand Up @@ -362,17 +364,21 @@ where
let num_expected_blocks = block_iter.num_expected_blocks();
let read_block_count = block_iter.read_block_count();
let delay = Delay::new(Duration::from_millis(DELAY_TIME));
state = Some(ImportState::WaitingForImportQueueToFinish{num_expected_blocks, read_block_count, delay});
state = Some(ImportState::WaitingForImportQueueToFinish {
num_expected_blocks, read_block_count, delay
});
},
Some(block_result) => {
let read_block_count = block_iter.read_block_count();
match block_result {
Ok(block) => {
if read_block_count - link.imported_blocks >= MAX_PENDING_BLOCKS {
// The queue is full, so do not add this block and simply wait until
// the queue has made some progress.
// The queue is full, so do not add this block and simply wait
// until the queue has made some progress.
let delay = Delay::new(Duration::from_millis(DELAY_TIME));
state = Some(ImportState::WaitingForImportQueueToCatchUp{block_iter, delay, block});
state = Some(ImportState::WaitingForImportQueueToCatchUp {
block_iter, delay, block
});
} else {
// Queue is not full, we can keep on adding blocks to the queue.
import_block_to_queue(block, queue, force);
Expand All @@ -381,7 +387,9 @@ where
}
Err(e) => {
return Poll::Ready(
Err(Error::Other(format!("Error reading block #{}: {}", read_block_count, e))))
Err(Error::Other(
format!("Error reading block #{}: {}", read_block_count, e)
)))
}
}
}
Expand All @@ -393,22 +401,28 @@ where
// Queue is still full, so wait until there is room to insert our block.
match Pin::new(&mut delay).poll(cx) {
Poll::Pending => {
state = Some(ImportState::WaitingForImportQueueToCatchUp{block_iter, delay, block});
state = Some(ImportState::WaitingForImportQueueToCatchUp {
block_iter, delay, block
});
return Poll::Pending
},
Poll::Ready(_) => {
delay.reset(Duration::from_millis(DELAY_TIME));
},
}
state = Some(ImportState::WaitingForImportQueueToCatchUp{block_iter, delay, block});
state = Some(ImportState::WaitingForImportQueueToCatchUp {
block_iter, delay, block
});
} else {
// Queue is no longer full, so we can add our block to the queue.
import_block_to_queue(block, queue, force);
// Switch back to Reading state.
state = Some(ImportState::Reading{block_iter});
}
},
ImportState::WaitingForImportQueueToFinish{num_expected_blocks, read_block_count, mut delay} => {
ImportState::WaitingForImportQueueToFinish {
num_expected_blocks, read_block_count, mut delay
} => {
// All the blocks have been added to the queue, which doesn't mean they
// have all been properly imported.
if importing_is_done(num_expected_blocks, read_block_count, link.imported_blocks) {
Expand All @@ -423,15 +437,19 @@ where
// Wait for the delay, because we know the queue is lagging behind.
match Pin::new(&mut delay).poll(cx) {
Poll::Pending => {
state = Some(ImportState::WaitingForImportQueueToFinish{num_expected_blocks, read_block_count, delay});
state = Some(ImportState::WaitingForImportQueueToFinish {
num_expected_blocks, read_block_count, delay
});
return Poll::Pending
},
Poll::Ready(_) => {
delay.reset(Duration::from_millis(DELAY_TIME));
},
}

state = Some(ImportState::WaitingForImportQueueToFinish{num_expected_blocks, read_block_count, delay});
state = Some(ImportState::WaitingForImportQueueToFinish {
num_expected_blocks, read_block_count, delay
});
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion client/service/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ impl<G, E, F, L, U> TestNet<G, E, F, L, U> where
for (key, authority) in authorities {
let task_executor = {
let executor = executor.clone();
Arc::new(move |fut: Pin<Box<dyn futures::Future<Output = ()> + Send>>, _: TaskType| executor.spawn(fut.unit_error().compat()))
Arc::new(move |fut: Pin<Box<dyn futures::Future<Output = ()> + Send>>, _| {
executor.spawn(fut.unit_error().compat())
})
};
let node_config = node_config(
self.nodes,
Expand Down