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:
Shawn Tabrizi
2021-08-02 12:47:33 +02:00
committed by GitHub
parent 30e3012270
commit ff5d56fb76
350 changed files with 20617 additions and 21266 deletions
+162 -186
View File
@@ -14,47 +14,37 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use std::sync::atomic;
use std::collections::HashMap;
use std::task::{Poll};
use futures::{executor, pin_mut, select, FutureExt, pending, poll, stream};
use futures::channel::mpsc;
use futures::{channel::mpsc, executor, pending, pin_mut, poll, select, stream, FutureExt};
use std::{collections::HashMap, sync::atomic, task::Poll};
use polkadot_primitives::v1::{CollatorPair, CandidateHash};
use polkadot_node_primitives::{CollationResult, CollationGenerationConfig, PoV, BlockData};
use polkadot_node_network_protocol::{PeerId, UnifiedReputationChange};
use polkadot_node_primitives::{BlockData, CollationGenerationConfig, CollationResult, PoV};
use polkadot_node_subsystem_types::{
ActivatedLeaf, LeafStatus,
messages::{
RuntimeApiRequest,
NetworkBridgeEvent,
},
jaeger,
messages::{NetworkBridgeEvent, RuntimeApiRequest},
ActivatedLeaf, LeafStatus,
};
use polkadot_primitives::v1::{CandidateHash, CollatorPair};
use crate::{
self as overseer,
Overseer,
HeadSupportsParachains,
gen::Delay,
};
use crate::{self as overseer, gen::Delay, HeadSupportsParachains, Overseer};
use metered_channel as metered;
use sp_core::crypto::Pair as _;
use assert_matches::assert_matches;
use sp_core::crypto::Pair as _;
use super::*;
type SpawnedSubsystem = crate::gen::SpawnedSubsystem<SubsystemError>;
struct TestSubsystem1(metered::MeteredSender<usize>);
impl<C> overseer::Subsystem<C, SubsystemError> for TestSubsystem1
where
C: overseer::SubsystemContext<Message=CandidateValidationMessage,Signal=OverseerSignal,AllMessages=AllMessages>,
C: overseer::SubsystemContext<
Message = CandidateValidationMessage,
Signal = OverseerSignal,
AllMessages = AllMessages,
>,
{
fn start(self, mut ctx: C) -> SpawnedSubsystem {
let mut sender = self.0;
@@ -67,8 +57,8 @@ where
Ok(FromOverseer::Communication { .. }) => {
let _ = sender.send(i).await;
i += 1;
continue;
}
continue
},
Ok(FromOverseer::Signal(OverseerSignal::Conclude)) => return Ok(()),
Err(_) => return Ok(()),
_ => (),
@@ -83,7 +73,11 @@ struct TestSubsystem2(metered::MeteredSender<usize>);
impl<C> overseer::Subsystem<C, SubsystemError> for TestSubsystem2
where
C: overseer::SubsystemContext<Message=CandidateBackingMessage,Signal=OverseerSignal,AllMessages=AllMessages>,
C: overseer::SubsystemContext<
Message = CandidateBackingMessage,
Signal = OverseerSignal,
AllMessages = AllMessages,
>,
{
fn start(self, mut ctx: C) -> SpawnedSubsystem {
let sender = self.0.clone();
@@ -95,25 +89,18 @@ where
loop {
if c < 10 {
let (tx, _) = oneshot::channel();
ctx.send_message(
CandidateValidationMessage::ValidateFromChainState(
Default::default(),
PoV {
block_data: BlockData(Vec::new()),
}.into(),
tx,
)
).await;
ctx.send_message(CandidateValidationMessage::ValidateFromChainState(
Default::default(),
PoV { block_data: BlockData(Vec::new()) }.into(),
tx,
))
.await;
c += 1;
continue;
continue
}
match ctx.try_recv().await {
Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => {
break;
}
Ok(Some(_)) => {
continue;
}
Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => break,
Ok(Some(_)) => continue,
Err(_) => return Ok(()),
_ => (),
}
@@ -130,7 +117,11 @@ struct ReturnOnStart;
impl<C> overseer::Subsystem<C, SubsystemError> for ReturnOnStart
where
C: overseer::SubsystemContext<Message=CandidateBackingMessage,Signal=OverseerSignal,AllMessages=AllMessages>,
C: overseer::SubsystemContext<
Message = CandidateBackingMessage,
Signal = OverseerSignal,
AllMessages = AllMessages,
>,
{
fn start(self, mut _ctx: C) -> SpawnedSubsystem {
SpawnedSubsystem {
@@ -167,13 +158,8 @@ fn overseer_works() {
.replace_candidate_validation(TestSubsystem1(s1_tx))
.replace_candidate_backing(TestSubsystem2(s2_tx));
let (overseer, handle) = Overseer::new(
vec![],
all_subsystems,
None,
MockSupportsParachains,
spawner,
).unwrap();
let (overseer, handle) =
Overseer::new(vec![], all_subsystems, None, MockSupportsParachains, spawner).unwrap();
let mut handle = Handle::Connected(handle);
let overseer_fut = overseer.run().fuse();
@@ -220,21 +206,12 @@ fn overseer_metrics_work() {
let second_block_hash = [2; 32].into();
let third_block_hash = [3; 32].into();
let first_block = BlockInfo {
hash: first_block_hash,
parent_hash: [0; 32].into(),
number: 1,
};
let second_block = BlockInfo {
hash: second_block_hash,
parent_hash: first_block_hash,
number: 2,
};
let third_block = BlockInfo {
hash: third_block_hash,
parent_hash: second_block_hash,
number: 3,
};
let first_block =
BlockInfo { hash: first_block_hash, parent_hash: [0; 32].into(), number: 1 };
let second_block =
BlockInfo { hash: second_block_hash, parent_hash: first_block_hash, number: 2 };
let third_block =
BlockInfo { hash: third_block_hash, parent_hash: second_block_hash, number: 3 };
let all_subsystems = AllSubsystems::<()>::dummy();
let registry = prometheus::Registry::new();
@@ -244,7 +221,8 @@ fn overseer_metrics_work() {
Some(&registry),
MockSupportsParachains,
spawner,
).unwrap();
)
.unwrap();
let mut handle = Handle::Connected(handle);
let overseer_fut = overseer.run().fuse();
@@ -252,7 +230,9 @@ fn overseer_metrics_work() {
handle.block_imported(second_block).await;
handle.block_imported(third_block).await;
handle.send_msg_anon(AllMessages::CandidateValidation(test_candidate_validation_msg())).await;
handle
.send_msg_anon(AllMessages::CandidateValidation(test_candidate_validation_msg()))
.await;
handle.stop().await;
select! {
@@ -291,15 +271,9 @@ fn overseer_ends_on_subsystem_exit() {
let spawner = sp_core::testing::TaskExecutor::new();
executor::block_on(async move {
let all_subsystems = AllSubsystems::<()>::dummy()
.replace_candidate_backing(ReturnOnStart);
let (overseer, _handle) = Overseer::new(
vec![],
all_subsystems,
None,
MockSupportsParachains,
spawner,
).unwrap();
let all_subsystems = AllSubsystems::<()>::dummy().replace_candidate_backing(ReturnOnStart);
let (overseer, _handle) =
Overseer::new(vec![], all_subsystems, None, MockSupportsParachains, spawner).unwrap();
overseer.run().await.unwrap();
})
@@ -309,7 +283,11 @@ struct TestSubsystem5(metered::MeteredSender<OverseerSignal>);
impl<C> overseer::Subsystem<C, SubsystemError> for TestSubsystem5
where
C: overseer::SubsystemContext<Message=CandidateValidationMessage,Signal=OverseerSignal,AllMessages=AllMessages>,
C: overseer::SubsystemContext<
Message = CandidateValidationMessage,
Signal = OverseerSignal,
AllMessages = AllMessages,
>,
{
fn start(self, mut ctx: C) -> SpawnedSubsystem {
let mut sender = self.0.clone();
@@ -322,7 +300,7 @@ where
Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => break,
Ok(Some(FromOverseer::Signal(s))) => {
sender.send(s).await.unwrap();
continue;
continue
},
Ok(Some(_)) => continue,
Err(_) => break,
@@ -341,7 +319,11 @@ struct TestSubsystem6(metered::MeteredSender<OverseerSignal>);
impl<C> Subsystem<C, SubsystemError> for TestSubsystem6
where
C: overseer::SubsystemContext<Message=CandidateBackingMessage,Signal=OverseerSignal,AllMessages=AllMessages>,
C: overseer::SubsystemContext<
Message = CandidateBackingMessage,
Signal = OverseerSignal,
AllMessages = AllMessages,
>,
{
fn start(self, mut ctx: C) -> SpawnedSubsystem {
let mut sender = self.0.clone();
@@ -354,7 +336,7 @@ where
Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => break,
Ok(Some(FromOverseer::Signal(s))) => {
sender.send(s).await.unwrap();
continue;
continue
},
Ok(Some(_)) => continue,
Err(_) => break,
@@ -380,34 +362,21 @@ fn overseer_start_stop_works() {
let second_block_hash = [2; 32].into();
let third_block_hash = [3; 32].into();
let first_block = BlockInfo {
hash: first_block_hash,
parent_hash: [0; 32].into(),
number: 1,
};
let second_block = BlockInfo {
hash: second_block_hash,
parent_hash: first_block_hash,
number: 2,
};
let third_block = BlockInfo {
hash: third_block_hash,
parent_hash: second_block_hash,
number: 3,
};
let first_block =
BlockInfo { hash: first_block_hash, parent_hash: [0; 32].into(), number: 1 };
let second_block =
BlockInfo { hash: second_block_hash, parent_hash: first_block_hash, number: 2 };
let third_block =
BlockInfo { hash: third_block_hash, parent_hash: second_block_hash, number: 3 };
let (tx_5, mut rx_5) = metered::channel(64);
let (tx_6, mut rx_6) = metered::channel(64);
let all_subsystems = AllSubsystems::<()>::dummy()
.replace_candidate_validation(TestSubsystem5(tx_5))
.replace_candidate_backing(TestSubsystem6(tx_6));
let (overseer, handle) = Overseer::new(
vec![first_block],
all_subsystems,
None,
MockSupportsParachains,
spawner,
).unwrap();
let (overseer, handle) =
Overseer::new(vec![first_block], all_subsystems, None, MockSupportsParachains, spawner)
.unwrap();
let mut handle = Handle::Connected(handle);
let overseer_fut = overseer.run().fuse();
@@ -466,8 +435,9 @@ fn overseer_start_stop_works() {
}
if ss5_results.len() == expected_heartbeats.len() &&
ss6_results.len() == expected_heartbeats.len() {
handle.stop().await;
ss6_results.len() == expected_heartbeats.len()
{
handle.stop().await;
}
}
@@ -487,21 +457,12 @@ fn overseer_finalize_works() {
let second_block_hash = [2; 32].into();
let third_block_hash = [3; 32].into();
let first_block = BlockInfo {
hash: first_block_hash,
parent_hash: [0; 32].into(),
number: 1,
};
let second_block = BlockInfo {
hash: second_block_hash,
parent_hash: [42; 32].into(),
number: 2,
};
let third_block = BlockInfo {
hash: third_block_hash,
parent_hash: second_block_hash,
number: 3,
};
let first_block =
BlockInfo { hash: first_block_hash, parent_hash: [0; 32].into(), number: 1 };
let second_block =
BlockInfo { hash: second_block_hash, parent_hash: [42; 32].into(), number: 2 };
let third_block =
BlockInfo { hash: third_block_hash, parent_hash: second_block_hash, number: 3 };
let (tx_5, mut rx_5) = metered::channel(64);
let (tx_6, mut rx_6) = metered::channel(64);
@@ -517,7 +478,8 @@ fn overseer_finalize_works() {
None,
MockSupportsParachains,
spawner,
).unwrap();
)
.unwrap();
let mut handle = Handle::Connected(handle);
let overseer_fut = overseer.run().fuse();
@@ -568,7 +530,9 @@ fn overseer_finalize_works() {
complete => break,
}
if ss5_results.len() == expected_heartbeats.len() && ss6_results.len() == expected_heartbeats.len() {
if ss5_results.len() == expected_heartbeats.len() &&
ss6_results.len() == expected_heartbeats.len()
{
handle.stop().await;
}
}
@@ -590,30 +554,20 @@ fn do_not_send_empty_leaves_update_on_block_finalization() {
let spawner = sp_core::testing::TaskExecutor::new();
executor::block_on(async move {
let imported_block = BlockInfo {
hash: Hash::random(),
parent_hash: Hash::random(),
number: 1,
};
let imported_block =
BlockInfo { hash: Hash::random(), parent_hash: Hash::random(), number: 1 };
let finalized_block = BlockInfo {
hash: Hash::random(),
parent_hash: Hash::random(),
number: 1,
};
let finalized_block =
BlockInfo { hash: Hash::random(), parent_hash: Hash::random(), number: 1 };
let (tx_5, mut rx_5) = metered::channel(64);
let all_subsystems = AllSubsystems::<()>::dummy()
.replace_candidate_backing(TestSubsystem6(tx_5));
let all_subsystems =
AllSubsystems::<()>::dummy().replace_candidate_backing(TestSubsystem6(tx_5));
let (overseer, handle) = Overseer::new(
Vec::new(),
all_subsystems,
None,
MockSupportsParachains,
spawner,
).unwrap();
let (overseer, handle) =
Overseer::new(Vec::new(), all_subsystems, None, MockSupportsParachains, spawner)
.unwrap();
let mut handle = Handle::Connected(handle);
let overseer_fut = overseer.run().fuse();
@@ -673,17 +627,13 @@ impl CounterSubsystem {
signals_received: Arc<atomic::AtomicUsize>,
msgs_received: Arc<atomic::AtomicUsize>,
) -> Self {
Self {
stop_signals_received,
signals_received,
msgs_received,
}
Self { stop_signals_received, signals_received, msgs_received }
}
}
impl<C, M> Subsystem<C, SubsystemError> for CounterSubsystem
where
C: overseer::SubsystemContext<Message=M,Signal=OverseerSignal,AllMessages=AllMessages>,
C: overseer::SubsystemContext<Message = M, Signal = OverseerSignal, AllMessages = AllMessages>,
M: Send,
{
fn start(self, mut ctx: C) -> SpawnedSubsystem {
@@ -694,15 +644,15 @@ where
match ctx.try_recv().await {
Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => {
self.stop_signals_received.fetch_add(1, atomic::Ordering::SeqCst);
break;
break
},
Ok(Some(FromOverseer::Signal(_))) => {
self.signals_received.fetch_add(1, atomic::Ordering::SeqCst);
continue;
continue
},
Ok(Some(FromOverseer::Communication { .. })) => {
self.msgs_received.fetch_add(1, atomic::Ordering::SeqCst);
continue;
continue
},
Err(_) => (),
_ => (),
@@ -872,47 +822,74 @@ fn overseer_all_subsystems_receive_signals_and_messages() {
dispute_distribution: subsystem.clone(),
chain_selection: subsystem.clone(),
};
let (overseer, handle) = Overseer::new(
vec![],
all_subsystems,
None,
MockSupportsParachains,
spawner,
).unwrap();
let (overseer, handle) =
Overseer::new(vec![], all_subsystems, None, MockSupportsParachains, spawner).unwrap();
let mut handle = Handle::Connected(handle);
let overseer_fut = overseer.run().fuse();
pin_mut!(overseer_fut);
// send a signal to each subsystem
handle.block_imported(BlockInfo {
hash: Default::default(),
parent_hash: Default::default(),
number: Default::default(),
}).await;
handle
.block_imported(BlockInfo {
hash: Default::default(),
parent_hash: Default::default(),
number: Default::default(),
})
.await;
// send a msg to each subsystem
// except for BitfieldSigning and GossipSupport as the messages are not instantiable
handle.send_msg_anon(AllMessages::CandidateValidation(test_candidate_validation_msg())).await;
handle.send_msg_anon(AllMessages::CandidateBacking(test_candidate_backing_msg())).await;
handle.send_msg_anon(AllMessages::CollationGeneration(test_collator_generation_msg())).await;
handle.send_msg_anon(AllMessages::CollatorProtocol(test_collator_protocol_msg())).await;
handle.send_msg_anon(AllMessages::StatementDistribution(test_statement_distribution_msg())).await;
handle.send_msg_anon(AllMessages::AvailabilityRecovery(test_availability_recovery_msg())).await;
handle
.send_msg_anon(AllMessages::CandidateValidation(test_candidate_validation_msg()))
.await;
handle
.send_msg_anon(AllMessages::CandidateBacking(test_candidate_backing_msg()))
.await;
handle
.send_msg_anon(AllMessages::CollationGeneration(test_collator_generation_msg()))
.await;
handle
.send_msg_anon(AllMessages::CollatorProtocol(test_collator_protocol_msg()))
.await;
handle
.send_msg_anon(AllMessages::StatementDistribution(test_statement_distribution_msg()))
.await;
handle
.send_msg_anon(AllMessages::AvailabilityRecovery(test_availability_recovery_msg()))
.await;
// handle.send_msg_anon(AllMessages::BitfieldSigning(test_bitfield_signing_msg())).await;
// handle.send_msg_anon(AllMessages::GossipSupport(test_bitfield_signing_msg())).await;
handle.send_msg_anon(AllMessages::BitfieldDistribution(test_bitfield_distribution_msg())).await;
handle
.send_msg_anon(AllMessages::BitfieldDistribution(test_bitfield_distribution_msg()))
.await;
handle.send_msg_anon(AllMessages::Provisioner(test_provisioner_msg())).await;
handle.send_msg_anon(AllMessages::RuntimeApi(test_runtime_api_msg())).await;
handle.send_msg_anon(AllMessages::AvailabilityStore(test_availability_store_msg())).await;
handle.send_msg_anon(AllMessages::NetworkBridge(test_network_bridge_msg())).await;
handle
.send_msg_anon(AllMessages::AvailabilityStore(test_availability_store_msg()))
.await;
handle
.send_msg_anon(AllMessages::NetworkBridge(test_network_bridge_msg()))
.await;
handle.send_msg_anon(AllMessages::ChainApi(test_chain_api_msg())).await;
handle.send_msg_anon(AllMessages::ApprovalDistribution(test_approval_distribution_msg())).await;
handle.send_msg_anon(AllMessages::ApprovalVoting(test_approval_voting_msg())).await;
handle.send_msg_anon(AllMessages::DisputeCoordinator(test_dispute_coordinator_msg())).await;
handle.send_msg_anon(AllMessages::DisputeParticipation(test_dispute_participation_msg())).await;
handle.send_msg_anon(AllMessages::DisputeDistribution(test_dispute_distribution_msg())).await;
handle.send_msg_anon(AllMessages::ChainSelection(test_chain_selection_msg())).await;
handle
.send_msg_anon(AllMessages::ApprovalDistribution(test_approval_distribution_msg()))
.await;
handle
.send_msg_anon(AllMessages::ApprovalVoting(test_approval_voting_msg()))
.await;
handle
.send_msg_anon(AllMessages::DisputeCoordinator(test_dispute_coordinator_msg()))
.await;
handle
.send_msg_anon(AllMessages::DisputeParticipation(test_dispute_participation_msg()))
.await;
handle
.send_msg_anon(AllMessages::DisputeDistribution(test_dispute_distribution_msg()))
.await;
handle
.send_msg_anon(AllMessages::ChainSelection(test_chain_selection_msg()))
.await;
// Wait until all subsystems have received. Otherwise the messages might race against
// the conclude signal.
@@ -927,7 +904,7 @@ fn overseer_all_subsystems_receive_signals_and_messages() {
} else {
break
}
}
},
Some(_) => panic!("exited too early"),
}
}
@@ -1055,17 +1032,16 @@ fn context_holds_onto_message_until_enough_signals_received() {
assert_matches!(ctx.recv().await.unwrap(), FromOverseer::Signal(OverseerSignal::Conclude));
assert_eq!(ctx.signals_received.load(), 1);
bounded_tx.send(MessagePacket {
signals_received: 2,
message: (),
}).await.unwrap();
unbounded_tx.unbounded_send(MessagePacket {
signals_received: 2,
message: (),
}).unwrap();
bounded_tx
.send(MessagePacket { signals_received: 2, message: () })
.await
.unwrap();
unbounded_tx
.unbounded_send(MessagePacket { signals_received: 2, message: () })
.unwrap();
match poll!(ctx.recv()) {
Poll::Pending => {}
Poll::Pending => {},
Poll::Ready(_) => panic!("ready too early"),
};