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:
@@ -53,8 +53,8 @@ pub(super) fn calculate_primary_threshold(
|
||||
|
||||
let c = c.0 as f64 / c.1 as f64;
|
||||
|
||||
let theta = authorities[authority_index].1 as f64 /
|
||||
authorities.iter().map(|(_, weight)| weight).sum::<u64>() as f64;
|
||||
let theta = authorities[authority_index].1 as f64
|
||||
/ authorities.iter().map(|(_, weight)| weight).sum::<u64>() as f64;
|
||||
|
||||
assert!(theta > 0.0, "authority with weight 0.");
|
||||
|
||||
@@ -204,8 +204,8 @@ pub fn claim_slot_using_keys(
|
||||
keys: &[(AuthorityId, usize)],
|
||||
) -> Option<(PreDigest, AuthorityId)> {
|
||||
claim_primary_slot(slot, epoch, epoch.config.c, keystore, keys).or_else(|| {
|
||||
if epoch.config.allowed_slots.is_secondary_plain_slots_allowed() ||
|
||||
epoch.config.allowed_slots.is_secondary_vrf_slots_allowed()
|
||||
if epoch.config.allowed_slots.is_secondary_plain_slots_allowed()
|
||||
|| epoch.config.allowed_slots.is_secondary_vrf_slots_allowed()
|
||||
{
|
||||
claim_secondary_slot(
|
||||
slot,
|
||||
|
||||
@@ -62,21 +62,25 @@ pub fn load_epoch_changes<Block: BlockT, B: AuxStore>(
|
||||
let version = load_decode::<_, u32>(backend, BABE_EPOCH_CHANGES_VERSION)?;
|
||||
|
||||
let maybe_epoch_changes = match version {
|
||||
None =>
|
||||
None => {
|
||||
load_decode::<_, EpochChangesV0For<Block, EpochV0>>(backend, BABE_EPOCH_CHANGES_KEY)?
|
||||
.map(|v0| v0.migrate().map(|_, _, epoch| epoch.migrate(config))),
|
||||
Some(1) =>
|
||||
.map(|v0| v0.migrate().map(|_, _, epoch| epoch.migrate(config)))
|
||||
},
|
||||
Some(1) => {
|
||||
load_decode::<_, EpochChangesV1For<Block, EpochV0>>(backend, BABE_EPOCH_CHANGES_KEY)?
|
||||
.map(|v1| v1.migrate().map(|_, _, epoch| epoch.migrate(config))),
|
||||
.map(|v1| v1.migrate().map(|_, _, epoch| epoch.migrate(config)))
|
||||
},
|
||||
Some(2) => {
|
||||
// v2 still uses `EpochChanges` v1 format but with a different `Epoch` type.
|
||||
load_decode::<_, EpochChangesV1For<Block, Epoch>>(backend, BABE_EPOCH_CHANGES_KEY)?
|
||||
.map(|v2| v2.migrate())
|
||||
},
|
||||
Some(BABE_EPOCH_CHANGES_CURRENT_VERSION) =>
|
||||
load_decode::<_, EpochChangesFor<Block, Epoch>>(backend, BABE_EPOCH_CHANGES_KEY)?,
|
||||
Some(other) =>
|
||||
return Err(ClientError::Backend(format!("Unsupported BABE DB version: {:?}", other))),
|
||||
Some(BABE_EPOCH_CHANGES_CURRENT_VERSION) => {
|
||||
load_decode::<_, EpochChangesFor<Block, Epoch>>(backend, BABE_EPOCH_CHANGES_KEY)?
|
||||
},
|
||||
Some(other) => {
|
||||
return Err(ClientError::Backend(format!("Unsupported BABE DB version: {:?}", other)))
|
||||
},
|
||||
};
|
||||
|
||||
let epoch_changes =
|
||||
@@ -199,8 +203,8 @@ mod test {
|
||||
.tree()
|
||||
.iter()
|
||||
.map(|(_, _, epoch)| epoch.clone())
|
||||
.collect::<Vec<_>>() ==
|
||||
vec![PersistedEpochHeader::Regular(EpochHeader {
|
||||
.collect::<Vec<_>>()
|
||||
== vec![PersistedEpochHeader::Regular(EpochHeader {
|
||||
start_slot: 0.into(),
|
||||
end_slot: 100.into(),
|
||||
})],
|
||||
|
||||
@@ -401,10 +401,11 @@ where
|
||||
}
|
||||
},
|
||||
Some(2) => runtime_api.configuration(at_hash)?,
|
||||
_ =>
|
||||
_ => {
|
||||
return Err(pezsp_blockchain::Error::VersionInvalid(
|
||||
"Unsupported or invalid BabeApi version".to_string(),
|
||||
)),
|
||||
))
|
||||
},
|
||||
};
|
||||
Ok(config)
|
||||
}
|
||||
@@ -791,13 +792,14 @@ where
|
||||
let sinks = &mut self.slot_notification_sinks.lock();
|
||||
sinks.retain_mut(|sink| match sink.try_send((slot, epoch_descriptor.clone())) {
|
||||
Ok(()) => true,
|
||||
Err(e) =>
|
||||
Err(e) => {
|
||||
if e.is_full() {
|
||||
warn!(target: LOG_TARGET, "Trying to notify a slot but the channel is full");
|
||||
true
|
||||
} else {
|
||||
false
|
||||
},
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -927,8 +929,9 @@ pub fn find_next_epoch_digest<B: BlockT>(
|
||||
trace!(target: LOG_TARGET, "Checking log {:?}, looking for epoch change digest.", log);
|
||||
let log = log.try_to::<ConsensusLog>(OpaqueDigestItemId::Consensus(&BABE_ENGINE_ID));
|
||||
match (log, epoch_digest.is_some()) {
|
||||
(Some(ConsensusLog::NextEpochData(_)), true) =>
|
||||
return Err(babe_err(Error::MultipleEpochChangeDigests)),
|
||||
(Some(ConsensusLog::NextEpochData(_)), true) => {
|
||||
return Err(babe_err(Error::MultipleEpochChangeDigests))
|
||||
},
|
||||
(Some(ConsensusLog::NextEpochData(epoch)), false) => epoch_digest = Some(epoch),
|
||||
_ => trace!(target: LOG_TARGET, "Ignoring digest not meant for us"),
|
||||
}
|
||||
@@ -946,8 +949,9 @@ fn find_next_config_digest<B: BlockT>(
|
||||
trace!(target: LOG_TARGET, "Checking log {:?}, looking for epoch change digest.", log);
|
||||
let log = log.try_to::<ConsensusLog>(OpaqueDigestItemId::Consensus(&BABE_ENGINE_ID));
|
||||
match (log, config_digest.is_some()) {
|
||||
(Some(ConsensusLog::NextConfigData(_)), true) =>
|
||||
return Err(babe_err(Error::MultipleConfigChangeDigests)),
|
||||
(Some(ConsensusLog::NextConfigData(_)), true) => {
|
||||
return Err(babe_err(Error::MultipleConfigChangeDigests))
|
||||
},
|
||||
(Some(ConsensusLog::NextConfigData(config)), false) => config_digest = Some(config),
|
||||
_ => trace!(target: LOG_TARGET, "Ignoring digest not meant for us"),
|
||||
}
|
||||
@@ -1094,8 +1098,8 @@ fn is_state_sync_or_gap_sync_import<B: BlockT>(
|
||||
) -> bool {
|
||||
let number = *block.header.number();
|
||||
let info = client.info();
|
||||
info.block_gap.map_or(false, |gap| gap.start <= number && number <= gap.end) ||
|
||||
block.with_state()
|
||||
info.block_gap.map_or(false, |gap| gap.start <= number && number <= gap.end)
|
||||
|| block.with_state()
|
||||
}
|
||||
|
||||
/// A block-import handler for BABE.
|
||||
@@ -1200,11 +1204,12 @@ where
|
||||
let import_result = self.inner.import_block(block).await;
|
||||
let aux = match import_result {
|
||||
Ok(ImportResult::Imported(aux)) => aux,
|
||||
Ok(r) =>
|
||||
Ok(r) => {
|
||||
return Err(ConsensusError::ClientImport(format!(
|
||||
"Unexpected import result: {:?}",
|
||||
r
|
||||
))),
|
||||
)))
|
||||
},
|
||||
Err(r) => return Err(r.into()),
|
||||
};
|
||||
|
||||
@@ -1271,8 +1276,9 @@ where
|
||||
.get(babe_pre_digest.authority_index() as usize)
|
||||
{
|
||||
Some(author) => author.0.clone(),
|
||||
None =>
|
||||
return Err(ConsensusError::Other(Error::<Block>::SlotAuthorNotFound.into())),
|
||||
None => {
|
||||
return Err(ConsensusError::Other(Error::<Block>::SlotAuthorNotFound.into()))
|
||||
},
|
||||
}
|
||||
};
|
||||
if let Err(err) = self
|
||||
@@ -1321,12 +1327,14 @@ where
|
||||
.await
|
||||
.map_err(|e| {
|
||||
ConsensusError::Other(Box::new(match e {
|
||||
CheckInherentsError::CreateInherentData(e) =>
|
||||
Error::<Block>::CreateInherents(e),
|
||||
CheckInherentsError::CreateInherentData(e) => {
|
||||
Error::<Block>::CreateInherents(e)
|
||||
},
|
||||
CheckInherentsError::Client(e) => Error::RuntimeApi(e),
|
||||
CheckInherentsError::CheckInherents(e) => Error::CheckInherents(e),
|
||||
CheckInherentsError::CheckInherentsUnknownError(id) =>
|
||||
Error::CheckInherentsUnhandled(id),
|
||||
CheckInherentsError::CheckInherentsUnknownError(id) => {
|
||||
Error::CheckInherentsUnhandled(id)
|
||||
},
|
||||
}))
|
||||
})?;
|
||||
let (_, inner_body) = new_block.deconstruct();
|
||||
@@ -1463,8 +1471,8 @@ where
|
||||
// Skip babe logic if block already in chain or importing blocks during initial sync,
|
||||
// otherwise the check for epoch changes will error because trying to re-import an
|
||||
// epoch change or because of missing epoch data in the tree, respectively.
|
||||
if info.block_gap.map_or(false, |gap| gap.start <= number && number <= gap.end) ||
|
||||
block_status == BlockStatus::InChain
|
||||
if info.block_gap.map_or(false, |gap| gap.start <= number && number <= gap.end)
|
||||
|| block_status == BlockStatus::InChain
|
||||
{
|
||||
// When re-importing existing block strip away intermediates.
|
||||
// In case of initial sync intermediates should not be present...
|
||||
@@ -1552,18 +1560,21 @@ where
|
||||
match (first_in_epoch, next_epoch_digest.is_some(), next_config_digest.is_some()) {
|
||||
(true, true, _) => {},
|
||||
(false, false, false) => {},
|
||||
(false, false, true) =>
|
||||
(false, false, true) => {
|
||||
return Err(ConsensusError::ClientImport(
|
||||
babe_err(Error::<Block>::UnexpectedConfigChange).into(),
|
||||
)),
|
||||
(true, false, _) =>
|
||||
))
|
||||
},
|
||||
(true, false, _) => {
|
||||
return Err(ConsensusError::ClientImport(
|
||||
babe_err(Error::<Block>::ExpectedEpochChange(hash, slot)).into(),
|
||||
)),
|
||||
(false, true, _) =>
|
||||
))
|
||||
},
|
||||
(false, true, _) => {
|
||||
return Err(ConsensusError::ClientImport(
|
||||
babe_err(Error::<Block>::UnexpectedEpochChange).into(),
|
||||
)),
|
||||
))
|
||||
},
|
||||
}
|
||||
|
||||
if let Some(next_epoch_descriptor) = next_epoch_digest {
|
||||
@@ -1953,8 +1964,8 @@ where
|
||||
let mut hash = leaf;
|
||||
loop {
|
||||
let meta = client.header_metadata(hash)?;
|
||||
if meta.number <= revert_up_to_number ||
|
||||
!weight_keys.insert(aux_schema::block_weight_key(hash))
|
||||
if meta.number <= revert_up_to_number
|
||||
|| !weight_keys.insert(aux_schema::block_weight_key(hash))
|
||||
{
|
||||
// We've reached the revert point or an already processed branch, stop here.
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user