mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 08:47:57 +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:
@@ -24,29 +24,20 @@
|
||||
//! in this graph will be forwarded to the network bridge with
|
||||
//! the `NetworkBridgeMessage::NewGossipTopology` message.
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
use futures::{channel::oneshot, FutureExt as _};
|
||||
use rand::{SeedableRng, seq::SliceRandom as _};
|
||||
use rand_chacha::ChaCha20Rng;
|
||||
use polkadot_node_network_protocol::peer_set::PeerSet;
|
||||
use polkadot_node_subsystem::{
|
||||
overseer,
|
||||
messages::{GossipSupportMessage, NetworkBridgeMessage, RuntimeApiMessage, RuntimeApiRequest},
|
||||
overseer, ActiveLeavesUpdate, FromOverseer, OverseerSignal, SpawnedSubsystem, SubsystemContext,
|
||||
SubsystemError,
|
||||
FromOverseer, SpawnedSubsystem, SubsystemContext,
|
||||
messages::{
|
||||
GossipSupportMessage,
|
||||
NetworkBridgeMessage,
|
||||
RuntimeApiMessage,
|
||||
RuntimeApiRequest,
|
||||
},
|
||||
ActiveLeavesUpdate, OverseerSignal,
|
||||
};
|
||||
use polkadot_node_subsystem_util as util;
|
||||
use polkadot_primitives::v1::{
|
||||
Hash, SessionIndex, AuthorityDiscoveryId,
|
||||
};
|
||||
use polkadot_node_network_protocol::peer_set::PeerSet;
|
||||
use polkadot_primitives::v1::{AuthorityDiscoveryId, Hash, SessionIndex};
|
||||
use rand::{seq::SliceRandom as _, SeedableRng};
|
||||
use rand_chacha::ChaCha20Rng;
|
||||
use sp_application_crypto::{AppKey, Public};
|
||||
use sp_keystore::{CryptoStore, SyncCryptoStorePtr};
|
||||
use sp_application_crypto::{Public, AppKey};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -90,9 +81,7 @@ struct State {
|
||||
impl GossipSupport {
|
||||
/// Create a new instance of the [`GossipSupport`] subsystem.
|
||||
pub fn new(keystore: SyncCryptoStorePtr) -> Self {
|
||||
Self {
|
||||
keystore,
|
||||
}
|
||||
Self { keystore }
|
||||
}
|
||||
|
||||
async fn run<Context>(self, ctx: Context)
|
||||
@@ -119,7 +108,7 @@ impl GossipSupport {
|
||||
err = ?e,
|
||||
"Failed to receive a message from Overseer, exiting",
|
||||
);
|
||||
return;
|
||||
return
|
||||
},
|
||||
};
|
||||
match message {
|
||||
@@ -134,11 +123,9 @@ impl GossipSupport {
|
||||
if let Err(e) = state.handle_active_leaves(&mut ctx, &keystore, leaves).await {
|
||||
tracing::debug!(target: LOG_TARGET, error = ?e);
|
||||
}
|
||||
}
|
||||
},
|
||||
FromOverseer::Signal(OverseerSignal::BlockFinalized(_hash, _number)) => {},
|
||||
FromOverseer::Signal(OverseerSignal::Conclude) => {
|
||||
return;
|
||||
}
|
||||
FromOverseer::Signal(OverseerSignal::Conclude) => return,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,11 +155,8 @@ async fn ensure_i_am_an_authority(
|
||||
authorities: &[AuthorityDiscoveryId],
|
||||
) -> Result<usize, util::Error> {
|
||||
for (i, v) in authorities.iter().enumerate() {
|
||||
if CryptoStore::has_keys(
|
||||
&**keystore,
|
||||
&[(v.to_raw_vec(), AuthorityDiscoveryId::ID)]
|
||||
).await {
|
||||
return Ok(i);
|
||||
if CryptoStore::has_keys(&**keystore, &[(v.to_raw_vec(), AuthorityDiscoveryId::ID)]).await {
|
||||
return Ok(i)
|
||||
}
|
||||
}
|
||||
Err(util::Error::NotAValidator)
|
||||
@@ -189,13 +173,8 @@ where
|
||||
Context: overseer::SubsystemContext<Message = GossipSupportMessage>,
|
||||
{
|
||||
let (failed, failed_rx) = oneshot::channel();
|
||||
ctx.send_message(
|
||||
NetworkBridgeMessage::ConnectToValidators {
|
||||
validator_ids,
|
||||
peer_set,
|
||||
failed,
|
||||
}
|
||||
).await;
|
||||
ctx.send_message(NetworkBridgeMessage::ConnectToValidators { validator_ids, peer_set, failed })
|
||||
.await;
|
||||
failed_rx
|
||||
}
|
||||
|
||||
@@ -224,7 +203,8 @@ where
|
||||
ctx.send_message(RuntimeApiMessage::Request(
|
||||
relay_parent,
|
||||
RuntimeApiRequest::CurrentBabeEpoch(tx),
|
||||
)).await;
|
||||
))
|
||||
.await;
|
||||
|
||||
let randomness = rx.await??.randomness;
|
||||
let mut subject = [0u8; 40];
|
||||
@@ -238,24 +218,22 @@ where
|
||||
let len = authorities.len();
|
||||
let mut indices: Vec<usize> = (0..len).collect();
|
||||
indices.shuffle(&mut rng);
|
||||
let our_shuffled_position = indices.iter()
|
||||
let our_shuffled_position = indices
|
||||
.iter()
|
||||
.position(|i| *i == our_index)
|
||||
.expect("our_index < len; indices contains it; qed");
|
||||
|
||||
let neighbors = matrix_neighbors(our_shuffled_position, len);
|
||||
let our_neighbors = neighbors.map(|i| authorities[indices[i]].clone()).collect();
|
||||
|
||||
ctx.send_message(
|
||||
NetworkBridgeMessage::NewGossipTopology {
|
||||
our_neighbors,
|
||||
}
|
||||
).await;
|
||||
ctx.send_message(NetworkBridgeMessage::NewGossipTopology { our_neighbors })
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Compute our row and column neighbors in a matrix
|
||||
fn matrix_neighbors(our_index: usize, len: usize) -> impl Iterator<Item=usize> {
|
||||
fn matrix_neighbors(our_index: usize, len: usize) -> impl Iterator<Item = usize> {
|
||||
assert!(our_index < len, "our_index is computed using `enumerate`; qed");
|
||||
|
||||
// e.g. for size 11 the matrix would be
|
||||
@@ -291,7 +269,8 @@ impl State {
|
||||
Context: overseer::SubsystemContext<Message = GossipSupportMessage>,
|
||||
{
|
||||
for leaf in leaves {
|
||||
let current_index = util::request_session_index_for_child(leaf, ctx.sender()).await.await??;
|
||||
let current_index =
|
||||
util::request_session_index_for_child(leaf, ctx.sender()).await.await??;
|
||||
let since_failure = self.last_failure.map(|i| i.elapsed()).unwrap_or_default();
|
||||
let force_request = since_failure >= BACKOFF_DURATION;
|
||||
let leaf_session = Some((current_index, leaf));
|
||||
@@ -300,11 +279,8 @@ impl State {
|
||||
_ => leaf_session,
|
||||
};
|
||||
|
||||
let maybe_issue_connection = if force_request {
|
||||
leaf_session
|
||||
} else {
|
||||
maybe_new_session
|
||||
};
|
||||
let maybe_issue_connection =
|
||||
if force_request { leaf_session } else { maybe_new_session };
|
||||
|
||||
if let Some((session_index, relay_parent)) = maybe_issue_connection {
|
||||
let is_new_session = maybe_new_session.is_some();
|
||||
@@ -326,7 +302,6 @@ impl State {
|
||||
update_gossip_topology(ctx, our_index, authorities, relay_parent).await?;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -344,11 +319,7 @@ impl State {
|
||||
let num = authorities.len();
|
||||
tracing::debug!(target: LOG_TARGET, %num, "Issuing a connection request");
|
||||
|
||||
let failures = connect_to_authorities(
|
||||
ctx,
|
||||
authorities,
|
||||
PeerSet::Validation,
|
||||
).await;
|
||||
let failures = connect_to_authorities(ctx, authorities, PeerSet::Validation).await;
|
||||
|
||||
// we await for the request to be processed
|
||||
// this is fine, it should take much less time than one session
|
||||
@@ -367,8 +338,7 @@ impl State {
|
||||
target = ?num,
|
||||
"Low connectivity - authority lookup failed for too many validators."
|
||||
);
|
||||
|
||||
}
|
||||
},
|
||||
Some(_) => {
|
||||
tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
@@ -376,7 +346,7 @@ impl State {
|
||||
target = ?num,
|
||||
"Low connectivity (due to authority lookup failures) - expected on startup."
|
||||
);
|
||||
}
|
||||
},
|
||||
}
|
||||
self.last_failure = Some(timestamp);
|
||||
} else {
|
||||
@@ -394,13 +364,8 @@ where
|
||||
Context: overseer::SubsystemContext<Message = GossipSupportMessage>,
|
||||
{
|
||||
fn start(self, ctx: Context) -> SpawnedSubsystem {
|
||||
let future = self.run(ctx)
|
||||
.map(|_| Ok(()))
|
||||
.boxed();
|
||||
let future = self.run(ctx).map(|_| Ok(())).boxed();
|
||||
|
||||
SpawnedSubsystem {
|
||||
name: "gossip-support-subsystem",
|
||||
future,
|
||||
}
|
||||
SpawnedSubsystem { name: "gossip-support-subsystem", future }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,21 +18,19 @@
|
||||
|
||||
use super::*;
|
||||
use polkadot_node_subsystem::{
|
||||
jaeger, ActivatedLeaf, LeafStatus,
|
||||
jaeger,
|
||||
messages::{AllMessages, RuntimeApiMessage, RuntimeApiRequest},
|
||||
ActivatedLeaf, LeafStatus,
|
||||
};
|
||||
use polkadot_node_subsystem_test_helpers as test_helpers;
|
||||
use polkadot_node_subsystem_util::TimeoutExt as _;
|
||||
use sp_consensus_babe::{AllowedSlots, BabeEpochConfiguration, Epoch as BabeEpoch};
|
||||
use sp_keyring::Sr25519Keyring;
|
||||
use sp_consensus_babe::{
|
||||
Epoch as BabeEpoch, BabeEpochConfiguration, AllowedSlots,
|
||||
};
|
||||
use test_helpers::mock::make_ferdie_keystore;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use assert_matches::assert_matches;
|
||||
use futures::{Future, executor, future};
|
||||
use futures::{executor, future, Future};
|
||||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
type VirtualOverseer = test_helpers::TestSubsystemContextHandle<GossipSupportMessage>;
|
||||
|
||||
@@ -53,14 +51,17 @@ fn test_harness<T: Future<Output = VirtualOverseer>>(
|
||||
futures::pin_mut!(test_fut);
|
||||
futures::pin_mut!(subsystem);
|
||||
|
||||
executor::block_on(future::join(async move {
|
||||
let mut overseer = test_fut.await;
|
||||
overseer
|
||||
.send(FromOverseer::Signal(OverseerSignal::Conclude))
|
||||
.timeout(TIMEOUT)
|
||||
.await
|
||||
.expect("Conclude send timeout");
|
||||
}, subsystem));
|
||||
executor::block_on(future::join(
|
||||
async move {
|
||||
let mut overseer = test_fut.await;
|
||||
overseer
|
||||
.send(FromOverseer::Signal(OverseerSignal::Conclude))
|
||||
.timeout(TIMEOUT)
|
||||
.await
|
||||
.expect("Conclude send timeout");
|
||||
},
|
||||
subsystem,
|
||||
));
|
||||
}
|
||||
|
||||
state
|
||||
@@ -68,10 +69,7 @@ fn test_harness<T: Future<Output = VirtualOverseer>>(
|
||||
|
||||
const TIMEOUT: Duration = Duration::from_millis(100);
|
||||
|
||||
async fn overseer_signal_active_leaves(
|
||||
overseer: &mut VirtualOverseer,
|
||||
leaf: Hash,
|
||||
) {
|
||||
async fn overseer_signal_active_leaves(overseer: &mut VirtualOverseer, leaf: Hash) {
|
||||
let leaf = ActivatedLeaf {
|
||||
hash: leaf,
|
||||
number: 0xdeadcafe,
|
||||
@@ -79,20 +77,16 @@ async fn overseer_signal_active_leaves(
|
||||
span: Arc::new(jaeger::Span::Disabled),
|
||||
};
|
||||
overseer
|
||||
.send(FromOverseer::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(leaf))))
|
||||
.send(FromOverseer::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(
|
||||
leaf,
|
||||
))))
|
||||
.timeout(TIMEOUT)
|
||||
.await
|
||||
.expect("signal send timeout");
|
||||
}
|
||||
|
||||
async fn overseer_recv(
|
||||
overseer: &mut VirtualOverseer,
|
||||
) -> AllMessages {
|
||||
let msg = overseer
|
||||
.recv()
|
||||
.timeout(TIMEOUT)
|
||||
.await
|
||||
.expect("msg recv timeout");
|
||||
async fn overseer_recv(overseer: &mut VirtualOverseer) -> AllMessages {
|
||||
let msg = overseer.recv().timeout(TIMEOUT).await.expect("msg recv timeout");
|
||||
|
||||
msg
|
||||
}
|
||||
@@ -368,7 +362,9 @@ fn test_matrix_neighbors() {
|
||||
(9, 10, vec![0, 3, 6]),
|
||||
(10, 11, vec![1, 4, 7, 9]),
|
||||
(7, 11, vec![1, 4, 6, 8, 10]),
|
||||
].into_iter() {
|
||||
]
|
||||
.into_iter()
|
||||
{
|
||||
let mut result: Vec<_> = matrix_neighbors(our_index, len).collect();
|
||||
result.sort();
|
||||
assert_eq!(result, expected);
|
||||
|
||||
Reference in New Issue
Block a user