cargo +nightly fmt (#3540)

* cargo +nightly fmt

* add cargo-fmt check to ci

* update ci

* fmt

* fmt

* skip macro

* ignore bridges
This commit is contained in:
Shawn Tabrizi
2021-08-02 12:47:33 +02:00
committed by GitHub
parent 30e3012270
commit ff5d56fb76
350 changed files with 20617 additions and 21266 deletions
@@ -93,17 +93,15 @@ impl SubstrateCli for Cli {
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
let id = if id.is_empty() { "rococo" } else { id };
Ok(match id {
"rococo-staging" => {
Box::new(polkadot_service::chain_spec::rococo_staging_testnet_config()?)
}
"rococo-local" => {
Box::new(polkadot_service::chain_spec::rococo_local_testnet_config()?)
}
"rococo-staging" =>
Box::new(polkadot_service::chain_spec::rococo_staging_testnet_config()?),
"rococo-local" =>
Box::new(polkadot_service::chain_spec::rococo_local_testnet_config()?),
"rococo" => Box::new(polkadot_service::chain_spec::rococo_config()?),
path => {
let path = std::path::PathBuf::from(path);
Box::new(polkadot_service::RococoChainSpec::from_json_file(path)?)
}
},
})
}
@@ -16,19 +16,23 @@
//! Collator for the adder test parachain.
use futures::channel::oneshot;
use futures_timer::Delay;
use polkadot_node_primitives::{Collation, CollatorFn, CollationResult, Statement, SignedFullStatement};
use parity_scale_codec::{Decode, Encode};
use polkadot_node_primitives::{
Collation, CollationResult, CollatorFn, PoV, SignedFullStatement, Statement,
};
use polkadot_primitives::v1::{CollatorId, CollatorPair};
use polkadot_node_primitives::PoV;
use parity_scale_codec::{Encode, Decode};
use sp_core::{Pair, traits::SpawnNamed};
use sp_core::{traits::SpawnNamed, Pair};
use std::{
collections::HashMap,
sync::{Arc, Mutex, atomic::{AtomicU32, Ordering}},
sync::{
atomic::{AtomicU32, Ordering},
Arc, Mutex,
},
time::Duration,
};
use test_parachain_adder::{execute, hash_state, BlockData, HeadData};
use futures::channel::oneshot;
/// The amount we add when producing a new block.
///
@@ -37,11 +41,8 @@ const ADD: u64 = 2;
/// Calculates the head and state for the block with the given `number`.
fn calculate_head_and_state_for_number(number: u64) -> (HeadData, u64) {
let mut head = HeadData {
number: 0,
parent_hash: Default::default(),
post_state: hash_state(0),
};
let mut head =
HeadData { number: 0, parent_hash: Default::default(), post_state: hash_state(0) };
let mut state = 0u64;
@@ -89,11 +90,11 @@ impl State {
add: ADD,
};
let new_head = execute(parent_head.hash(), parent_head, &block).expect("Produces valid block");
let new_head =
execute(parent_head.hash(), parent_head, &block).expect("Produces valid block");
let new_head_arc = Arc::new(new_head.clone());
self.head_to_state
.insert(new_head_arc.clone(), block.state.wrapping_add(ADD));
self.head_to_state.insert(new_head_arc.clone(), block.state.wrapping_add(ADD));
self.number_to_head.insert(new_head.number, new_head_arc);
(block, new_head)
@@ -146,7 +147,10 @@ impl Collator {
/// Create the collation function.
///
/// This collation function can be plugged into the overseer to generate collations for the adder parachain.
pub fn create_collation_function(&self, spawner: impl SpawnNamed + Clone + 'static) -> CollatorFn {
pub fn create_collation_function(
&self,
spawner: impl SpawnNamed + Clone + 'static,
) -> CollatorFn {
use futures::FutureExt as _;
let state = self.state.clone();
@@ -180,21 +184,29 @@ impl Collator {
let (result_sender, recv) = oneshot::channel::<SignedFullStatement>();
let seconded_collations = seconded_collations.clone();
spawner.spawn("adder-collator-seconded", async move {
if let Ok(res) = recv.await {
if !matches!(
res.payload(),
Statement::Seconded(s) if s.descriptor.pov_hash == compressed_pov.hash(),
) {
log::error!("Seconded statement should match our collation: {:?}", res.payload());
std::process::exit(-1);
spawner.spawn(
"adder-collator-seconded",
async move {
if let Ok(res) = recv.await {
if !matches!(
res.payload(),
Statement::Seconded(s) if s.descriptor.pov_hash == compressed_pov.hash(),
) {
log::error!(
"Seconded statement should match our collation: {:?}",
res.payload()
);
std::process::exit(-1);
}
seconded_collations.fetch_add(1, Ordering::Relaxed);
}
seconded_collations.fetch_add(1, Ordering::Relaxed);
}
}.boxed());
.boxed(),
);
async move { Some(CollationResult { collation, result_sender: Some(result_sender) }) }.boxed()
async move { Some(CollationResult { collation, result_sender: Some(result_sender) }) }
.boxed()
})
}
@@ -207,7 +219,7 @@ impl Collator {
let current_block = self.state.lock().unwrap().best_block;
if start_block + blocks <= current_block {
return;
return
}
}
}
@@ -222,7 +234,7 @@ impl Collator {
Delay::new(Duration::from_secs(1)).await;
if seconded <= seconded_collations.load(Ordering::Relaxed) {
return;
return
}
}
}
@@ -233,7 +245,7 @@ mod tests {
use super::*;
use futures::executor::block_on;
use polkadot_parachain::{primitives::{ValidationParams, ValidationResult}};
use polkadot_parachain::primitives::{ValidationParams, ValidationResult};
use polkadot_primitives::v1::PersistedValidationData;
#[test]
@@ -243,14 +255,8 @@ mod tests {
let collation_function = collator.create_collation_function(spawner);
for i in 0..5 {
let parent_head = collator
.state
.lock()
.unwrap()
.number_to_head
.get(&i)
.unwrap()
.clone();
let parent_head =
collator.state.lock().unwrap().number_to_head.get(&i).unwrap().clone();
let validation_data = PersistedValidationData {
parent_head: parent_head.encode().into(),
@@ -263,11 +269,7 @@ mod tests {
}
}
fn validate_collation(
collator: &Collator,
parent_head: HeadData,
collation: Collation,
) {
fn validate_collation(collator: &Collator, parent_head: HeadData, collation: Collation) {
use polkadot_node_core_pvf::testing::validate_candidate;
let ret_buf = validate_candidate(
@@ -277,7 +279,8 @@ mod tests {
block_data: collation.proof_of_validity.block_data,
relay_parent_number: 1,
relay_parent_storage_root: Default::default(),
}.encode(),
}
.encode(),
)
.unwrap();
let ret = ValidationResult::decode(&mut &ret_buf[..]).unwrap();
@@ -307,7 +310,16 @@ mod tests {
}
let collator = Collator::new();
let mut second_head = collator.state.lock().unwrap().number_to_head.get(&0).cloned().unwrap().as_ref().clone();
let mut second_head = collator
.state
.lock()
.unwrap()
.number_to_head
.get(&0)
.cloned()
.unwrap()
.as_ref()
.clone();
for _ in 1..20 {
second_head = collator.state.lock().unwrap().advance(second_head.clone()).1;
@@ -16,10 +16,10 @@
//! Collator for the adder test parachain.
use polkadot_cli::{Error, Result};
use polkadot_node_primitives::CollationGenerationConfig;
use polkadot_node_subsystem::messages::{CollationGenerationMessage, CollatorProtocolMessage};
use polkadot_primitives::v1::Id as ParaId;
use polkadot_cli::{Error, Result};
use sc_cli::{Error as SubstrateCliError, Role, SubstrateCli};
use sp_core::hexdisplay::HexDisplay;
use test_parachain_adder_collator::Collator;
@@ -39,16 +39,19 @@ fn main() -> Result<()> {
println!("0x{:?}", HexDisplay::from(&collator.genesis_head()));
Ok::<_, Error>(())
}
},
Some(cli::Subcommand::ExportGenesisWasm(_params)) => {
let collator = Collator::new();
println!("0x{:?}", HexDisplay::from(&collator.validation_code()));
Ok(())
}
},
None => {
let runner = cli.create_runner(&cli.run.base)
.map_err(|e| SubstrateCliError::Application(Box::new(e) as Box::<(dyn 'static + Send + Sync + std::error::Error)>))?;
let runner = cli.create_runner(&cli.run.base).map_err(|e| {
SubstrateCliError::Application(
Box::new(e) as Box<(dyn 'static + Send + Sync + std::error::Error)>
)
})?;
runner.run_node_until_exit(|config| async move {
let role = config.role.clone();
@@ -66,7 +69,8 @@ fn main() -> Result<()> {
None,
None,
polkadot_service::RealOverseerGen,
).map_err(|e| e.to_string())?;
)
.map_err(|e| e.to_string())?;
let mut overseer_handle = full_node
.overseer_handle
.expect("Overseer handle should be initialized for collators");
@@ -76,7 +80,8 @@ fn main() -> Result<()> {
let validation_code_hex =
format!("0x{:?}", HexDisplay::from(&collator.validation_code()));
let para_id = cli.run.parachain_id.map(ParaId::from).unwrap_or(DEFAULT_PARA_ID);
let para_id =
cli.run.parachain_id.map(ParaId::from).unwrap_or(DEFAULT_PARA_ID);
log::info!("Running adder collator for parachain id: {}", para_id);
log::info!("Genesis state: {}", genesis_head_hex);
@@ -84,7 +89,8 @@ fn main() -> Result<()> {
let config = CollationGenerationConfig {
key: collator.collator_key(),
collator: collator.create_collation_function(full_node.task_manager.spawn_handle()),
collator: collator
.create_collation_function(full_node.task_manager.spawn_handle()),
para_id,
};
overseer_handle
@@ -96,10 +102,10 @@ fn main() -> Result<()> {
.await;
Ok(full_node.task_manager)
}
},
}
})
}
},
}?;
Ok(())
}
@@ -22,9 +22,9 @@ const PUPPET_EXE: &str = env!("CARGO_BIN_EXE_adder_collator_puppet_worker");
// If this test is failing, make sure to run all tests with the `real-overseer` feature being enabled.
#[substrate_test_utils::test]
async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor) {
use sp_keyring::AccountKeyring::*;
use futures::join;
use polkadot_primitives::v1::Id as ParaId;
use sp_keyring::AccountKeyring::*;
let mut builder = sc_cli::LoggerBuilder::new("");
builder.with_colors(false);
@@ -35,7 +35,8 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
// start alice
let alice = polkadot_test_service::run_validator_node(
task_executor.clone(),
Alice, || {},
Alice,
|| {},
vec![],
Some(PUPPET_EXE.into()),
);
@@ -53,11 +54,7 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
// register parachain
alice
.register_parachain(
para_id,
collator.validation_code().to_vec(),
collator.genesis_head(),
)
.register_parachain(para_id, collator.validation_code().to_vec(), collator.genesis_head())
.await
.unwrap();
@@ -70,11 +67,13 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
collator.collator_key(),
);
charlie.register_collator(
collator.collator_key(),
para_id,
collator.create_collation_function(charlie.task_manager.spawn_handle()),
).await;
charlie
.register_collator(
collator.collator_key(),
para_id,
collator.create_collation_function(charlie.task_manager.spawn_handle()),
)
.await;
// Wait until the parachain has 4 blocks produced.
collator.wait_for_blocks(4).await;