mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +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:
@@ -25,53 +25,48 @@
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use polkadot_node_subsystem::{
|
||||
overseer,
|
||||
errors::RuntimeApiError,
|
||||
errors::{RuntimeApiError, SubsystemError},
|
||||
messages::{
|
||||
AllMessages,
|
||||
RuntimeApiMessage,
|
||||
RuntimeApiRequest,
|
||||
RuntimeApiSender,
|
||||
BoundToRelayParent,
|
||||
AllMessages, BoundToRelayParent, RuntimeApiMessage, RuntimeApiRequest, RuntimeApiSender,
|
||||
},
|
||||
ActiveLeavesUpdate, OverseerSignal,
|
||||
overseer, ActiveLeavesUpdate, FromOverseer, OverseerSignal, SpawnedSubsystem, SubsystemContext,
|
||||
SubsystemSender,
|
||||
errors::{
|
||||
SubsystemError,
|
||||
},
|
||||
SubsystemContext,
|
||||
SpawnedSubsystem,
|
||||
FromOverseer,
|
||||
};
|
||||
|
||||
pub use overseer::{
|
||||
Subsystem,
|
||||
TimeoutExt,
|
||||
gen::OverseerError,
|
||||
gen::Timeout,
|
||||
gen::{OverseerError, Timeout},
|
||||
Subsystem, TimeoutExt,
|
||||
};
|
||||
|
||||
pub use polkadot_node_metrics::{
|
||||
Metronome,
|
||||
metrics,
|
||||
};
|
||||
pub use polkadot_node_metrics::{metrics, Metronome};
|
||||
|
||||
use polkadot_node_jaeger as jaeger;
|
||||
use futures::{channel::{mpsc, oneshot}, prelude::*, select, stream::{Stream, SelectAll}};
|
||||
use futures::{
|
||||
channel::{mpsc, oneshot},
|
||||
prelude::*,
|
||||
select,
|
||||
stream::{SelectAll, Stream},
|
||||
};
|
||||
use parity_scale_codec::Encode;
|
||||
use pin_project::pin_project;
|
||||
use polkadot_node_jaeger as jaeger;
|
||||
use polkadot_primitives::v1::{
|
||||
CandidateEvent, CommittedCandidateReceipt, CoreState, EncodeAs, PersistedValidationData,
|
||||
GroupRotationInfo, Hash, Id as ParaId, OccupiedCoreAssumption,
|
||||
SessionIndex, Signed, SigningContext, ValidationCode, ValidatorId, ValidatorIndex, SessionInfo,
|
||||
AuthorityDiscoveryId, GroupIndex,
|
||||
AuthorityDiscoveryId, CandidateEvent, CommittedCandidateReceipt, CoreState, EncodeAs,
|
||||
GroupIndex, GroupRotationInfo, Hash, Id as ParaId, OccupiedCoreAssumption,
|
||||
PersistedValidationData, SessionIndex, SessionInfo, Signed, SigningContext, ValidationCode,
|
||||
ValidatorId, ValidatorIndex,
|
||||
};
|
||||
use sp_core::{traits::SpawnNamed, Public};
|
||||
use sp_application_crypto::AppKey;
|
||||
use sp_keystore::{CryptoStore, SyncCryptoStorePtr, Error as KeystoreError};
|
||||
use sp_core::{traits::SpawnNamed, Public};
|
||||
use sp_keystore::{CryptoStore, Error as KeystoreError, SyncCryptoStorePtr};
|
||||
use std::{
|
||||
collections::{HashMap, hash_map::Entry}, convert::TryFrom, marker::Unpin, pin::Pin, task::{Poll, Context},
|
||||
time::Duration, fmt, sync::Arc,
|
||||
collections::{hash_map::Entry, HashMap},
|
||||
convert::TryFrom,
|
||||
fmt,
|
||||
marker::Unpin,
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
task::{Context, Poll},
|
||||
time::Duration,
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
@@ -80,22 +75,17 @@ pub use polkadot_node_network_protocol::MIN_GOSSIP_PEERS;
|
||||
|
||||
pub use determine_new_blocks::determine_new_blocks;
|
||||
/// Error classification.
|
||||
pub use error_handling::{Fault, unwrap_non_fatal};
|
||||
pub use error_handling::{unwrap_non_fatal, Fault};
|
||||
|
||||
/// These reexports are required so that external crates can use the `delegated_subsystem` macro properly.
|
||||
pub mod reexports {
|
||||
pub use polkadot_overseer::gen::{
|
||||
SpawnNamed,
|
||||
SpawnedSubsystem,
|
||||
Subsystem,
|
||||
SubsystemContext,
|
||||
};
|
||||
pub use polkadot_overseer::gen::{SpawnNamed, SpawnedSubsystem, Subsystem, SubsystemContext};
|
||||
}
|
||||
|
||||
/// Convenient and efficient runtime info access.
|
||||
pub mod runtime;
|
||||
/// A rolling session window cache.
|
||||
pub mod rolling_session_window;
|
||||
/// Convenient and efficient runtime info access.
|
||||
pub mod runtime;
|
||||
|
||||
mod determine_new_blocks;
|
||||
mod error_handling;
|
||||
@@ -158,7 +148,9 @@ where
|
||||
{
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
sender.send_message(RuntimeApiMessage::Request(parent, request_builder(tx)).into()).await;
|
||||
sender
|
||||
.send_message(RuntimeApiMessage::Request(parent, request_builder(tx)).into())
|
||||
.await;
|
||||
|
||||
rx
|
||||
}
|
||||
@@ -225,39 +217,48 @@ specialize_requests! {
|
||||
}
|
||||
|
||||
/// From the given set of validators, find the first key we can sign with, if any.
|
||||
pub async fn signing_key(validators: &[ValidatorId], keystore: &SyncCryptoStorePtr)
|
||||
-> Option<ValidatorId>
|
||||
{
|
||||
pub async fn signing_key(
|
||||
validators: &[ValidatorId],
|
||||
keystore: &SyncCryptoStorePtr,
|
||||
) -> Option<ValidatorId> {
|
||||
signing_key_and_index(validators, keystore).await.map(|(k, _)| k)
|
||||
}
|
||||
|
||||
/// From the given set of validators, find the first key we can sign with, if any, and return it
|
||||
/// along with the validator index.
|
||||
pub async fn signing_key_and_index(validators: &[ValidatorId], keystore: &SyncCryptoStorePtr)
|
||||
-> Option<(ValidatorId, ValidatorIndex)>
|
||||
{
|
||||
pub async fn signing_key_and_index(
|
||||
validators: &[ValidatorId],
|
||||
keystore: &SyncCryptoStorePtr,
|
||||
) -> Option<(ValidatorId, ValidatorIndex)> {
|
||||
for (i, v) in validators.iter().enumerate() {
|
||||
if CryptoStore::has_keys(&**keystore, &[(v.to_raw_vec(), ValidatorId::ID)]).await {
|
||||
return Some((v.clone(), ValidatorIndex(i as _)));
|
||||
return Some((v.clone(), ValidatorIndex(i as _)))
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Find the validator group the given validator index belongs to.
|
||||
pub fn find_validator_group(groups: &[Vec<ValidatorIndex>], index: ValidatorIndex)
|
||||
-> Option<GroupIndex>
|
||||
{
|
||||
groups.iter().enumerate().find_map(|(i, g)| if g.contains(&index) {
|
||||
Some(GroupIndex(i as _))
|
||||
} else {
|
||||
None
|
||||
pub fn find_validator_group(
|
||||
groups: &[Vec<ValidatorIndex>],
|
||||
index: ValidatorIndex,
|
||||
) -> Option<GroupIndex> {
|
||||
groups.iter().enumerate().find_map(|(i, g)| {
|
||||
if g.contains(&index) {
|
||||
Some(GroupIndex(i as _))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Choose a random subset of `min` elements.
|
||||
/// But always include `is_priority` elements.
|
||||
pub fn choose_random_subset<T, F: FnMut(&T) -> bool>(is_priority: F, mut v: Vec<T>, min: usize) -> Vec<T> {
|
||||
pub fn choose_random_subset<T, F: FnMut(&T) -> bool>(
|
||||
is_priority: F,
|
||||
mut v: Vec<T>,
|
||||
min: usize,
|
||||
) -> Vec<T> {
|
||||
use rand::seq::SliceRandom as _;
|
||||
|
||||
// partition the elements into priority first
|
||||
@@ -266,7 +267,7 @@ pub fn choose_random_subset<T, F: FnMut(&T) -> bool>(is_priority: F, mut v: Vec<
|
||||
|
||||
if i >= min || v.len() <= i {
|
||||
v.truncate(i);
|
||||
return v;
|
||||
return v
|
||||
}
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
@@ -300,8 +301,7 @@ impl Validator {
|
||||
parent: Hash,
|
||||
keystore: SyncCryptoStorePtr,
|
||||
sender: &mut impl SubsystemSender,
|
||||
) -> Result<Self, Error>
|
||||
{
|
||||
) -> Result<Self, Error> {
|
||||
// Note: request_validators and request_session_index_for_child do not and cannot
|
||||
// run concurrently: they both have a mutable handle to the same sender.
|
||||
// However, each of them returns a oneshot::Receiver, and those are resolved concurrently.
|
||||
@@ -310,10 +310,7 @@ impl Validator {
|
||||
request_session_index_for_child(parent, sender).await,
|
||||
)?;
|
||||
|
||||
let signing_context = SigningContext {
|
||||
session_index: session_index?,
|
||||
parent_hash: parent,
|
||||
};
|
||||
let signing_context = SigningContext { session_index: session_index?, parent_hash: parent };
|
||||
|
||||
let validators = validators?;
|
||||
|
||||
@@ -328,15 +325,10 @@ impl Validator {
|
||||
signing_context: SigningContext,
|
||||
keystore: SyncCryptoStorePtr,
|
||||
) -> Result<Self, Error> {
|
||||
let (key, index) = signing_key_and_index(validators, &keystore)
|
||||
.await
|
||||
.ok_or(Error::NotAValidator)?;
|
||||
let (key, index) =
|
||||
signing_key_and_index(validators, &keystore).await.ok_or(Error::NotAValidator)?;
|
||||
|
||||
Ok(Validator {
|
||||
signing_context,
|
||||
key,
|
||||
index,
|
||||
})
|
||||
Ok(Validator { signing_context, key, index })
|
||||
}
|
||||
|
||||
/// Get this validator's id.
|
||||
@@ -403,10 +395,7 @@ pub struct JobSender<S: SubsystemSender> {
|
||||
// which `#[derive(Clone)]` requires.
|
||||
impl<S: SubsystemSender> Clone for JobSender<S> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
sender: self.sender.clone(),
|
||||
from_job: self.from_job.clone(),
|
||||
}
|
||||
Self { sender: self.sender.clone(), from_job: self.from_job.clone() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,13 +413,13 @@ impl<S: SubsystemSender> JobSender<S> {
|
||||
/// Send multiple direct messages to other `Subsystem`s, routed based on message type.
|
||||
pub async fn send_messages<T, M>(&mut self, msgs: T)
|
||||
where
|
||||
T: IntoIterator<Item = M> + Send, T::IntoIter: Send,
|
||||
T: IntoIterator<Item = M> + Send,
|
||||
T::IntoIter: Send,
|
||||
M: Into<AllMessages>,
|
||||
{
|
||||
self.sender.send_messages(msgs.into_iter().map(|m| m.into())).await
|
||||
}
|
||||
|
||||
|
||||
/// Send a message onto the unbounded queue of some other `Subsystem`, routed based on message
|
||||
/// type.
|
||||
///
|
||||
@@ -446,7 +435,6 @@ impl<S: SubsystemSender> JobSender<S> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<S, M> overseer::SubsystemSender<M> for JobSender<S>
|
||||
where
|
||||
@@ -458,7 +446,9 @@ where
|
||||
}
|
||||
|
||||
async fn send_messages<T>(&mut self, msgs: T)
|
||||
where T: IntoIterator<Item = M> + Send, T::IntoIter: Send
|
||||
where
|
||||
T: IntoIterator<Item = M> + Send,
|
||||
T::IntoIter: Send,
|
||||
{
|
||||
self.sender.send_messages(msgs.into_iter().map(|m| m.into())).await
|
||||
}
|
||||
@@ -547,11 +537,7 @@ where
|
||||
{
|
||||
/// Create a new Jobs manager which handles spawning appropriate jobs.
|
||||
pub fn new(spawner: Spawner) -> Self {
|
||||
Self {
|
||||
spawner,
|
||||
running: HashMap::new(),
|
||||
outgoing_msgs: SelectAll::new(),
|
||||
}
|
||||
Self { spawner, running: HashMap::new(), outgoing_msgs: SelectAll::new() }
|
||||
}
|
||||
|
||||
/// Spawn a new job for this `parent_hash`, with whatever args are appropriate.
|
||||
@@ -562,10 +548,9 @@ where
|
||||
run_args: Job::RunArgs,
|
||||
metrics: Job::Metrics,
|
||||
sender: Sender,
|
||||
)
|
||||
where
|
||||
Job: JobTrait<ToJob = ToJob>,
|
||||
Sender: SubsystemSender,
|
||||
) where
|
||||
Job: JobTrait<ToJob = ToJob>,
|
||||
Sender: SubsystemSender,
|
||||
{
|
||||
let (to_job_tx, to_job_rx) = mpsc::channel(JOB_CHANNEL_CAPACITY);
|
||||
let (from_job_tx, from_job_rx) = mpsc::channel(JOB_CHANNEL_CAPACITY);
|
||||
@@ -577,11 +562,10 @@ where
|
||||
run_args,
|
||||
metrics,
|
||||
to_job_rx,
|
||||
JobSender {
|
||||
sender,
|
||||
from_job: from_job_tx,
|
||||
},
|
||||
).await {
|
||||
JobSender { sender, from_job: from_job_tx },
|
||||
)
|
||||
.await
|
||||
{
|
||||
tracing::error!(
|
||||
job = Job::NAME,
|
||||
parent_hash = %parent_hash,
|
||||
@@ -589,7 +573,7 @@ where
|
||||
"job finished with an error",
|
||||
);
|
||||
|
||||
return Err(e);
|
||||
return Err(e)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -598,10 +582,7 @@ where
|
||||
self.spawner.spawn(Job::NAME, future.map(drop).boxed());
|
||||
self.outgoing_msgs.push(from_job_rx);
|
||||
|
||||
let handle = JobHandle {
|
||||
_abort_handle: AbortOnDrop(abort_handle),
|
||||
to_job: to_job_tx,
|
||||
};
|
||||
let handle = JobHandle { _abort_handle: AbortOnDrop(abort_handle), to_job: to_job_tx };
|
||||
|
||||
self.running.insert(parent_hash, handle);
|
||||
}
|
||||
@@ -672,34 +653,24 @@ impl<Job: JobTrait, Spawner> JobSubsystem<Job, Spawner> {
|
||||
/// Create a new `JobSubsystem`.
|
||||
pub fn new(spawner: Spawner, run_args: Job::RunArgs, metrics: Job::Metrics) -> Self {
|
||||
JobSubsystem {
|
||||
params: JobSubsystemParams {
|
||||
spawner,
|
||||
run_args,
|
||||
metrics,
|
||||
},
|
||||
params: JobSubsystemParams { spawner, run_args, metrics },
|
||||
_marker: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
/// Run the subsystem to completion.
|
||||
pub async fn run<Context>(self, mut ctx: Context)
|
||||
where
|
||||
Spawner: SpawnNamed + Send + Clone + Unpin + 'static,
|
||||
Context: SubsystemContext<Message=<Job as JobTrait>::ToJob, Signal=OverseerSignal>,
|
||||
<Context as SubsystemContext>::Sender: SubsystemSender,
|
||||
Job: 'static + JobTrait + Send,
|
||||
<Job as JobTrait>::RunArgs: Clone + Sync,
|
||||
<Job as JobTrait>::ToJob: Sync + From<<Context as polkadot_overseer::SubsystemContext>::Message>,
|
||||
<Job as JobTrait>::Metrics: Sync,
|
||||
where
|
||||
Spawner: SpawnNamed + Send + Clone + Unpin + 'static,
|
||||
Context: SubsystemContext<Message = <Job as JobTrait>::ToJob, Signal = OverseerSignal>,
|
||||
<Context as SubsystemContext>::Sender: SubsystemSender,
|
||||
Job: 'static + JobTrait + Send,
|
||||
<Job as JobTrait>::RunArgs: Clone + Sync,
|
||||
<Job as JobTrait>::ToJob:
|
||||
Sync + From<<Context as polkadot_overseer::SubsystemContext>::Message>,
|
||||
<Job as JobTrait>::Metrics: Sync,
|
||||
{
|
||||
let JobSubsystem {
|
||||
params: JobSubsystemParams {
|
||||
spawner,
|
||||
run_args,
|
||||
metrics,
|
||||
},
|
||||
..
|
||||
} = self;
|
||||
let JobSubsystem { params: JobSubsystemParams { spawner, run_args, metrics }, .. } = self;
|
||||
|
||||
let mut jobs = Jobs::<Spawner, Job::ToJob>::new(spawner);
|
||||
|
||||
@@ -768,10 +739,11 @@ impl<Job: JobTrait, Spawner> JobSubsystem<Job, Spawner> {
|
||||
impl<Context, Job, Spawner> Subsystem<Context, SubsystemError> for JobSubsystem<Job, Spawner>
|
||||
where
|
||||
Spawner: SpawnNamed + Send + Clone + Unpin + 'static,
|
||||
Context: SubsystemContext<Message=Job::ToJob,Signal=OverseerSignal>,
|
||||
Context: SubsystemContext<Message = Job::ToJob, Signal = OverseerSignal>,
|
||||
Job: 'static + JobTrait + Send,
|
||||
Job::RunArgs: Clone + Sync,
|
||||
<Job as JobTrait>::ToJob: Sync + From<<Context as polkadot_overseer::SubsystemContext>::Message>,
|
||||
<Job as JobTrait>::ToJob:
|
||||
Sync + From<<Context as polkadot_overseer::SubsystemContext>::Message>,
|
||||
Job::Metrics: Sync,
|
||||
{
|
||||
fn start(self, ctx: Context) -> SpawnedSubsystem {
|
||||
@@ -780,9 +752,6 @@ where
|
||||
Ok(())
|
||||
});
|
||||
|
||||
SpawnedSubsystem {
|
||||
name: Job::NAME.strip_suffix("Job").unwrap_or(Job::NAME),
|
||||
future,
|
||||
}
|
||||
SpawnedSubsystem { name: Job::NAME.strip_suffix("Job").unwrap_or(Job::NAME), future }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user