mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 03:27: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:
+126
-117
@@ -59,46 +59,36 @@
|
||||
// yielding false positives
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use std::fmt::{self, Debug};
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::collections::{hash_map, HashMap};
|
||||
use std::iter::FromIterator;
|
||||
|
||||
use futures::channel::oneshot;
|
||||
use futures::{
|
||||
select,
|
||||
future::BoxFuture,
|
||||
Future, FutureExt, StreamExt,
|
||||
use std::{
|
||||
collections::{hash_map, HashMap},
|
||||
fmt::{self, Debug},
|
||||
iter::FromIterator,
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use futures::{channel::oneshot, future::BoxFuture, select, Future, FutureExt, StreamExt};
|
||||
use lru::LruCache;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use polkadot_primitives::v1::{Block, BlockId,BlockNumber, Hash, ParachainHost};
|
||||
use client::{BlockImportNotification, BlockchainEvents, FinalityNotification};
|
||||
use polkadot_primitives::v1::{Block, BlockId, BlockNumber, Hash, ParachainHost};
|
||||
use sp_api::{ApiExt, ProvideRuntimeApi};
|
||||
|
||||
use polkadot_node_network_protocol::{
|
||||
v1 as protocol_v1,
|
||||
};
|
||||
use polkadot_node_network_protocol::v1 as protocol_v1;
|
||||
use polkadot_node_subsystem_types::messages::{
|
||||
CandidateValidationMessage, CandidateBackingMessage,
|
||||
ChainApiMessage, StatementDistributionMessage,
|
||||
AvailabilityDistributionMessage, BitfieldSigningMessage, BitfieldDistributionMessage,
|
||||
ProvisionerMessage, RuntimeApiMessage,
|
||||
AvailabilityStoreMessage, NetworkBridgeMessage, CollationGenerationMessage,
|
||||
CollatorProtocolMessage, AvailabilityRecoveryMessage, ApprovalDistributionMessage,
|
||||
ApprovalVotingMessage, GossipSupportMessage,
|
||||
NetworkBridgeEvent,
|
||||
DisputeParticipationMessage, DisputeCoordinatorMessage, ChainSelectionMessage,
|
||||
DisputeDistributionMessage,
|
||||
ApprovalDistributionMessage, ApprovalVotingMessage, AvailabilityDistributionMessage,
|
||||
AvailabilityRecoveryMessage, AvailabilityStoreMessage, BitfieldDistributionMessage,
|
||||
BitfieldSigningMessage, CandidateBackingMessage, CandidateValidationMessage, ChainApiMessage,
|
||||
ChainSelectionMessage, CollationGenerationMessage, CollatorProtocolMessage,
|
||||
DisputeCoordinatorMessage, DisputeDistributionMessage, DisputeParticipationMessage,
|
||||
GossipSupportMessage, NetworkBridgeEvent, NetworkBridgeMessage, ProvisionerMessage,
|
||||
RuntimeApiMessage, StatementDistributionMessage,
|
||||
};
|
||||
pub use polkadot_node_subsystem_types::{
|
||||
OverseerSignal,
|
||||
errors::{SubsystemResult, SubsystemError,},
|
||||
ActiveLeavesUpdate, ActivatedLeaf, LeafStatus,
|
||||
jaeger,
|
||||
errors::{SubsystemError, SubsystemResult},
|
||||
jaeger, ActivatedLeaf, ActiveLeavesUpdate, LeafStatus, OverseerSignal,
|
||||
};
|
||||
|
||||
// TODO legacy, to be deleted, left for easier integration
|
||||
@@ -110,30 +100,15 @@ mod metrics;
|
||||
use self::metrics::Metrics;
|
||||
|
||||
use polkadot_node_metrics::{
|
||||
metrics::{
|
||||
prometheus,
|
||||
Metrics as MetricsTrait
|
||||
},
|
||||
metrics::{prometheus, Metrics as MetricsTrait},
|
||||
Metronome,
|
||||
};
|
||||
pub use polkadot_overseer_gen::{
|
||||
TimeoutExt,
|
||||
SpawnNamed,
|
||||
Subsystem,
|
||||
SubsystemMeterReadouts,
|
||||
SubsystemMeters,
|
||||
SubsystemIncomingMessages,
|
||||
SubsystemInstance,
|
||||
SubsystemSender,
|
||||
SubsystemContext,
|
||||
overlord,
|
||||
MessagePacket,
|
||||
SignalsReceived,
|
||||
FromOverseer,
|
||||
ToOverseer,
|
||||
MapSubsystem,
|
||||
};
|
||||
pub use polkadot_overseer_gen as gen;
|
||||
pub use polkadot_overseer_gen::{
|
||||
overlord, FromOverseer, MapSubsystem, MessagePacket, SignalsReceived, SpawnNamed, Subsystem,
|
||||
SubsystemContext, SubsystemIncomingMessages, SubsystemInstance, SubsystemMeterReadouts,
|
||||
SubsystemMeters, SubsystemSender, TimeoutExt, ToOverseer,
|
||||
};
|
||||
|
||||
/// Store 2 days worth of blocks, not accounting for forks,
|
||||
/// in the LRU cache. Assumes a 6-second block time.
|
||||
@@ -142,14 +117,14 @@ const KNOWN_LEAVES_CACHE_SIZE: usize = 2 * 24 * 3600 / 6;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
|
||||
/// Whether a header supports parachain consensus or not.
|
||||
pub trait HeadSupportsParachains {
|
||||
/// Return true if the given header supports parachain consensus. Otherwise, false.
|
||||
fn head_supports_parachains(&self, head: &Hash) -> bool;
|
||||
}
|
||||
|
||||
impl<Client> HeadSupportsParachains for Arc<Client> where
|
||||
impl<Client> HeadSupportsParachains for Arc<Client>
|
||||
where
|
||||
Client: ProvideRuntimeApi<Block>,
|
||||
Client::Api: ParachainHost<Block>,
|
||||
{
|
||||
@@ -159,7 +134,6 @@ impl<Client> HeadSupportsParachains for Arc<Client> where
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// A handle used to communicate with the [`Overseer`].
|
||||
///
|
||||
/// [`Overseer`]: struct.Overseer.html
|
||||
@@ -205,11 +179,16 @@ impl Handle {
|
||||
/// Note that due the fact the overseer doesn't store the whole active-leaves set, only deltas,
|
||||
/// the response channel may never return if the hash was deactivated before this call.
|
||||
/// In this case, it's the caller's responsibility to ensure a timeout is set.
|
||||
pub async fn wait_for_activation(&mut self, hash: Hash, response_channel: oneshot::Sender<SubsystemResult<()>>) {
|
||||
pub async fn wait_for_activation(
|
||||
&mut self,
|
||||
hash: Hash,
|
||||
response_channel: oneshot::Sender<SubsystemResult<()>>,
|
||||
) {
|
||||
self.send_and_log_error(Event::ExternalRequest(ExternalRequest::WaitForActivation {
|
||||
hash,
|
||||
response_channel
|
||||
})).await;
|
||||
hash,
|
||||
response_channel,
|
||||
}))
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Tell `Overseer` to shutdown.
|
||||
@@ -293,21 +272,13 @@ pub struct BlockInfo {
|
||||
|
||||
impl From<BlockImportNotification<Block>> for BlockInfo {
|
||||
fn from(n: BlockImportNotification<Block>) -> Self {
|
||||
BlockInfo {
|
||||
hash: n.hash,
|
||||
parent_hash: n.header.parent_hash,
|
||||
number: n.header.number,
|
||||
}
|
||||
BlockInfo { hash: n.hash, parent_hash: n.header.parent_hash, number: n.header.number }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FinalityNotification<Block>> for BlockInfo {
|
||||
fn from(n: FinalityNotification<Block>) -> Self {
|
||||
BlockInfo {
|
||||
hash: n.hash,
|
||||
parent_hash: n.header.parent_hash,
|
||||
number: n.header.number,
|
||||
}
|
||||
BlockInfo { hash: n.hash, parent_hash: n.header.parent_hash, number: n.header.number }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,10 +316,7 @@ pub enum ExternalRequest {
|
||||
|
||||
/// Glues together the [`Overseer`] and `BlockchainEvents` by forwarding
|
||||
/// import and finality notifications into the [`OverseerHandle`].
|
||||
pub async fn forward_events<P: BlockchainEvents<Block>>(
|
||||
client: Arc<P>,
|
||||
mut handle: Handle,
|
||||
) {
|
||||
pub async fn forward_events<P: BlockchainEvents<Block>>(client: Arc<P>, mut handle: Handle) {
|
||||
let mut finality = client.finality_notification_stream();
|
||||
let mut imports = client.import_notification_stream();
|
||||
|
||||
@@ -594,9 +562,53 @@ where
|
||||
/// # });
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn new<CV, CB, SD, AD, AR, BS, BD, P, RA, AS, NB, CA, CG, CP, ApD, ApV, GS, DC, DP, DD, CS>(
|
||||
pub fn new<
|
||||
CV,
|
||||
CB,
|
||||
SD,
|
||||
AD,
|
||||
AR,
|
||||
BS,
|
||||
BD,
|
||||
P,
|
||||
RA,
|
||||
AS,
|
||||
NB,
|
||||
CA,
|
||||
CG,
|
||||
CP,
|
||||
ApD,
|
||||
ApV,
|
||||
GS,
|
||||
DC,
|
||||
DP,
|
||||
DD,
|
||||
CS,
|
||||
>(
|
||||
leaves: impl IntoIterator<Item = BlockInfo>,
|
||||
all_subsystems: AllSubsystems<CV, CB, SD, AD, AR, BS, BD, P, RA, AS, NB, CA, CG, CP, ApD, ApV, GS, DC, DP, DD, CS>,
|
||||
all_subsystems: AllSubsystems<
|
||||
CV,
|
||||
CB,
|
||||
SD,
|
||||
AD,
|
||||
AR,
|
||||
BS,
|
||||
BD,
|
||||
P,
|
||||
RA,
|
||||
AS,
|
||||
NB,
|
||||
CA,
|
||||
CG,
|
||||
CP,
|
||||
ApD,
|
||||
ApV,
|
||||
GS,
|
||||
DC,
|
||||
DP,
|
||||
DD,
|
||||
CS,
|
||||
>,
|
||||
prometheus_registry: Option<&prometheus::Registry>,
|
||||
supports_parachains: SupportsParachains,
|
||||
s: S,
|
||||
@@ -604,8 +616,10 @@ where
|
||||
where
|
||||
CV: Subsystem<OverseerSubsystemContext<CandidateValidationMessage>, SubsystemError> + Send,
|
||||
CB: Subsystem<OverseerSubsystemContext<CandidateBackingMessage>, SubsystemError> + Send,
|
||||
SD: Subsystem<OverseerSubsystemContext<StatementDistributionMessage>, SubsystemError> + Send,
|
||||
AD: Subsystem<OverseerSubsystemContext<AvailabilityDistributionMessage>, SubsystemError> + Send,
|
||||
SD: Subsystem<OverseerSubsystemContext<StatementDistributionMessage>, SubsystemError>
|
||||
+ Send,
|
||||
AD: Subsystem<OverseerSubsystemContext<AvailabilityDistributionMessage>, SubsystemError>
|
||||
+ Send,
|
||||
AR: Subsystem<OverseerSubsystemContext<AvailabilityRecoveryMessage>, SubsystemError> + Send,
|
||||
BS: Subsystem<OverseerSubsystemContext<BitfieldSigningMessage>, SubsystemError> + Send,
|
||||
BD: Subsystem<OverseerSubsystemContext<BitfieldDistributionMessage>, SubsystemError> + Send,
|
||||
@@ -616,7 +630,8 @@ where
|
||||
CA: Subsystem<OverseerSubsystemContext<ChainApiMessage>, SubsystemError> + Send,
|
||||
CG: Subsystem<OverseerSubsystemContext<CollationGenerationMessage>, SubsystemError> + Send,
|
||||
CP: Subsystem<OverseerSubsystemContext<CollatorProtocolMessage>, SubsystemError> + Send,
|
||||
ApD: Subsystem<OverseerSubsystemContext<ApprovalDistributionMessage>, SubsystemError> + Send,
|
||||
ApD:
|
||||
Subsystem<OverseerSubsystemContext<ApprovalDistributionMessage>, SubsystemError> + Send,
|
||||
ApV: Subsystem<OverseerSubsystemContext<ApprovalVotingMessage>, SubsystemError> + Send,
|
||||
GS: Subsystem<OverseerSubsystemContext<GossipSupportMessage>, SubsystemError> + Send,
|
||||
DC: Subsystem<OverseerSubsystemContext<DisputeCoordinatorMessage>, SubsystemError> + Send,
|
||||
@@ -650,7 +665,9 @@ where
|
||||
.dispute_distribution(all_subsystems.dispute_distribution)
|
||||
.chain_selection(all_subsystems.chain_selection)
|
||||
.leaves(Vec::from_iter(
|
||||
leaves.into_iter().map(|BlockInfo { hash, parent_hash: _, number }| (hash, number))
|
||||
leaves
|
||||
.into_iter()
|
||||
.map(|BlockInfo { hash, parent_hash: _, number }| (hash, number)),
|
||||
))
|
||||
.known_leaves(LruCache::new(KNOWN_LEAVES_CACHE_SIZE))
|
||||
.active_leaves(Default::default())
|
||||
@@ -669,33 +686,29 @@ where
|
||||
type Output = Option<(&'static str, SubsystemMeters)>;
|
||||
|
||||
fn map_subsystem(&self, subsystem: &'a OverseenSubsystem<T>) -> Self::Output {
|
||||
subsystem.instance.as_ref().map(|instance| {
|
||||
(
|
||||
instance.name,
|
||||
instance.meters.clone(),
|
||||
)
|
||||
})
|
||||
subsystem
|
||||
.instance
|
||||
.as_ref()
|
||||
.map(|instance| (instance.name, instance.meters.clone()))
|
||||
}
|
||||
}
|
||||
let subsystem_meters = overseer.map_subsystems(ExtractNameAndMeters);
|
||||
|
||||
let metronome_metrics = metrics.clone();
|
||||
let metronome = Metronome::new(std::time::Duration::from_millis(950))
|
||||
.for_each(move |_| {
|
||||
|
||||
let metronome =
|
||||
Metronome::new(std::time::Duration::from_millis(950)).for_each(move |_| {
|
||||
// We combine the amount of messages from subsystems to the overseer
|
||||
// as well as the amount of messages from external sources to the overseer
|
||||
// into one `to_overseer` value.
|
||||
metronome_metrics.channel_fill_level_snapshot(
|
||||
subsystem_meters.iter()
|
||||
subsystem_meters
|
||||
.iter()
|
||||
.cloned()
|
||||
.filter_map(|x| x)
|
||||
.map(|(name, ref meters)| (name, meters.read()))
|
||||
.map(|(name, ref meters)| (name, meters.read())),
|
||||
);
|
||||
|
||||
async move {
|
||||
()
|
||||
}
|
||||
async move { () }
|
||||
});
|
||||
overseer.spawner().spawn("metrics_metronome", Box::pin(metronome));
|
||||
}
|
||||
@@ -705,10 +718,7 @@ where
|
||||
|
||||
/// Stop the overseer.
|
||||
async fn stop(mut self) {
|
||||
let _ = self.wait_terminate(
|
||||
OverseerSignal::Conclude,
|
||||
Duration::from_secs(1_u64)
|
||||
).await;
|
||||
let _ = self.wait_terminate(OverseerSignal::Conclude, Duration::from_secs(1_u64)).await;
|
||||
}
|
||||
|
||||
/// Run the `Overseer`.
|
||||
@@ -717,12 +727,8 @@ where
|
||||
for (hash, number) in std::mem::take(&mut self.leaves) {
|
||||
let _ = self.active_leaves.insert(hash, number);
|
||||
if let Some((span, status)) = self.on_head_activated(&hash, None) {
|
||||
let update = ActiveLeavesUpdate::start_work(ActivatedLeaf {
|
||||
hash,
|
||||
number,
|
||||
status,
|
||||
span,
|
||||
});
|
||||
let update =
|
||||
ActiveLeavesUpdate::start_work(ActivatedLeaf { hash, number, status, span });
|
||||
self.broadcast_signal(OverseerSignal::ActiveLeaves(update)).await?;
|
||||
}
|
||||
}
|
||||
@@ -778,8 +784,8 @@ where
|
||||
hash_map::Entry::Vacant(entry) => entry.insert(block.number),
|
||||
hash_map::Entry::Occupied(entry) => {
|
||||
debug_assert_eq!(*entry.get(), block.number);
|
||||
return Ok(());
|
||||
}
|
||||
return Ok(())
|
||||
},
|
||||
};
|
||||
|
||||
let mut update = match self.on_head_activated(&block.hash, Some(block.parent_hash)) {
|
||||
@@ -787,7 +793,7 @@ where
|
||||
hash: block.hash,
|
||||
number: block.number,
|
||||
status,
|
||||
span
|
||||
span,
|
||||
}),
|
||||
None => ActiveLeavesUpdate::default(),
|
||||
};
|
||||
@@ -822,7 +828,8 @@ where
|
||||
self.on_head_deactivated(deactivated)
|
||||
}
|
||||
|
||||
self.broadcast_signal(OverseerSignal::BlockFinalized(block.hash, block.number)).await?;
|
||||
self.broadcast_signal(OverseerSignal::BlockFinalized(block.hash, block.number))
|
||||
.await?;
|
||||
|
||||
// If there are no leaves being deactivated, we don't need to send an update.
|
||||
//
|
||||
@@ -836,11 +843,13 @@ where
|
||||
|
||||
/// Handles a header activation. If the header's state doesn't support the parachains API,
|
||||
/// this returns `None`.
|
||||
fn on_head_activated(&mut self, hash: &Hash, parent_hash: Option<Hash>)
|
||||
-> Option<(Arc<jaeger::Span>, LeafStatus)>
|
||||
{
|
||||
fn on_head_activated(
|
||||
&mut self,
|
||||
hash: &Hash,
|
||||
parent_hash: Option<Hash>,
|
||||
) -> Option<(Arc<jaeger::Span>, LeafStatus)> {
|
||||
if !self.supports_parachains.head_supports_parachains(hash) {
|
||||
return None;
|
||||
return None
|
||||
}
|
||||
|
||||
self.metrics.on_head_activated();
|
||||
@@ -894,9 +903,12 @@ where
|
||||
// it's fine if the listener is no longer interested
|
||||
let _ = response_channel.send(Ok(()));
|
||||
} else {
|
||||
self.activation_external_listeners.entry(hash).or_default().push(response_channel);
|
||||
self.activation_external_listeners
|
||||
.entry(hash)
|
||||
.or_default()
|
||||
.push(response_channel);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -909,15 +921,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Additional `From` implementations, in order to deal with incoming network messages.
|
||||
// Kept out of the proc macro, for sake of simplicity reduce the need to make even
|
||||
// more types to the proc macro logic.
|
||||
|
||||
use polkadot_node_network_protocol::{
|
||||
request_response::{request::IncomingRequest, v1 as req_res_v1},
|
||||
use polkadot_node_network_protocol::request_response::{
|
||||
request::IncomingRequest, v1 as req_res_v1,
|
||||
};
|
||||
|
||||
impl From<IncomingRequest<req_res_v1::PoVFetchingRequest>> for AllMessages {
|
||||
|
||||
Reference in New Issue
Block a user