ci: add quick-check with rustfmt (#615)

* ci: add quick-check with clippy and rustfmt

* chore: rustfmt round

* chore: set the same rustfmt config than substrate

* chore: fix formatting

* cI: remove clippy

* ci: switch to nightly for the checks

* ci: fix toolchains and naming

* ci: Limit the check to formatting

* chore: fix formatting

* Update .rustfmt.toml

* Update .rustfmt.toml

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Chevdor
2021-09-16 16:57:52 +02:00
committed by GitHub
parent 035a576008
commit 1dd000a011
98 changed files with 1244 additions and 1872 deletions
+1 -3
View File
@@ -65,9 +65,7 @@ impl<B: BlockT> ParachainConsensus<B> for Box<dyn ParachainConsensus<B> + Send +
relay_parent: PHash,
validation_data: &PersistedValidationData,
) -> Option<ParachainCandidate<B>> {
(*self)
.produce_candidate(parent, relay_parent, validation_data)
.await
(*self).produce_candidate(parent, relay_parent, validation_data).await
}
}
@@ -75,7 +75,7 @@ where
h
} else {
tracing::debug!(target: "cumulus-consensus", "Stopping following finalized head.");
return;
return
};
let header = match Block::Header::decode(&mut &finalized_head[..]) {
@@ -86,8 +86,8 @@ where
error = ?err,
"Could not decode parachain header while following finalized heads.",
);
continue;
}
continue
},
};
let hash = header.hash();
@@ -140,12 +140,8 @@ pub async fn run_parachain_consensus<P, R, Block, B>(
R: RelaychainClient,
B: Backend<Block>,
{
let follow_new_best = follow_new_best(
para_id,
parachain.clone(),
relay_chain.clone(),
announce_block,
);
let follow_new_best =
follow_new_best(para_id, parachain.clone(), relay_chain.clone(), announce_block);
let follow_finalized_head = follow_finalized_head(para_id, parachain, relay_chain);
select! {
_ = follow_new_best.fuse() => {},
@@ -242,12 +238,12 @@ async fn handle_new_block_imported<Block, P>(
};
let unset_hash = if notification.header.number() < unset_best_header.number() {
return;
return
} else if notification.header.number() == unset_best_header.number() {
let unset_hash = unset_best_header.hash();
if unset_hash != notification.hash {
return;
return
} else {
unset_hash
}
@@ -263,7 +259,7 @@ async fn handle_new_block_imported<Block, P>(
.expect("We checked above that the value is set; qed");
import_block_as_new_best(unset_hash, unset_best_header, parachain).await;
}
},
state => tracing::debug!(
target: "cumulus-consensus",
?unset_best_header,
@@ -292,8 +288,8 @@ async fn handle_new_best_parachain_head<Block, P>(
error = ?err,
"Could not decode Parachain header while following best heads.",
);
return;
}
return
},
};
let hash = parachain_head.hash();
@@ -311,14 +307,14 @@ async fn handle_new_best_parachain_head<Block, P>(
unset_best_header.take();
import_block_as_new_best(hash, parachain_head, parachain).await;
}
},
Ok(BlockStatus::InChainPruned) => {
tracing::error!(
target: "cumulus-collator",
block_hash = ?hash,
"Trying to set pruned block as new best!",
);
}
},
Ok(BlockStatus::Unknown) => {
*unset_best_header = Some(parachain_head);
@@ -327,7 +323,7 @@ async fn handle_new_best_parachain_head<Block, P>(
block_hash = ?hash,
"Parachain block not yet imported, waiting for import to enact as best block.",
);
}
},
Err(e) => {
tracing::error!(
target: "cumulus-collator",
@@ -335,8 +331,8 @@ async fn handle_new_best_parachain_head<Block, P>(
error = ?e,
"Failed to get block status of block.",
);
}
_ => {}
},
_ => {},
}
}
}
@@ -356,7 +352,7 @@ where
"Skipping importing block as new best block, because there already exists a \
best block with an higher number",
);
return;
return
}
// Make it the new best block
@@ -364,10 +360,7 @@ where
block_import_params.fork_choice = Some(ForkChoiceStrategy::Custom(true));
block_import_params.import_existing = true;
if let Err(err) = (&*parachain)
.import_block(block_import_params, Default::default())
.await
{
if let Err(err) = (&*parachain).import_block(block_import_params, Default::default()).await {
tracing::warn!(
target: "cumulus-consensus",
block_hash = ?hash,
@@ -392,10 +385,7 @@ where
self.import_notification_stream()
.filter_map(move |n| {
future::ready(if n.is_new_best {
relay_chain
.parachain_head_at(&BlockId::hash(n.hash), para_id)
.ok()
.flatten()
relay_chain.parachain_head_at(&BlockId::hash(n.hash), para_id).ok().flatten()
} else {
None
})
@@ -409,10 +399,7 @@ where
self.finality_notification_stream()
.filter_map(move |n| {
future::ready(
relay_chain
.parachain_head_at(&BlockId::hash(n.hash), para_id)
.ok()
.flatten(),
relay_chain.parachain_head_at(&BlockId::hash(n.hash), para_id).ok().flatten(),
)
})
.boxed()
+18 -60
View File
@@ -62,9 +62,7 @@ struct Relaychain {
impl Relaychain {
fn new() -> Self {
Self {
inner: Arc::new(Mutex::new(RelaychainInner::new())),
}
Self { inner: Arc::new(Mutex::new(RelaychainInner::new())) }
}
}
@@ -125,24 +123,17 @@ fn follow_new_best_works() {
let block = build_and_import_block(client.clone(), false);
let relay_chain = Relaychain::new();
let new_best_heads_sender = relay_chain
.inner
.lock()
.unwrap()
.new_best_heads_sender
.clone();
let new_best_heads_sender = relay_chain.inner.lock().unwrap().new_best_heads_sender.clone();
let consensus =
run_parachain_consensus(100.into(), client.clone(), relay_chain, Arc::new(|_, _| {}));
let work = async move {
new_best_heads_sender
.unbounded_send(block.header().clone())
.unwrap();
new_best_heads_sender.unbounded_send(block.header().clone()).unwrap();
loop {
Delay::new(Duration::from_millis(100)).await;
if block.hash() == client.usage_info().chain.best_hash {
break;
break
}
}
};
@@ -166,24 +157,17 @@ fn follow_finalized_works() {
let block = build_and_import_block(client.clone(), false);
let relay_chain = Relaychain::new();
let finalized_sender = relay_chain
.inner
.lock()
.unwrap()
.finalized_heads_sender
.clone();
let finalized_sender = relay_chain.inner.lock().unwrap().finalized_heads_sender.clone();
let consensus =
run_parachain_consensus(100.into(), client.clone(), relay_chain, Arc::new(|_, _| {}));
let work = async move {
finalized_sender
.unbounded_send(block.header().clone())
.unwrap();
finalized_sender.unbounded_send(block.header().clone()).unwrap();
loop {
Delay::new(Duration::from_millis(100)).await;
if block.hash() == client.usage_info().chain.finalized_hash {
break;
break
}
}
};
@@ -214,32 +198,23 @@ fn follow_finalized_does_not_stop_on_unknown_block() {
};
let relay_chain = Relaychain::new();
let finalized_sender = relay_chain
.inner
.lock()
.unwrap()
.finalized_heads_sender
.clone();
let finalized_sender = relay_chain.inner.lock().unwrap().finalized_heads_sender.clone();
let consensus =
run_parachain_consensus(100.into(), client.clone(), relay_chain, Arc::new(|_, _| {}));
let work = async move {
for _ in 0..3usize {
finalized_sender
.unbounded_send(unknown_block.header().clone())
.unwrap();
finalized_sender.unbounded_send(unknown_block.header().clone()).unwrap();
Delay::new(Duration::from_millis(100)).await;
}
finalized_sender
.unbounded_send(block.header().clone())
.unwrap();
finalized_sender.unbounded_send(block.header().clone()).unwrap();
loop {
Delay::new(Duration::from_millis(100)).await;
if block.hash() == client.usage_info().chain.finalized_hash {
break;
break
}
}
};
@@ -273,32 +248,23 @@ fn follow_new_best_sets_best_after_it_is_imported() {
};
let relay_chain = Relaychain::new();
let new_best_heads_sender = relay_chain
.inner
.lock()
.unwrap()
.new_best_heads_sender
.clone();
let new_best_heads_sender = relay_chain.inner.lock().unwrap().new_best_heads_sender.clone();
let consensus =
run_parachain_consensus(100.into(), client.clone(), relay_chain, Arc::new(|_, _| {}));
let work = async move {
new_best_heads_sender
.unbounded_send(block.header().clone())
.unwrap();
new_best_heads_sender.unbounded_send(block.header().clone()).unwrap();
loop {
Delay::new(Duration::from_millis(100)).await;
if block.hash() == client.usage_info().chain.best_hash {
break;
break
}
}
// Announce the unknown block
new_best_heads_sender
.unbounded_send(unknown_block.header().clone())
.unwrap();
new_best_heads_sender.unbounded_send(unknown_block.header().clone()).unwrap();
// Do some iterations. As this is a local task executor, only one task can run at a time.
// Meaning that it should already have processed the unknown block.
@@ -313,15 +279,12 @@ fn follow_new_best_sets_best_after_it_is_imported() {
block_import_params.body = Some(body);
// Now import the unkown block to make it "known"
client
.import_block(block_import_params, Default::default())
.await
.unwrap();
client.import_block(block_import_params, Default::default()).await.unwrap();
loop {
Delay::new(Duration::from_millis(100)).await;
if unknown_block.hash() == client.usage_info().chain.best_hash {
break;
break
}
}
};
@@ -362,12 +325,7 @@ fn do_not_set_best_block_to_older_block() {
assert_eq!(NUM_BLOCKS as u32, client.usage_info().chain.best_number);
let relay_chain = Relaychain::new();
let new_best_heads_sender = relay_chain
.inner
.lock()
.unwrap()
.new_best_heads_sender
.clone();
let new_best_heads_sender = relay_chain.inner.lock().unwrap().new_best_heads_sender.clone();
let consensus =
run_parachain_consensus(100.into(), client.clone(), relay_chain, Arc::new(|_, _| {}));