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
@@ -75,9 +75,9 @@ pub(crate) enum BlockAnnounceValidationResult<H> {
impl<H> BlockAnnounceValidationResult<H> {
fn peer_id(&self) -> &PeerId {
match self {
BlockAnnounceValidationResult::Failure { peer_id, .. } |
BlockAnnounceValidationResult::Process { peer_id, .. } |
BlockAnnounceValidationResult::Skip { peer_id } => peer_id,
BlockAnnounceValidationResult::Failure { peer_id, .. }
| BlockAnnounceValidationResult::Process { peer_id, .. }
| BlockAnnounceValidationResult::Skip { peer_id } => peer_id,
}
}
}
@@ -262,12 +262,13 @@ impl<B: BlockT> BlockAnnounceValidator<B> {
);
},
Entry::Occupied(mut entry) => match entry.get().checked_sub(1) {
Some(value) =>
Some(value) => {
if value == 0 {
entry.remove();
} else {
*entry.get_mut() = value;
},
}
},
None => {
entry.remove();
@@ -400,8 +400,9 @@ where
let body = if get_body {
match self.client.block_body(hash)? {
Some(mut extrinsics) =>
extrinsics.iter_mut().map(|extrinsic| extrinsic.encode()).collect(),
Some(mut extrinsics) => {
extrinsics.iter_mut().map(|extrinsic| extrinsic.encode()).collect()
},
None => {
log::trace!(target: LOG_TARGET, "Missing data for block request.");
break;
@@ -441,9 +442,9 @@ where
indexed_body,
};
let new_total_size = total_size +
block_data.body.iter().map(|ex| ex.len()).sum::<usize>() +
block_data.indexed_body.iter().map(|ex| ex.len()).sum::<usize>();
let new_total_size = total_size
+ block_data.body.iter().map(|ex| ex.len()).sum::<usize>()
+ block_data.indexed_body.iter().map(|ex| ex.len()).sum::<usize>();
// Send at least one block, but make sure to not exceed the limit.
if !blocks.is_empty() && new_total_size > MAX_BODY_BYTES {
+14 -8
View File
@@ -136,23 +136,29 @@ impl<B: BlockT> BlockCollection<B> {
// the range start.
(Some((start, &BlockRangeState::Downloading { ref len, downloading })), _)
if downloading < max_parallel && *start >= first_different =>
(*start..*start + *len, downloading),
{
(*start..*start + *len, downloading)
},
// If there is a gap between ranges requested, download this gap unless the peer
// has common number above the gap start
(Some((start, r)), Some((next_start, _)))
if *start + r.len() < *next_start &&
*start + r.len() >= first_different =>
(*start + r.len()..cmp::min(*next_start, *start + r.len() + count), 0),
if *start + r.len() < *next_start
&& *start + r.len() >= first_different =>
{
(*start + r.len()..cmp::min(*next_start, *start + r.len() + count), 0)
},
// Download `count` blocks after the last range requested unless the peer
// has common number above this new range
(Some((start, r)), None) if *start + r.len() >= first_different =>
(*start + r.len()..*start + r.len() + count, 0),
(Some((start, r)), None) if *start + r.len() >= first_different => {
(*start + r.len()..*start + r.len() + count, 0)
},
// If there are no ranges currently requested, download `count` blocks after
// `common` number
(None, None) => (first_different..first_different + count, 0),
// If the first range starts above `common + 1`, download the gap at the start
(None, Some((start, _))) if *start > first_different =>
(first_different..cmp::min(first_different + count, *start), 0),
(None, Some((start, _))) if *start > first_different => {
(first_different..cmp::min(first_different + count, *start), 0)
},
// Move on to the next range pair
_ => {
prev = next;
+29 -26
View File
@@ -290,8 +290,8 @@ where
where
N: NetworkBackend<B, <B as BlockT>::Hash>,
{
let cache_capacity = (net_config.network_config.default_peers_set.in_peers +
net_config.network_config.default_peers_set.out_peers)
let cache_capacity = (net_config.network_config.default_peers_set.in_peers
+ net_config.network_config.default_peers_set.out_peers)
.max(1);
let important_peers = {
let mut imp_p = HashSet::new();
@@ -328,8 +328,8 @@ where
let default_peers_set_num_full =
net_config.network_config.default_peers_set_num_full as usize;
let default_peers_set_num_light = {
let total = net_config.network_config.default_peers_set.out_peers +
net_config.network_config.default_peers_set.in_peers;
let total = net_config.network_config.default_peers_set.out_peers
+ net_config.network_config.default_peers_set.in_peers;
total.saturating_sub(net_config.network_config.default_peers_set_num_full) as usize
};
@@ -663,10 +663,12 @@ where
}
self.event_streams.push(tx);
},
ToServiceCommand::RequestJustification(hash, number) =>
self.strategy.request_justification(&hash, number),
ToServiceCommand::ClearJustificationRequests =>
self.strategy.clear_justification_requests(),
ToServiceCommand::RequestJustification(hash, number) => {
self.strategy.request_justification(&hash, number)
},
ToServiceCommand::ClearJustificationRequests => {
self.strategy.clear_justification_requests()
},
ToServiceCommand::BlocksProcessed(imported, count, results) => {
self.strategy.on_blocks_processed(imported, count, results);
},
@@ -734,8 +736,9 @@ where
self.peers.iter().map(|(peer_id, peer)| (*peer_id, peer.info)).collect();
let _ = tx.send(peers_info);
},
ToServiceCommand::OnBlockFinalized(hash, header) =>
self.strategy.on_block_finalized(&hash, *header.number()),
ToServiceCommand::OnBlockFinalized(hash, header) => {
self.strategy.on_block_finalized(&hash, *header.number())
},
}
}
@@ -815,9 +818,9 @@ where
log::debug!(target: LOG_TARGET, "{peer_id} disconnected");
}
if !self.default_peers_set_no_slot_connected_peers.remove(&peer_id) &&
info.inbound &&
info.info.roles.is_full()
if !self.default_peers_set_no_slot_connected_peers.remove(&peer_id)
&& info.inbound
&& info.info.roles.is_full()
{
match self.num_in_peers.checked_sub(1) {
Some(value) => {
@@ -918,21 +921,21 @@ where
let no_slot_peer = self.default_peers_set_no_slot_peers.contains(&peer_id);
let this_peer_reserved_slot: usize = if no_slot_peer { 1 } else { 0 };
if handshake.roles.is_full() &&
self.strategy.num_peers() >=
self.default_peers_set_num_full +
self.default_peers_set_no_slot_connected_peers.len() +
this_peer_reserved_slot
if handshake.roles.is_full()
&& self.strategy.num_peers()
>= self.default_peers_set_num_full
+ self.default_peers_set_no_slot_connected_peers.len()
+ this_peer_reserved_slot
{
log::debug!(target: LOG_TARGET, "Too many full nodes, rejecting {peer_id}");
return Err(false);
}
// make sure to accept no more than `--in-peers` many full nodes
if !no_slot_peer &&
handshake.roles.is_full() &&
direction.is_inbound() &&
self.num_in_peers == self.max_in_peers
if !no_slot_peer
&& handshake.roles.is_full()
&& direction.is_inbound()
&& self.num_in_peers == self.max_in_peers
{
log::debug!(target: LOG_TARGET, "All inbound slots have been consumed, rejecting {peer_id}");
return Err(false);
@@ -942,8 +945,8 @@ where
//
// `ChainSync` only accepts full peers whereas `SyncingEngine` accepts both full and light
// peers. Verify that there is a slot in `SyncingEngine` for the inbound light peer
if handshake.roles.is_light() &&
(self.peers.len() - self.strategy.num_peers()) >= self.default_peers_set_num_light
if handshake.roles.is_light()
&& (self.peers.len() - self.strategy.num_peers()) >= self.default_peers_set_num_light
{
log::debug!(target: LOG_TARGET, "Too many light nodes, rejecting {peer_id}");
return Err(false);
@@ -1034,8 +1037,8 @@ where
self.network_service
.disconnect_peer(peer_id, self.block_announce_protocol_name.clone());
},
RequestFailure::Network(OutboundFailure::ConnectionClosed) |
RequestFailure::NotConnected => {
RequestFailure::Network(OutboundFailure::ConnectionClosed)
| RequestFailure::NotConnected => {
self.network_service
.disconnect_peer(peer_id, self.block_announce_protocol_name.clone());
},
@@ -119,12 +119,15 @@ impl NetworkServiceProvider {
while let Some(inner) = rx.next().await {
match inner {
ToServiceCommand::DisconnectPeer(peer, protocol_name) =>
service.disconnect_peer(peer, protocol_name),
ToServiceCommand::ReportPeer(peer, reputation_change) =>
service.report_peer(peer, reputation_change),
ToServiceCommand::StartRequest(peer, protocol, request, tx, connect) =>
service.start_request(peer, protocol, request, None, tx, connect),
ToServiceCommand::DisconnectPeer(peer, protocol_name) => {
service.disconnect_peer(peer, protocol_name)
},
ToServiceCommand::ReportPeer(peer, reputation_change) => {
service.report_peer(peer, reputation_change)
},
ToServiceCommand::StartRequest(peer, protocol, request, tx, connect) => {
service.start_request(peer, protocol, request, None, tx, connect)
},
}
}
}
@@ -441,8 +441,8 @@ where
if is_best {
if known && self.best_queued_number >= number {
self.update_peer_common_number(&peer_id, number);
} else if announce.header.parent_hash() == &self.best_queued_hash ||
known_parent && self.best_queued_number >= number
} else if announce.header.parent_hash() == &self.best_queued_hash
|| known_parent && self.best_queued_number >= number
{
self.update_peer_common_number(&peer_id, number.saturating_sub(One::one()));
}
@@ -727,7 +727,7 @@ where
self.complete_gap_if_target(number);
},
Err(BlockImportError::IncompleteHeader(peer_id)) =>
Err(BlockImportError::IncompleteHeader(peer_id)) => {
if let Some(peer) = peer_id {
warn!(
target: LOG_TARGET,
@@ -736,7 +736,8 @@ where
self.actions
.push(SyncingAction::DropPeer(BadPeer(peer, rep::INCOMPLETE_HEADER)));
self.restart();
},
}
},
Err(BlockImportError::VerificationFailed(peer_id, e)) => {
let extra_message = peer_id
.map_or_else(|| "".into(), |peer| format!(" received from ({peer})"));
@@ -753,14 +754,15 @@ where
self.restart();
},
Err(BlockImportError::BadBlock(peer_id)) =>
Err(BlockImportError::BadBlock(peer_id)) => {
if let Some(peer) = peer_id {
warn!(
target: LOG_TARGET,
"💔 Block {hash:?} received from peer {peer} has been blacklisted",
);
self.actions.push(SyncingAction::DropPeer(BadPeer(peer, rep::BAD_BLOCK)));
},
}
},
Err(BlockImportError::MissingState) => {
// This may happen if the chain we were requesting upon has been discarded
// in the meantime because other chain has been finalized.
@@ -1096,9 +1098,9 @@ where
Ok(req)
},
Ok(BlockStatus::Queued) |
Ok(BlockStatus::InChainWithState) |
Ok(BlockStatus::InChainPruned) => {
Ok(BlockStatus::Queued)
| Ok(BlockStatus::InChainWithState)
| Ok(BlockStatus::InChainPruned) => {
debug!(
target: LOG_TARGET,
"New peer {peer_id} with known best hash {best_hash} ({best_number}).",
@@ -1278,8 +1280,8 @@ where
},
};
if matching_hash.is_some() {
if *start < self.best_queued_number &&
self.best_queued_number <= peer.best_number
if *start < self.best_queued_number
&& self.best_queued_number <= peer.best_number
{
// We've made progress on this chain since the search was started.
// Opportunistically set common number to updated number
@@ -1335,8 +1337,8 @@ where
matching_hash,
peer.common_number,
);
if peer.common_number < peer.best_number &&
peer.best_number < self.best_queued_number
if peer.common_number < peer.best_number
&& peer.best_number < self.best_queued_number
{
trace!(
target: LOG_TARGET,
@@ -1364,9 +1366,9 @@ where
return Ok(());
}
},
PeerSyncState::Available |
PeerSyncState::DownloadingJustification(..) |
PeerSyncState::DownloadingState => Vec::new(),
PeerSyncState::Available
| PeerSyncState::DownloadingJustification(..)
| PeerSyncState::DownloadingState => Vec::new(),
}
} else {
// When request.is_none() this is a block announcement. Just accept blocks.
@@ -1525,14 +1527,17 @@ where
fn required_block_attributes(&self) -> BlockAttributes {
match self.mode {
ChainSyncMode::Full =>
BlockAttributes::HEADER | BlockAttributes::JUSTIFICATION | BlockAttributes::BODY,
ChainSyncMode::LightState { storage_chain_mode: false, .. } =>
BlockAttributes::HEADER | BlockAttributes::JUSTIFICATION | BlockAttributes::BODY,
ChainSyncMode::LightState { storage_chain_mode: true, .. } =>
BlockAttributes::HEADER |
BlockAttributes::JUSTIFICATION |
BlockAttributes::INDEXED_BODY,
ChainSyncMode::Full => {
BlockAttributes::HEADER | BlockAttributes::JUSTIFICATION | BlockAttributes::BODY
},
ChainSyncMode::LightState { storage_chain_mode: false, .. } => {
BlockAttributes::HEADER | BlockAttributes::JUSTIFICATION | BlockAttributes::BODY
},
ChainSyncMode::LightState { storage_chain_mode: true, .. } => {
BlockAttributes::HEADER
| BlockAttributes::JUSTIFICATION
| BlockAttributes::INDEXED_BODY
},
}
}
@@ -1653,11 +1658,11 @@ where
PeerSyncState::Available => {
self.add_peer(peer_id, peer_sync.best_hash, peer_sync.best_number);
},
PeerSyncState::AncestorSearch { .. } |
PeerSyncState::DownloadingNew(_) |
PeerSyncState::DownloadingStale(_) |
PeerSyncState::DownloadingGap(_) |
PeerSyncState::DownloadingState => {
PeerSyncState::AncestorSearch { .. }
| PeerSyncState::DownloadingNew(_)
| PeerSyncState::DownloadingStale(_)
| PeerSyncState::DownloadingGap(_)
| PeerSyncState::DownloadingState => {
// Cancel a request first, as `add_peer` may generate a new request.
self.actions
.push(SyncingAction::CancelRequest { peer_id, key: Self::STRATEGY_KEY });
@@ -1699,8 +1704,8 @@ where
self.best_queued_hash = info.best_hash;
self.best_queued_number = info.best_number;
if self.mode == ChainSyncMode::Full &&
self.client.block_status(info.best_hash)? != BlockStatus::InChainWithState
if self.mode == ChainSyncMode::Full
&& self.client.block_status(info.best_hash)? != BlockStatus::InChainWithState
{
self.import_existing = true;
// Latest state is missing, start with the last finalized state or genesis instead.
@@ -1835,9 +1840,9 @@ where
.peers
.iter_mut()
.filter_map(move |(&id, peer)| {
if !peer.state.is_available() ||
!allowed_requests.contains(&id) ||
!disconnected_peers.is_peer_available(&id)
if !peer.state.is_available()
|| !allowed_requests.contains(&id)
|| !disconnected_peers.is_peer_available(&id)
{
return None;
}
@@ -1847,11 +1852,11 @@ where
// common number is smaller than the last finalized block number, we should do an
// ancestor search to find a better common block. If the queue is full we wait till
// all blocks are imported though.
if best_queued.saturating_sub(peer.common_number) >
MAX_BLOCKS_TO_LOOK_BACKWARDS.into() &&
best_queued < peer.best_number &&
peer.common_number < last_finalized &&
queue_blocks.len() <= MAJOR_SYNC_BLOCKS as usize
if best_queued.saturating_sub(peer.common_number)
> MAX_BLOCKS_TO_LOOK_BACKWARDS.into()
&& best_queued < peer.best_number
&& peer.common_number < last_finalized
&& queue_blocks.len() <= MAJOR_SYNC_BLOCKS as usize
{
trace!(
target: LOG_TARGET,
@@ -1947,8 +1952,8 @@ where
if self.allowed_requests.is_empty() {
return None;
}
if self.state_sync.is_some() &&
self.peers.iter().any(|(_, peer)| peer.state == PeerSyncState::DownloadingState)
if self.state_sync.is_some()
&& self.peers.iter().any(|(_, peer)| peer.state == PeerSyncState::DownloadingState)
{
// Only one pending state request is allowed.
return None;
@@ -1959,9 +1964,9 @@ where
}
for (id, peer) in self.peers.iter_mut() {
if peer.state.is_available() &&
peer.common_number >= sync.target_number() &&
self.disconnected_peers.is_peer_available(&id)
if peer.state.is_available()
&& peer.common_number >= sync.target_number()
&& self.disconnected_peers.is_peer_available(&id)
{
peer.state = PeerSyncState::DownloadingState;
let request = sync.next_request();
@@ -2286,8 +2291,8 @@ fn fork_sync_request<B: BlockT>(
}
// Download the fork only if it is behind or not too far ahead our tip of the chain
// Otherwise it should be downloaded in full sync mode.
if r.number <= best_num ||
(r.number - best_num).saturated_into::<u32>() < max_blocks_per_request as u32
if r.number <= best_num
|| (r.number - best_num).saturated_into::<u32>() < max_blocks_per_request as u32
{
let parent_status = r.parent_hash.as_ref().map_or(BlockStatus::Unknown, check_block);
let count = if parent_status == BlockStatus::Unknown {
@@ -2378,8 +2383,8 @@ pub fn validate_blocks<Block: BlockT>(
return Err(BadPeer(*peer_id, rep::NOT_REQUESTED));
}
if request.fields.contains(BlockAttributes::HEADER) &&
blocks.iter().any(|b| b.header.is_none())
if request.fields.contains(BlockAttributes::HEADER)
&& blocks.iter().any(|b| b.header.is_none())
{
trace!(
target: LOG_TARGET,
@@ -211,9 +211,9 @@ fn restart_doesnt_affect_peers_downloading_finality_data() {
// the justification request should be scheduled to the
// new peer which is at the given block
assert!(sync.justification_requests().iter().any(|(p, r)| {
*p == peer_id3 &&
r.fields == BlockAttributes::JUSTIFICATION &&
r.from == FromBlock::Hash(b1_hash)
*p == peer_id3
&& r.fields == BlockAttributes::JUSTIFICATION
&& r.from == FromBlock::Hash(b1_hash)
}));
assert_eq!(
@@ -47,8 +47,9 @@ use std::{any::Any, collections::HashMap, sync::Arc};
fn chain_sync_mode(sync_mode: SyncMode) -> ChainSyncMode {
match sync_mode {
SyncMode::Full => ChainSyncMode::Full,
SyncMode::LightState { skip_proofs, storage_chain_mode } =>
ChainSyncMode::LightState { skip_proofs, storage_chain_mode },
SyncMode::LightState { skip_proofs, storage_chain_mode } => {
ChainSyncMode::LightState { skip_proofs, storage_chain_mode }
},
SyncMode::Warp => ChainSyncMode::Full,
}
}
@@ -188,7 +189,7 @@ where
response: Box<dyn Any + Send>,
) {
match key {
StateStrategy::<B>::STRATEGY_KEY =>
StateStrategy::<B>::STRATEGY_KEY => {
if let Some(state) = &mut self.state {
let Ok(response) = response.downcast::<Vec<u8>>() else {
warn!(target: LOG_TARGET, "Failed to downcast state response");
@@ -206,8 +207,9 @@ where
or corresponding strategy is not active.",
);
debug_assert!(false);
},
WarpSync::<B, Client>::STRATEGY_KEY =>
}
},
WarpSync::<B, Client>::STRATEGY_KEY => {
if let Some(warp) = &mut self.warp {
warp.on_generic_response(peer_id, protocol_name, response);
} else {
@@ -217,8 +219,9 @@ where
or warp strategy is not active",
);
debug_assert!(false);
},
ChainSync::<B, Client>::STRATEGY_KEY =>
}
},
ChainSync::<B, Client>::STRATEGY_KEY => {
if let Some(chain_sync) = &mut self.chain_sync {
chain_sync.on_generic_response(peer_id, key, protocol_name, response);
} else {
@@ -228,7 +231,8 @@ where
or corresponding strategy is not active.",
);
debug_assert!(false);
},
}
},
key => {
warn!(
target: LOG_TARGET,
@@ -268,9 +272,9 @@ where
}
fn is_major_syncing(&self) -> bool {
self.warp.is_some() ||
self.state.is_some() ||
match self.chain_sync {
self.warp.is_some()
|| self.state.is_some()
|| match self.chain_sync {
Some(ref s) => s.status().state.is_major_syncing(),
None => unreachable!("At least one syncing strategy is active; qed"),
}
@@ -322,9 +322,9 @@ impl<B: BlockT> StateStrategy<B> {
// Find a random peer that is synced as much as peer majority and is above
// `min_best_number`.
for (peer_id, peer) in self.peers.iter_mut() {
if peer.state.is_available() &&
peer.best_number >= threshold &&
self.disconnected_peers.is_peer_available(peer_id)
if peer.state.is_available()
&& peer.best_number >= threshold
&& self.disconnected_peers.is_peer_available(peer_id)
{
peer.state = new_state;
return Some(*peer_id);
@@ -261,8 +261,9 @@ where
}
let phase = match warp_sync_config {
WarpSyncConfig::WithProvider(warp_sync_provider) =>
Phase::WaitingForPeers { warp_sync_provider },
WarpSyncConfig::WithProvider(warp_sync_provider) => {
Phase::WaitingForPeers { warp_sync_provider }
},
WarpSyncConfig::WithTarget(target_header) => Phase::TargetBlock(target_header),
};
@@ -558,9 +559,9 @@ where
// Find a random peer that is synced as much as peer majority and is above
// `min_best_number`.
for (peer_id, peer) in self.peers.iter_mut() {
if peer.state.is_available() &&
peer.best_number >= threshold &&
self.disconnected_peers.is_peer_available(peer_id)
if peer.state.is_available()
&& peer.best_number >= threshold
&& self.disconnected_peers.is_peer_available(peer_id)
{
peer.state = new_state;
return Some(*peer_id);
@@ -632,9 +633,9 @@ where
peer_id,
BlockRequest::<B> {
id: 0,
fields: BlockAttributes::HEADER |
BlockAttributes::BODY |
BlockAttributes::JUSTIFICATION,
fields: BlockAttributes::HEADER
| BlockAttributes::BODY
| BlockAttributes::JUSTIFICATION,
from: FromBlock::Hash(target_hash),
direction: Direction::Ascending,
max: Some(1),