style: Migrate to stable-only rustfmt configuration

- Remove nightly-only features from .rustfmt.toml and vendor/ss58-registry/rustfmt.toml
- Removed features: imports_granularity, wrap_comments, comment_width,
  reorder_impl_items, spaces_around_ranges, binop_separator,
  match_arm_blocks, trailing_semicolon, trailing_comma
- Format all 898 affected files with stable rustfmt
- Ensures long-term reliability without nightly toolchain dependency
This commit is contained in:
2025-12-22 17:12:58 +03:00
parent 65b7f5e640
commit 4c8f281051
898 changed files with 8671 additions and 6432 deletions
@@ -230,8 +230,8 @@ where
F: Fn(&H, &H) -> Result<bool, E>,
{
let filter = |node_hash: &H, node_num: &N, _: &PendingChange<H, N>| {
if number >= *node_num &&
(is_descendent_of(node_hash, &hash).unwrap_or_default() || *node_hash == hash)
if number >= *node_num
&& (is_descendent_of(node_hash, &hash).unwrap_or_default() || *node_hash == hash)
{
// Continue the search in this subtree.
FilterAction::KeepNode
@@ -291,8 +291,9 @@ where
}
let earliest = match (forced, standard) {
(Some(forced), Some(standard)) =>
Some(if forced.1 < standard.1 { forced } else { standard }),
(Some(forced), Some(standard)) => {
Some(if forced.1 < standard.1 { forced } else { standard })
},
(Some(forced), None) => Some(forced),
(None, Some(standard)) => Some(standard),
(None, None) => None,
@@ -476,8 +477,8 @@ where
// check if there's any pending standard change that we depend on
for (_, _, standard_change) in self.pending_standard_changes.roots() {
if standard_change.effective_number() <= median_last_finalized &&
is_descendent_of(&standard_change.canon_hash, &change.canon_hash)?
if standard_change.effective_number() <= median_last_finalized
&& is_descendent_of(&standard_change.canon_hash, &change.canon_hash)?
{
log::info!(target: LOG_TARGET,
"Not applying authority set change forced at block #{:?}, due to pending standard change at block #{:?}",
@@ -566,8 +567,8 @@ where
// we will keep all forced changes for any later blocks and that are a
// descendent of the finalized block (i.e. they are part of this branch).
for change in pending_forced_changes {
if change.effective_number() > finalized_number &&
is_descendent_of(&finalized_hash, &change.canon_hash)?
if change.effective_number() > finalized_number
&& is_descendent_of(&finalized_hash, &change.canon_hash)?
{
self.pending_forced_changes.push(change)
}
@@ -382,8 +382,12 @@ where
});
}
},
Some(other) =>
return Err(ClientError::Backend(format!("Unsupported GRANDPA DB version: {:?}", other))),
Some(other) => {
return Err(ClientError::Backend(format!(
"Unsupported GRANDPA DB version: {:?}",
other
)))
},
}
// genesis.
@@ -199,12 +199,13 @@ impl<N: Ord> View<N> {
// the one we're aware of.
match self.last_commit {
None => Consider::Accept,
Some(ref num) =>
Some(ref num) => {
if num < &number {
Consider::Accept
} else {
Consider::RejectPast
},
}
},
}
}
}
@@ -549,17 +550,17 @@ impl<N: Ord> Peers<N> {
) -> Result<Option<&View<N>>, Misbehavior> {
let Some(peer) = self.inner.get_mut(who) else { return Ok(None) };
let invalid_change = peer.view.set_id > update.set_id ||
peer.view.round > update.round && peer.view.set_id == update.set_id ||
peer.view.last_commit.as_ref() > Some(&update.commit_finalized_height);
let invalid_change = peer.view.set_id > update.set_id
|| peer.view.round > update.round && peer.view.set_id == update.set_id
|| peer.view.last_commit.as_ref() > Some(&update.commit_finalized_height);
if invalid_change {
return Err(Misbehavior::InvalidViewChange);
}
let now = Instant::now();
let duplicate_packet = (update.set_id, update.round, Some(&update.commit_finalized_height)) ==
(peer.view.set_id, peer.view.round, peer.view.last_commit.as_ref());
let duplicate_packet = (update.set_id, update.round, Some(&update.commit_finalized_height))
== (peer.view.set_id, peer.view.round, peer.view.last_commit.as_ref());
if duplicate_packet {
if let Some(last_update) = peer.view.last_update {
@@ -820,8 +821,8 @@ impl<Block: BlockT> Inner<Block> {
ref mut x @ None => x.get_or_insert(LocalView::new(set_id, Round(1))),
Some(ref mut v) => {
if v.set_id == set_id {
let diff_authorities = self.authorities.iter().collect::<HashSet<_>>() !=
authorities.iter().collect::<HashSet<_>>();
let diff_authorities = self.authorities.iter().collect::<HashSet<_>>()
!= authorities.iter().collect::<HashSet<_>>();
if diff_authorities {
debug!(
@@ -902,10 +903,12 @@ impl<Block: BlockT> Inner<Block> {
) -> Action<Block::Hash> {
match self.consider_vote(full.round, full.set_id) {
Consider::RejectFuture => return Action::Discard(Misbehavior::FutureMessage.cost()),
Consider::RejectOutOfScope =>
return Action::Discard(Misbehavior::OutOfScopeMessage.cost()),
Consider::RejectPast =>
return Action::Discard(self.cost_past_rejection(who, full.round, full.set_id)),
Consider::RejectOutOfScope => {
return Action::Discard(Misbehavior::OutOfScopeMessage.cost())
},
Consider::RejectPast => {
return Action::Discard(self.cost_past_rejection(who, full.round, full.set_id))
},
Consider::Accept => {},
}
@@ -955,15 +958,17 @@ impl<Block: BlockT> Inner<Block> {
match self.consider_global(full.set_id, full.message.target_number) {
Consider::RejectFuture => return Action::Discard(Misbehavior::FutureMessage.cost()),
Consider::RejectPast =>
return Action::Discard(self.cost_past_rejection(who, full.round, full.set_id)),
Consider::RejectOutOfScope =>
return Action::Discard(Misbehavior::OutOfScopeMessage.cost()),
Consider::RejectPast => {
return Action::Discard(self.cost_past_rejection(who, full.round, full.set_id))
},
Consider::RejectOutOfScope => {
return Action::Discard(Misbehavior::OutOfScopeMessage.cost())
},
Consider::Accept => {},
}
if full.message.precommits.len() != full.message.auth_data.len() ||
full.message.precommits.is_empty()
if full.message.precommits.len() != full.message.auth_data.len()
|| full.message.precommits.is_empty()
{
debug!(target: LOG_TARGET, "Malformed compact commit");
telemetry!(
@@ -1046,8 +1051,8 @@ impl<Block: BlockT> Inner<Block> {
// race where the peer sent us the request before it observed that
// we had transitioned to a new set. In this case we charge a lower
// cost.
if request.set_id.0.saturating_add(1) == local_view.set_id.0 &&
local_view.round.0.saturating_sub(CATCH_UP_THRESHOLD) == 0
if request.set_id.0.saturating_add(1) == local_view.set_id.0
&& local_view.round.0.saturating_sub(CATCH_UP_THRESHOLD) == 0
{
return (None, Action::Discard(cost::HONEST_OUT_OF_SCOPE_CATCH_UP));
}
@@ -1057,8 +1062,9 @@ impl<Block: BlockT> Inner<Block> {
match self.peers.peer(who) {
None => return (None, Action::Discard(Misbehavior::OutOfScopeMessage.cost())),
Some(peer) if peer.view.round >= request.round =>
return (None, Action::Discard(Misbehavior::OutOfScopeMessage.cost())),
Some(peer) if peer.view.round >= request.round => {
return (None, Action::Discard(Misbehavior::OutOfScopeMessage.cost()))
},
_ => {},
}
@@ -1131,9 +1137,9 @@ impl<Block: BlockT> Inner<Block> {
// won't be able to reply since they don't follow the full GRANDPA
// protocol and therefore might not have the vote data available.
if let (Some(peer), Some(local_view)) = (self.peers.peer(who), &self.local_view) {
if self.catch_up_config.request_allowed(peer) &&
peer.view.set_id == local_view.set_id &&
peer.view.round.0.saturating_sub(CATCH_UP_THRESHOLD) > local_view.round.0
if self.catch_up_config.request_allowed(peer)
&& peer.view.set_id == local_view.set_id
&& peer.view.round.0.saturating_sub(CATCH_UP_THRESHOLD) > local_view.round.0
{
// send catch up request if allowed
let round = peer.view.round.0 - 1; // peer.view.round is > 0
@@ -1166,8 +1172,9 @@ impl<Block: BlockT> Inner<Block> {
let update_res = self.peers.update_peer_state(who, update);
let (cost_benefit, topics) = match update_res {
Ok(view) =>
(benefit::NEIGHBOR_MESSAGE, view.map(|view| neighbor_topics::<Block>(view))),
Ok(view) => {
(benefit::NEIGHBOR_MESSAGE, view.map(|view| neighbor_topics::<Block>(view)))
},
Err(misbehavior) => (misbehavior.cost(), None),
};
@@ -1249,8 +1256,8 @@ impl<Block: BlockT> Inner<Block> {
if round_elapsed < round_duration.mul_f32(PROPAGATION_SOME) {
self.peers.first_stage_peers.contains(who)
} else if round_elapsed < round_duration.mul_f32(PROPAGATION_ALL) {
self.peers.first_stage_peers.contains(who) ||
self.peers.second_stage_peers.contains(who)
self.peers.first_stage_peers.contains(who)
|| self.peers.second_stage_peers.contains(who)
} else {
self.peers.peer(who).map(|info| !info.roles.is_light()).unwrap_or(false)
}
@@ -1278,9 +1285,9 @@ impl<Block: BlockT> Inner<Block> {
};
if round_elapsed < round_duration.mul_f32(PROPAGATION_ALL) {
self.peers.first_stage_peers.contains(who) ||
self.peers.second_stage_peers.contains(who) ||
self.peers.lucky_light_peers.contains(who)
self.peers.first_stage_peers.contains(who)
|| self.peers.second_stage_peers.contains(who)
|| self.peers.lucky_light_peers.contains(who)
} else {
true
}
@@ -1611,9 +1618,9 @@ impl<Block: BlockT> pezsc_network_gossip::Validator<Block> for GossipValidator<B
// set the peer is in and if the commit is better than the
// last received by peer, additionally we make sure to only
// broadcast our best commit.
peer.view.consider_global(set_id, full.message.target_number) ==
Consider::Accept && Some(&full.message.target_number) ==
local_view.last_commit_height()
peer.view.consider_global(set_id, full.message.target_number)
== Consider::Accept
&& Some(&full.message.target_number) == local_view.last_commit_height()
},
Ok(GossipMessage::Neighbor(_)) => false,
Ok(GossipMessage::CatchUpRequest(_)) => false,
@@ -1646,8 +1653,11 @@ impl<Block: BlockT> pezsc_network_gossip::Validator<Block> for GossipValidator<B
Some((number, round, set_id)) =>
// we expire any commit message that doesn't target the same block
// as our best commit or isn't from the same round and set id
!(full.message.target_number == number &&
full.round == round && full.set_id == set_id),
{
!(full.message.target_number == number
&& full.round == round
&& full.set_id == set_id)
},
None => true,
},
Ok(_) => true,
@@ -2323,8 +2333,8 @@ mod tests {
let test = |rounds_elapsed, peers| {
// rewind n round durations
val.inner.write().local_view.as_mut().unwrap().round_start = Instant::now() -
Duration::from_millis(
val.inner.write().local_view.as_mut().unwrap().round_start = Instant::now()
- Duration::from_millis(
(round_duration.as_millis() as f32 * rounds_elapsed) as u64,
);
@@ -505,10 +505,11 @@ impl<B: BlockT, N: Network<B>, S: Syncing<B>> Future for NetworkBridge<B, N, S>
Poll::Ready(Some((to, packet))) => {
self.gossip_engine.lock().send_message(to, packet.encode());
},
Poll::Ready(None) =>
Poll::Ready(None) => {
return Poll::Ready(Err(Error::Network(
"Neighbor packet worker stream closed.".into(),
))),
)))
},
Poll::Pending => break,
}
}
@@ -518,17 +519,19 @@ impl<B: BlockT, N: Network<B>, S: Syncing<B>> Future for NetworkBridge<B, N, S>
Poll::Ready(Some(PeerReport { who, cost_benefit })) => {
self.gossip_engine.lock().report(who, cost_benefit);
},
Poll::Ready(None) =>
Poll::Ready(None) => {
return Poll::Ready(Err(Error::Network(
"Gossip validator report stream closed.".into(),
))),
)))
},
Poll::Pending => break,
}
}
match self.gossip_engine.lock().poll_unpin(cx) {
Poll::Ready(()) =>
return Poll::Ready(Err(Error::Network("Gossip engine future finished.".into()))),
Poll::Ready(()) => {
return Poll::Ready(Err(Error::Network("Gossip engine future finished.".into())))
},
Poll::Pending => {},
}
@@ -666,10 +669,12 @@ fn incoming_global<B: BlockT>(
})
.filter_map(move |(notification, msg)| {
future::ready(match msg {
GossipMessage::Commit(msg) =>
process_commit(msg, notification, &gossip_engine, &gossip_validator, &voters),
GossipMessage::CatchUp(msg) =>
process_catch_up(msg, notification, &gossip_engine, &gossip_validator, &voters),
GossipMessage::Commit(msg) => {
process_commit(msg, notification, &gossip_engine, &gossip_validator, &voters)
},
GossipMessage::CatchUp(msg) => {
process_catch_up(msg, notification, &gossip_engine, &gossip_validator, &voters)
},
_ => {
debug!(target: LOG_TARGET, "Skipping unknown message type");
None
@@ -270,10 +270,11 @@ impl Tester {
futures::future::poll_fn(move |cx| loop {
match Stream::poll_next(Pin::new(&mut s.as_mut().unwrap().events), cx) {
Poll::Ready(None) => panic!("concluded early"),
Poll::Ready(Some(item)) =>
Poll::Ready(Some(item)) => {
if pred(item) {
return Poll::Ready(s.take().unwrap());
},
}
},
Poll::Pending => return Poll::Pending,
}
})
@@ -622,8 +623,9 @@ fn bad_commit_leads_to_report() {
let fut = future::join(send_message, handle_commit)
.then(move |(tester, ())| {
tester.filter_network_events(move |event| match event {
Event::Report(who, cost_benefit) =>
who == id && cost_benefit == super::cost::INVALID_COMMIT,
Event::Report(who, cost_benefit) => {
who == id && cost_benefit == super::cost::INVALID_COMMIT
},
_ => false,
})
})
@@ -277,8 +277,8 @@ impl<Header: HeaderT> HasVoted<Header> {
pub fn propose(&self) -> Option<&PrimaryPropose<Header>> {
match self {
HasVoted::Yes(_, Vote::Propose(propose)) => Some(propose),
HasVoted::Yes(_, Vote::Prevote(propose, _)) |
HasVoted::Yes(_, Vote::Precommit(propose, _, _)) => propose.as_ref(),
HasVoted::Yes(_, Vote::Prevote(propose, _))
| HasVoted::Yes(_, Vote::Precommit(propose, _, _)) => propose.as_ref(),
_ => None,
}
}
@@ -286,8 +286,8 @@ impl<Header: HeaderT> HasVoted<Header> {
/// Returns the prevote we should vote with (if any.)
pub fn prevote(&self) -> Option<&Prevote<Header>> {
match self {
HasVoted::Yes(_, Vote::Prevote(_, prevote)) |
HasVoted::Yes(_, Vote::Precommit(_, prevote, _)) => Some(prevote),
HasVoted::Yes(_, Vote::Prevote(_, prevote))
| HasVoted::Yes(_, Vote::Precommit(_, prevote, _)) => Some(prevote),
_ => None,
}
}
@@ -528,8 +528,9 @@ where
// find the hash of the latest block in the current set
let current_set_latest_hash = match next_change {
Some((_, n)) if n.is_zero() =>
return Err(Error::Safety("Authority set change signalled at genesis.".to_string())),
Some((_, n)) if n.is_zero() => {
return Err(Error::Safety("Authority set change signalled at genesis.".to_string()))
},
// the next set starts at `n` so the current one lasts until `n - 1`. if
// `n` is later than the best block, then the current set is still live
// at best block.
@@ -733,12 +734,13 @@ where
let local_id = local_authority_id(&self.voters, self.config.keystore.as_ref());
let has_voted = match self.voter_set_state.has_voted(round) {
HasVoted::Yes(id, vote) =>
HasVoted::Yes(id, vote) => {
if local_id.as_ref().map(|k| k == &id).unwrap_or(false) {
HasVoted::Yes(id, vote)
} else {
HasVoted::No
},
}
},
HasVoted::No => HasVoted::No,
};
@@ -1253,10 +1255,10 @@ where
let is_descendent_of = is_descendent_of(&*client, None);
if target_header.number() > best_header.number() ||
target_header.number() == best_header.number() &&
target_header.hash() != best_header.hash() ||
!is_descendent_of(&target_header.hash(), &best_header.hash())?
if target_header.number() > best_header.number()
|| target_header.number() == best_header.number()
&& target_header.hash() != best_header.hash()
|| !is_descendent_of(&target_header.hash(), &best_header.hash())?
{
debug!(
target: LOG_TARGET,
@@ -111,9 +111,9 @@ where
self.authority_set.inner().pending_changes().cloned().collect();
for pending_change in pending_changes {
if pending_change.delay_kind == DelayKind::Finalized &&
pending_change.effective_number() > chain_info.finalized_number &&
pending_change.effective_number() <= chain_info.best_number
if pending_change.delay_kind == DelayKind::Finalized
&& pending_change.effective_number() > chain_info.finalized_number
&& pending_change.effective_number() <= chain_info.best_number
{
let effective_block_hash = if !pending_change.delay.is_zero() {
self.select_chain
@@ -685,7 +685,7 @@ where
);
}
},
None =>
None => {
if needs_justification {
debug!(
target: LOG_TARGET,
@@ -694,7 +694,8 @@ where
);
imported_aux.needs_justification = true;
},
}
},
}
Ok(ImportResult::Imported(imported_aux))
@@ -799,8 +800,9 @@ where
let justification = match justification {
Err(e) => {
return match e {
pezsp_blockchain::Error::OutdatedJustification =>
Err(ConsensusError::OutdatedJustification),
pezsp_blockchain::Error::OutdatedJustification => {
Err(ConsensusError::OutdatedJustification)
},
_ => Err(ConsensusError::ClientImport(e.to_string())),
};
},
@@ -832,7 +834,7 @@ where
// send the command to the voter
let _ = self.send_voter_commands.unbounded_send(command);
},
Err(CommandOrError::Error(e)) =>
Err(CommandOrError::Error(e)) => {
return Err(match e {
Error::Grandpa(error) => ConsensusError::ClientImport(error.to_string()),
Error::Network(error) => ConsensusError::ClientImport(error),
@@ -842,7 +844,8 @@ where
Error::Signing(error) => ConsensusError::ClientImport(error),
Error::Timer(error) => ConsensusError::ClientImport(error.to_string()),
Error::RuntimeApi(error) => ConsensusError::ClientImport(error.to_string()),
}),
})
},
Ok(_) => {
assert!(
!enacts_change,
@@ -214,12 +214,14 @@ impl<Block: BlockT> GrandpaJustification<Block> {
&mut buf,
);
match signature_result {
pezsp_consensus_grandpa::SignatureResult::Invalid =>
pezsp_consensus_grandpa::SignatureResult::Invalid => {
return Err(ClientError::BadJustification(
"invalid signature for precommit in grandpa justification".to_string(),
)),
pezsp_consensus_grandpa::SignatureResult::OutdatedSet =>
return Err(ClientError::OutdatedJustification),
))
},
pezsp_consensus_grandpa::SignatureResult::OutdatedSet => {
return Err(ClientError::OutdatedJustification)
},
pezsp_consensus_grandpa::SignatureResult::Valid => {},
}
@@ -236,10 +238,11 @@ impl<Block: BlockT> GrandpaJustification<Block> {
visited_hashes.insert(hash);
}
},
_ =>
_ => {
return Err(ClientError::BadJustification(
"invalid precommit ancestry proof in grandpa justification".to_string(),
)),
))
},
}
}
@@ -1231,8 +1231,8 @@ async fn voter_persists_its_votes() {
Pin::new(&mut *round_tx.lock())
.start_send(finality_grandpa::Message::Prevote(prevote))
.unwrap();
} else if state.compare_exchange(1, 2, Ordering::SeqCst, Ordering::SeqCst).unwrap() ==
1
} else if state.compare_exchange(1, 2, Ordering::SeqCst, Ordering::SeqCst).unwrap()
== 1
{
// the next message we receive should be our own prevote
let prevote = match signed.message {
@@ -1246,8 +1246,8 @@ async fn voter_persists_its_votes() {
// after alice restarts it should send its previous prevote
// therefore we won't ever receive it again since it will be a
// known message on the gossip layer
} else if state.compare_exchange(2, 3, Ordering::SeqCst, Ordering::SeqCst).unwrap() ==
2
} else if state.compare_exchange(2, 3, Ordering::SeqCst, Ordering::SeqCst).unwrap()
== 2
{
// we then receive a precommit from alice for block 15
// even though we casted a prevote for block 30
@@ -940,8 +940,8 @@ mod tests {
let block_sync_requests = block_sync_requester.requests.lock();
// we request blocks targeted by the precommits that aren't imported
if block_sync_requests.contains(&(h2.hash(), *h2.number())) &&
block_sync_requests.contains(&(h3.hash(), *h3.number()))
if block_sync_requests.contains(&(h2.hash(), *h2.number()))
&& block_sync_requests.contains(&(h3.hash(), *h3.number()))
{
return Poll::Ready(());
}
@@ -236,8 +236,8 @@ where
.await
.filter(|(_, restricted_number)| {
// NOTE: we can only restrict votes within the interval [base, target)
restricted_number >= base.number() &&
restricted_number < restricted_target.number()
restricted_number >= base.number()
&& restricted_number < restricted_target.number()
})
.and_then(|(hash, _)| backend.header(hash).ok())
.and_then(std::convert::identity)