Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit 1ed5e70

Browse files
authored
Merge pull request paritytech#264 from subspace/format-cumulus-and-polkadot
Format cumulus and polkadot in the original form
2 parents f163ff1 + c34e734 commit 1ed5e70

File tree

7 files changed

+417
-407
lines changed

7 files changed

+417
-407
lines changed

cumulus/client/cli/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#![warn(missing_docs)]
2020
#![allow(clippy::all)]
2121

22+
use clap::Parser;
2223
use sc_service::{
2324
config::{PrometheusConfig, TelemetryEndpoints},
2425
BasePath, TransactionPoolOptions,
@@ -28,7 +29,6 @@ use std::{
2829
io::{self, Write},
2930
net::SocketAddr,
3031
};
31-
use clap::Parser;
3232

3333
/// The `purge-chain` command used to remove the whole chain: the parachain and the relaychain.
3434
#[derive(Debug, Parser)]

cumulus/client/consensus/relay-chain/src/import_queue.rs

Lines changed: 80 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -17,124 +17,111 @@
1717
use std::{marker::PhantomData, sync::Arc};
1818

1919
use sc_consensus::{
20-
import_queue::{BasicQueue, Verifier as VerifierT},
21-
BlockImport, BlockImportParams,
20+
import_queue::{BasicQueue, Verifier as VerifierT},
21+
BlockImport, BlockImportParams,
2222
};
2323
use sp_api::ProvideRuntimeApi;
2424
use sp_block_builder::BlockBuilder as BlockBuilderApi;
2525
use sp_blockchain::Result as ClientResult;
2626
use sp_consensus::{error::Error as ConsensusError, CacheKeyId};
2727
use sp_inherents::{CreateInherentDataProviders, InherentDataProvider};
2828
use sp_runtime::{
29-
generic::BlockId,
30-
traits::{Block as BlockT, Header as HeaderT},
29+
generic::BlockId,
30+
traits::{Block as BlockT, Header as HeaderT},
3131
};
3232

3333
/// A verifier that just checks the inherents.
3434
pub struct Verifier<Client, Block, CIDP> {
35-
client: Arc<Client>,
36-
create_inherent_data_providers: CIDP,
37-
_marker: PhantomData<Block>,
35+
client: Arc<Client>,
36+
create_inherent_data_providers: CIDP,
37+
_marker: PhantomData<Block>,
3838
}
3939

4040
impl<Client, Block, CIDP> Verifier<Client, Block, CIDP> {
41-
/// Create a new instance.
42-
pub fn new(client: Arc<Client>, create_inherent_data_providers: CIDP) -> Self {
43-
Self {
44-
client,
45-
create_inherent_data_providers,
46-
_marker: PhantomData,
47-
}
48-
}
41+
/// Create a new instance.
42+
pub fn new(client: Arc<Client>, create_inherent_data_providers: CIDP) -> Self {
43+
Self { client, create_inherent_data_providers, _marker: PhantomData }
44+
}
4945
}
5046

5147
#[async_trait::async_trait]
5248
impl<Client, Block, CIDP> VerifierT<Block> for Verifier<Client, Block, CIDP>
5349
where
54-
Block: BlockT,
55-
Client: ProvideRuntimeApi<Block> + Send + Sync,
56-
<Client as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block>,
57-
CIDP: CreateInherentDataProviders<Block, ()>,
50+
Block: BlockT,
51+
Client: ProvideRuntimeApi<Block> + Send + Sync,
52+
<Client as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block>,
53+
CIDP: CreateInherentDataProviders<Block, ()>,
5854
{
59-
async fn verify(
60-
&mut self,
61-
mut block_params: BlockImportParams<Block, ()>,
62-
) -> Result<
63-
(
64-
BlockImportParams<Block, ()>,
65-
Option<Vec<(CacheKeyId, Vec<u8>)>>,
66-
),
67-
String,
68-
> {
69-
if let Some(inner_body) = block_params.body.take() {
70-
let inherent_data_providers = self
71-
.create_inherent_data_providers
72-
.create_inherent_data_providers(*block_params.header.parent_hash(), ())
73-
.await
74-
.map_err(|e| e.to_string())?;
75-
76-
let inherent_data = inherent_data_providers
77-
.create_inherent_data()
78-
.map_err(|e| e.to_string())?;
79-
80-
let block = Block::new(block_params.header.clone(), inner_body);
81-
82-
let inherent_res = self
83-
.client
84-
.runtime_api()
85-
.check_inherents(
86-
&BlockId::Hash(*block.header().parent_hash()),
87-
block.clone(),
88-
inherent_data,
89-
)
90-
.map_err(|e| e.to_string())?;
91-
92-
if !inherent_res.ok() {
93-
for (i, e) in inherent_res.into_errors() {
94-
match inherent_data_providers.try_handle_error(&i, &e).await {
95-
Some(r) => r.map_err(|e| e.to_string())?,
96-
None => Err(format!(
97-
"Unhandled inherent error from `{}`.",
98-
String::from_utf8_lossy(&i)
99-
))?,
100-
}
101-
}
102-
}
103-
104-
let (_, inner_body) = block.deconstruct();
105-
block_params.body = Some(inner_body);
106-
}
107-
108-
block_params.post_hash = Some(block_params.header.hash());
109-
110-
Ok((block_params, None))
111-
}
55+
async fn verify(
56+
&mut self,
57+
mut block_params: BlockImportParams<Block, ()>,
58+
) -> Result<(BlockImportParams<Block, ()>, Option<Vec<(CacheKeyId, Vec<u8>)>>), String> {
59+
if let Some(inner_body) = block_params.body.take() {
60+
let inherent_data_providers = self
61+
.create_inherent_data_providers
62+
.create_inherent_data_providers(*block_params.header.parent_hash(), ())
63+
.await
64+
.map_err(|e| e.to_string())?;
65+
66+
let inherent_data =
67+
inherent_data_providers.create_inherent_data().map_err(|e| e.to_string())?;
68+
69+
let block = Block::new(block_params.header.clone(), inner_body);
70+
71+
let inherent_res = self
72+
.client
73+
.runtime_api()
74+
.check_inherents(
75+
&BlockId::Hash(*block.header().parent_hash()),
76+
block.clone(),
77+
inherent_data,
78+
)
79+
.map_err(|e| e.to_string())?;
80+
81+
if !inherent_res.ok() {
82+
for (i, e) in inherent_res.into_errors() {
83+
match inherent_data_providers.try_handle_error(&i, &e).await {
84+
Some(r) => r.map_err(|e| e.to_string())?,
85+
None => Err(format!(
86+
"Unhandled inherent error from `{}`.",
87+
String::from_utf8_lossy(&i)
88+
))?,
89+
}
90+
}
91+
}
92+
93+
let (_, inner_body) = block.deconstruct();
94+
block_params.body = Some(inner_body);
95+
}
96+
97+
block_params.post_hash = Some(block_params.header.hash());
98+
99+
Ok((block_params, None))
100+
}
112101
}
113102

114103
/// Start an import queue for a Cumulus collator that does not uses any special authoring logic.
115104
pub fn import_queue<Client, Block: BlockT, I, CIDP>(
116-
client: Arc<Client>,
117-
block_import: I,
118-
create_inherent_data_providers: CIDP,
119-
spawner: &impl sp_core::traits::SpawnEssentialNamed,
120-
registry: Option<&substrate_prometheus_endpoint::Registry>,
105+
client: Arc<Client>,
106+
block_import: I,
107+
create_inherent_data_providers: CIDP,
108+
spawner: &impl sp_core::traits::SpawnEssentialNamed,
109+
registry: Option<&substrate_prometheus_endpoint::Registry>,
121110
) -> ClientResult<BasicQueue<Block, I::Transaction>>
122111
where
123-
I: BlockImport<Block, Error = ConsensusError> + Send + Sync + 'static,
124-
I::Transaction: Send,
125-
Client: ProvideRuntimeApi<Block> + Send + Sync + 'static,
126-
<Client as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block>,
127-
CIDP: CreateInherentDataProviders<Block, ()> + 'static,
112+
I: BlockImport<Block, Error = ConsensusError> + Send + Sync + 'static,
113+
I::Transaction: Send,
114+
Client: ProvideRuntimeApi<Block> + Send + Sync + 'static,
115+
<Client as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block>,
116+
CIDP: CreateInherentDataProviders<Block, ()> + 'static,
128117
{
129-
let verifier = Verifier::new(client, create_inherent_data_providers);
130-
131-
Ok(BasicQueue::new(
132-
verifier,
133-
Box::new(cumulus_client_consensus_common::ParachainBlockImport::new(
134-
block_import,
135-
)),
136-
None,
137-
spawner,
138-
registry,
139-
))
118+
let verifier = Verifier::new(client, create_inherent_data_providers);
119+
120+
Ok(BasicQueue::new(
121+
verifier,
122+
Box::new(cumulus_client_consensus_common::ParachainBlockImport::new(block_import)),
123+
None,
124+
spawner,
125+
registry,
126+
))
140127
}

cumulus/parachain-template/node/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::chain_spec;
2-
use std::path::PathBuf;
32
use clap::{AppSettings, Parser};
3+
use std::path::PathBuf;
44

55
/// Sub-commands supported by the collator.
66
#[derive(Debug, clap::Subcommand)]

cumulus/parachain-template/node/src/service.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
22
33
// std
4-
use std::sync::Arc;
54
use sc_basic_authorship::ProposerFactory;
5+
use std::sync::Arc;
66

77
// Local Runtime Types
8-
use parachain_template_runtime::{
9-
opaque::Block, AccountId, Balance, Index as Nonce, RuntimeApi,
10-
};
8+
use parachain_template_runtime::{opaque::Block, AccountId, Balance, Index as Nonce, RuntimeApi};
119

1210
// Cumulus Imports
1311
use cirrus_client_service::prepare_node_config;
@@ -230,18 +228,15 @@ where
230228
let (mut telemetry, _telemetry_worker_handle) = params.other;
231229

232230
let primary_chain_full_node = {
233-
let span = tracing::info_span!(
234-
sc_tracing::logging::PREFIX_LOG_SPAN,
235-
name = "Primarychain"
236-
);
231+
let span = tracing::info_span!(sc_tracing::logging::PREFIX_LOG_SPAN, name = "Primarychain");
237232
let _enter = span.enter();
238233

239234
subspace_service::new_full::<subspace_runtime::RuntimeApi, SubspaceExecutorDispatch>(
240235
polkadot_config,
241236
false,
242237
)
243-
.await
244-
.map_err(|_| sc_service::Error::Other("Failed to build a full subspace node".into()))?
238+
.await
239+
.map_err(|_| sc_service::Error::Other("Failed to build a full subspace node".into()))?
245240
};
246241

247242
let client = params.client.clone();

cumulus/rustfmt.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Basic
2+
edition = "2021"
3+
hard_tabs = true
4+
max_width = 100
5+
use_small_heuristics = "Max"
6+
7+
# Imports
8+
imports_granularity = "Crate"
9+
reorder_imports = true
10+
11+
# Consistency
12+
newline_style = "Unix"
13+
14+
# Misc
15+
binop_separator = "Back"
16+
chain_width = 80
17+
match_arm_blocks = false
18+
match_arm_leading_pipes = "Preserve"
19+
match_block_trailing_comma = true
20+
reorder_impl_items = false
21+
spaces_around_ranges = false
22+
trailing_comma = "Vertical"
23+
trailing_semicolon = false
24+
use_field_init_shorthand = true

0 commit comments

Comments
 (0)