mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 08:27:55 +00:00
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:
@@ -17,9 +17,9 @@
|
||||
//! Runtimes implementing the v1 runtime API are recommended to forward directly to these
|
||||
//! functions.
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use sp_std::collections::btree_map::BTreeMap;
|
||||
use sp_runtime::traits::One;
|
||||
use crate::{
|
||||
configuration, dmp, hrmp, inclusion, initializer, paras, scheduler, session_info, shared,
|
||||
};
|
||||
use primitives::v1::{
|
||||
AuthorityDiscoveryId, CandidateEvent, CommittedCandidateReceipt, CoreIndex, CoreOccupied,
|
||||
CoreState, GroupIndex, GroupRotationInfo, Id as ParaId, InboundDownwardMessage,
|
||||
@@ -27,8 +27,8 @@ use primitives::v1::{
|
||||
ScheduledCore, SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash, ValidatorId,
|
||||
ValidatorIndex,
|
||||
};
|
||||
use crate::{initializer, inclusion, scheduler, configuration, paras, session_info, dmp, hrmp, shared};
|
||||
|
||||
use sp_runtime::traits::One;
|
||||
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
|
||||
|
||||
/// Implementation for the `validators` function of the runtime API.
|
||||
pub fn validators<T: initializer::Config>() -> Vec<ValidatorId> {
|
||||
@@ -36,10 +36,8 @@ pub fn validators<T: initializer::Config>() -> Vec<ValidatorId> {
|
||||
}
|
||||
|
||||
/// Implementation for the `validator_groups` function of the runtime API.
|
||||
pub fn validator_groups<T: initializer::Config>() -> (
|
||||
Vec<Vec<ValidatorIndex>>,
|
||||
GroupRotationInfo<T::BlockNumber>,
|
||||
) {
|
||||
pub fn validator_groups<T: initializer::Config>(
|
||||
) -> (Vec<Vec<ValidatorIndex>>, GroupRotationInfo<T::BlockNumber>) {
|
||||
let now = <frame_system::Pallet<T>>::block_number() + One::one();
|
||||
|
||||
let groups = <scheduler::Pallet<T>>::validator_groups();
|
||||
@@ -80,10 +78,13 @@ pub fn availability_cores<T: initializer::Config>() -> Vec<CoreState<T::Hash, T:
|
||||
}
|
||||
};
|
||||
|
||||
let group_responsible_for = |backed_in_number, core_index| {
|
||||
match <scheduler::Pallet<T>>::group_assigned_to_core(core_index, backed_in_number) {
|
||||
let group_responsible_for =
|
||||
|backed_in_number, core_index| match <scheduler::Pallet<T>>::group_assigned_to_core(
|
||||
core_index,
|
||||
backed_in_number,
|
||||
) {
|
||||
Some(g) => g,
|
||||
None => {
|
||||
None => {
|
||||
log::warn!(
|
||||
target: "runtime::polkadot-api::v1",
|
||||
"Could not determine the group responsible for core extracted \
|
||||
@@ -91,23 +92,24 @@ pub fn availability_cores<T: initializer::Config>() -> Vec<CoreState<T::Hash, T:
|
||||
);
|
||||
|
||||
GroupIndex(0)
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
let mut core_states: Vec<_> = cores.into_iter().enumerate().map(|(i, core)| match core {
|
||||
Some(occupied) => {
|
||||
CoreState::Occupied(match occupied {
|
||||
let mut core_states: Vec<_> = cores
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(i, core)| match core {
|
||||
Some(occupied) => CoreState::Occupied(match occupied {
|
||||
CoreOccupied::Parachain => {
|
||||
let para_id = parachains[i];
|
||||
let pending_availability = <inclusion::Pallet<T>>
|
||||
::pending_availability(para_id)
|
||||
.expect("Occupied core always has pending availability; qed");
|
||||
let pending_availability =
|
||||
<inclusion::Pallet<T>>::pending_availability(para_id)
|
||||
.expect("Occupied core always has pending availability; qed");
|
||||
|
||||
let backed_in_number = pending_availability.backed_in_number().clone();
|
||||
OccupiedCore {
|
||||
next_up_on_available: <scheduler::Pallet<T>>::next_up_on_available(
|
||||
CoreIndex(i as u32)
|
||||
CoreIndex(i as u32),
|
||||
),
|
||||
occupied_since: backed_in_number,
|
||||
time_out_at: time_out_at(
|
||||
@@ -115,7 +117,7 @@ pub fn availability_cores<T: initializer::Config>() -> Vec<CoreState<T::Hash, T:
|
||||
config.chain_availability_period,
|
||||
),
|
||||
next_up_on_time_out: <scheduler::Pallet<T>>::next_up_on_time_out(
|
||||
CoreIndex(i as u32)
|
||||
CoreIndex(i as u32),
|
||||
),
|
||||
availability: pending_availability.availability_votes().clone(),
|
||||
group_responsible: group_responsible_for(
|
||||
@@ -125,17 +127,17 @@ pub fn availability_cores<T: initializer::Config>() -> Vec<CoreState<T::Hash, T:
|
||||
candidate_hash: pending_availability.candidate_hash(),
|
||||
candidate_descriptor: pending_availability.candidate_descriptor().clone(),
|
||||
}
|
||||
}
|
||||
},
|
||||
CoreOccupied::Parathread(p) => {
|
||||
let para_id = p.claim.0;
|
||||
let pending_availability = <inclusion::Pallet<T>>
|
||||
::pending_availability(para_id)
|
||||
.expect("Occupied core always has pending availability; qed");
|
||||
let pending_availability =
|
||||
<inclusion::Pallet<T>>::pending_availability(para_id)
|
||||
.expect("Occupied core always has pending availability; qed");
|
||||
|
||||
let backed_in_number = pending_availability.backed_in_number().clone();
|
||||
OccupiedCore {
|
||||
next_up_on_available: <scheduler::Pallet<T>>::next_up_on_available(
|
||||
CoreIndex(i as u32)
|
||||
CoreIndex(i as u32),
|
||||
),
|
||||
occupied_since: backed_in_number,
|
||||
time_out_at: time_out_at(
|
||||
@@ -143,7 +145,7 @@ pub fn availability_cores<T: initializer::Config>() -> Vec<CoreState<T::Hash, T:
|
||||
config.thread_availability_period,
|
||||
),
|
||||
next_up_on_time_out: <scheduler::Pallet<T>>::next_up_on_time_out(
|
||||
CoreIndex(i as u32)
|
||||
CoreIndex(i as u32),
|
||||
),
|
||||
availability: pending_availability.availability_votes().clone(),
|
||||
group_responsible: group_responsible_for(
|
||||
@@ -153,11 +155,11 @@ pub fn availability_cores<T: initializer::Config>() -> Vec<CoreState<T::Hash, T:
|
||||
candidate_hash: pending_availability.candidate_hash(),
|
||||
candidate_descriptor: pending_availability.candidate_descriptor().clone(),
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
None => CoreState::Free,
|
||||
}).collect();
|
||||
},
|
||||
}),
|
||||
None => CoreState::Free,
|
||||
})
|
||||
.collect();
|
||||
|
||||
// This will overwrite only `Free` cores if the scheduler module is working as intended.
|
||||
for scheduled in <scheduler::Pallet<T>>::scheduled() {
|
||||
@@ -174,7 +176,8 @@ fn with_assumption<Config, T, F>(
|
||||
para_id: ParaId,
|
||||
assumption: OccupiedCoreAssumption,
|
||||
build: F,
|
||||
) -> Option<T> where
|
||||
) -> Option<T>
|
||||
where
|
||||
Config: inclusion::Config,
|
||||
F: FnOnce() -> Option<T>,
|
||||
{
|
||||
@@ -182,17 +185,15 @@ fn with_assumption<Config, T, F>(
|
||||
OccupiedCoreAssumption::Included => {
|
||||
<inclusion::Pallet<Config>>::force_enact(para_id);
|
||||
build()
|
||||
}
|
||||
OccupiedCoreAssumption::TimedOut => {
|
||||
build()
|
||||
}
|
||||
},
|
||||
OccupiedCoreAssumption::TimedOut => build(),
|
||||
OccupiedCoreAssumption::Free => {
|
||||
if <inclusion::Pallet<Config>>::pending_availability(para_id).is_some() {
|
||||
None
|
||||
} else {
|
||||
build()
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +238,8 @@ pub fn session_index_for_child<T: initializer::Config>() -> SessionIndex {
|
||||
/// Implementation for the `AuthorityDiscoveryApi::authorities()` function of the runtime API.
|
||||
/// It is a heavy call, but currently only used for authority discovery, so it is fine.
|
||||
/// Gets next, current and some historical authority ids using `session_info` module.
|
||||
pub fn relevant_authority_ids<T: initializer::Config + pallet_authority_discovery::Config>() -> Vec<AuthorityDiscoveryId> {
|
||||
pub fn relevant_authority_ids<T: initializer::Config + pallet_authority_discovery::Config>(
|
||||
) -> Vec<AuthorityDiscoveryId> {
|
||||
let current_session_index = session_index_for_child::<T>();
|
||||
let earliest_stored_session = <session_info::Pallet<T>>::earliest_stored_session();
|
||||
|
||||
@@ -267,17 +269,13 @@ pub fn validation_code<T: initializer::Config>(
|
||||
para_id: ParaId,
|
||||
assumption: OccupiedCoreAssumption,
|
||||
) -> Option<ValidationCode> {
|
||||
with_assumption::<T, _, _>(
|
||||
para_id,
|
||||
assumption,
|
||||
|| <paras::Pallet<T>>::current_code(¶_id),
|
||||
)
|
||||
with_assumption::<T, _, _>(para_id, assumption, || <paras::Pallet<T>>::current_code(¶_id))
|
||||
}
|
||||
|
||||
/// Implementation for the `candidate_pending_availability` function of the runtime API.
|
||||
pub fn candidate_pending_availability<T: initializer::Config>(para_id: ParaId)
|
||||
-> Option<CommittedCandidateReceipt<T::Hash>>
|
||||
{
|
||||
pub fn candidate_pending_availability<T: initializer::Config>(
|
||||
para_id: ParaId,
|
||||
) -> Option<CommittedCandidateReceipt<T::Hash>> {
|
||||
<inclusion::Pallet<T>>::candidate_pending_availability(para_id)
|
||||
}
|
||||
|
||||
@@ -291,17 +289,17 @@ where
|
||||
{
|
||||
use inclusion::Event as RawEvent;
|
||||
|
||||
<frame_system::Pallet<T>>::events().into_iter()
|
||||
<frame_system::Pallet<T>>::events()
|
||||
.into_iter()
|
||||
.filter_map(|record| extract_event(record.event))
|
||||
.map(|event| match event {
|
||||
RawEvent::<T>::CandidateBacked(c, h, core, group)
|
||||
=> CandidateEvent::CandidateBacked(c, h, core, group),
|
||||
RawEvent::<T>::CandidateIncluded(c, h, core, group)
|
||||
=> CandidateEvent::CandidateIncluded(c, h, core, group),
|
||||
RawEvent::<T>::CandidateTimedOut(c, h, core)
|
||||
=> CandidateEvent::CandidateTimedOut(c, h, core),
|
||||
RawEvent::<T>::__Ignore(_, _)
|
||||
=> unreachable!("__Ignore cannot be used"),
|
||||
RawEvent::<T>::CandidateBacked(c, h, core, group) =>
|
||||
CandidateEvent::CandidateBacked(c, h, core, group),
|
||||
RawEvent::<T>::CandidateIncluded(c, h, core, group) =>
|
||||
CandidateEvent::CandidateIncluded(c, h, core, group),
|
||||
RawEvent::<T>::CandidateTimedOut(c, h, core) =>
|
||||
CandidateEvent::CandidateTimedOut(c, h, core),
|
||||
RawEvent::<T>::__Ignore(_, _) => unreachable!("__Ignore cannot be used"),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user