diff --git a/polkadot/node/subsystem-bench/src/approval/helpers.rs b/polkadot/node/subsystem-bench/src/approval/helpers.rs index 7cbe3ba75949..623d91848f53 100644 --- a/polkadot/node/subsystem-bench/src/approval/helpers.rs +++ b/polkadot/node/subsystem-bench/src/approval/helpers.rs @@ -11,6 +11,9 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + use crate::core::configuration::TestAuthorities; use itertools::Itertools; use polkadot_node_core_approval_voting::time::{Clock, SystemClock, Tick}; @@ -39,9 +42,6 @@ use sp_keyring::sr25519::Keyring as Sr25519Keyring; use sp_runtime::{Digest, DigestItem}; use std::sync::{atomic::AtomicU64, Arc}; -// You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . - /// A fake system clock used for driving the approval voting and make /// it process blocks, assignments and approvals from the past. #[derive(Clone)] diff --git a/polkadot/node/subsystem-bench/src/approval/message_generator.rs b/polkadot/node/subsystem-bench/src/approval/message_generator.rs index 0d308a2fecc0..a71034013247 100644 --- a/polkadot/node/subsystem-bench/src/approval/message_generator.rs +++ b/polkadot/node/subsystem-bench/src/approval/message_generator.rs @@ -14,15 +14,20 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -use std::{ - cmp::max, - collections::{BTreeMap, HashSet}, - fs, - io::Write, - path::{Path, PathBuf}, - time::Duration, +use crate::{ + approval::{ + helpers::{generate_babe_epoch, generate_topology}, + test_message::{MessagesBundle, TestMessageInfo}, + ApprovalTestState, BlockTestData, GeneratedState, BUFFER_FOR_GENERATION_MILLIS, LOG_TARGET, + SLOT_DURATION_MILLIS, + }, + core::{ + configuration::{TestAuthorities, TestConfiguration}, + mock::runtime_api::session_info_for_peers, + NODE_UNDER_TEST, + }, + ApprovalsOptions, TestObjective, }; - use futures::SinkExt; use itertools::Itertools; use parity_scale_codec::Encode; @@ -30,8 +35,9 @@ use polkadot_node_core_approval_voting::{ criteria::{compute_assignments, Config}, time::tranche_to_tick, }; -use polkadot_node_network_protocol::grid_topology::{ - GridNeighbors, RandomRouting, RequiredRouting, SessionGridTopology, +use polkadot_node_network_protocol::{ + grid_topology::{GridNeighbors, RandomRouting, RequiredRouting, SessionGridTopology}, + v3 as protocol_v3, }; use polkadot_node_primitives::approval::{ self, @@ -39,38 +45,28 @@ use polkadot_node_primitives::approval::{ }; use polkadot_primitives::{ vstaging::ApprovalVoteMultipleCandidates, CandidateEvent, CandidateHash, CandidateIndex, - CoreIndex, SessionInfo, Slot, ValidatorId, ValidatorIndex, ASSIGNMENT_KEY_TYPE_ID, + CoreIndex, Hash, SessionInfo, Slot, ValidatorId, ValidatorIndex, ASSIGNMENT_KEY_TYPE_ID, }; use rand::{seq::SliceRandom, RngCore, SeedableRng}; use rand_chacha::ChaCha20Rng; use rand_distr::{Distribution, Normal}; use sc_keystore::LocalKeystore; use sc_network::PeerId; +use sc_service::SpawnTaskHandle; use sha1::Digest; use sp_application_crypto::AppCrypto; use sp_consensus_babe::SlotDuration; use sp_keystore::Keystore; use sp_timestamp::Timestamp; - -use super::{ - test_message::{MessagesBundle, TestMessageInfo}, - ApprovalTestState, ApprovalsOptions, BlockTestData, -}; -use crate::{ - approval::{ - helpers::{generate_babe_epoch, generate_topology}, - GeneratedState, BUFFER_FOR_GENERATION_MILLIS, LOG_TARGET, SLOT_DURATION_MILLIS, - }, - core::{ - configuration::{TestAuthorities, TestConfiguration}, - mock::session_info_for_peers, - NODE_UNDER_TEST, - }, - TestObjective, +use std::{ + cmp::max, + collections::{BTreeMap, HashSet}, + fs, + io::Write, + path::{Path, PathBuf}, + time::Duration, }; -use polkadot_node_network_protocol::v3 as protocol_v3; -use polkadot_primitives::Hash; -use sc_service::SpawnTaskHandle; + /// A generator of messages coming from a given Peer/Validator pub struct PeerMessagesGenerator { /// The grid neighbors of the node under test. diff --git a/polkadot/node/subsystem-bench/src/approval/mock_chain_selection.rs b/polkadot/node/subsystem-bench/src/approval/mock_chain_selection.rs index ab23a8ced484..77ba80d4b2bb 100644 --- a/polkadot/node/subsystem-bench/src/approval/mock_chain_selection.rs +++ b/polkadot/node/subsystem-bench/src/approval/mock_chain_selection.rs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -use crate::approval::{LOG_TARGET, SLOT_DURATION_MILLIS}; - -use super::{ApprovalTestState, PastSystemClock}; +use crate::approval::{ApprovalTestState, PastSystemClock, LOG_TARGET, SLOT_DURATION_MILLIS}; use futures::FutureExt; use polkadot_node_core_approval_voting::time::{slot_number_to_tick, Clock, TICK_DURATION_MILLIS}; use polkadot_node_subsystem::{overseer, SpawnedSubsystem, SubsystemError}; diff --git a/polkadot/node/subsystem-bench/src/approval/mod.rs b/polkadot/node/subsystem-bench/src/approval/mod.rs index b1ab53638701..f07912de1887 100644 --- a/polkadot/node/subsystem-bench/src/approval/mod.rs +++ b/polkadot/node/subsystem-bench/src/approval/mod.rs @@ -14,18 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -use self::{ - helpers::{make_candidates, make_header}, - test_message::{MessagesBundle, TestMessageInfo}, -}; use crate::{ approval::{ helpers::{ generate_babe_epoch, generate_new_session_topology, generate_peer_view_change_for, - PastSystemClock, + make_header, PastSystemClock, }, message_generator::PeerMessagesGenerator, mock_chain_selection::MockChainSelection, + test_message::{MessagesBundle, TestMessageInfo}, }, core::{ configuration::TestAuthorities, @@ -33,9 +30,11 @@ use crate::{ BenchmarkUsage, TestEnvironment, TestEnvironmentDependencies, MAX_TIME_OF_FLIGHT, }, mock::{ + chain_api::{ChainApiState, MockChainApi}, dummy_builder, network_bridge::{MockNetworkBridgeRx, MockNetworkBridgeTx}, - AlwaysSupportsParachains, ChainApiState, MockChainApi, MockRuntimeApi, TestSyncOracle, + runtime_api::MockRuntimeApi, + AlwaysSupportsParachains, TestSyncOracle, }, network::{ new_network, HandleNetworkMessage, NetworkEmulatorHandle, NetworkInterface, @@ -92,8 +91,7 @@ mod message_generator; mod mock_chain_selection; mod test_message; -pub const LOG_TARGET: &str = "subsystem-bench::approval"; -const DATA_COL: u32 = 0; +pub(crate) const LOG_TARGET: &str = "subsystem-bench::approval"; pub(crate) const NUM_COLUMNS: u32 = 1; pub(crate) const SLOT_DURATION_MILLIS: u64 = 6000; pub(crate) const TEST_CONFIG: ApprovalVotingConfig = ApprovalVotingConfig { @@ -101,6 +99,8 @@ pub(crate) const TEST_CONFIG: ApprovalVotingConfig = ApprovalVotingConfig { slot_duration_millis: SLOT_DURATION_MILLIS, }; +const DATA_COL: u32 = 0; + /// Start generating messages for a slot into the future, so that the /// generation nevers falls behind the current slot. const BUFFER_FOR_GENERATION_MILLIS: u64 = 30_000; @@ -235,7 +235,7 @@ impl CandidateTestData { #[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)] struct GeneratedState { /// All assignments and approvals - all_messages: Option>, + all_messages: Option>, /// The first slot in the test. initial_slot: Slot, } @@ -368,7 +368,7 @@ impl ApprovalTestState { block_number: block_number as BlockNumber, hash: block_hash, header, - candidates: make_candidates( + candidates: helpers::make_candidates( block_hash, block_number as BlockNumber, configuration.n_cores as u32, @@ -505,12 +505,16 @@ struct PeerMessageProducer { impl PeerMessageProducer { /// Generates messages by spawning a blocking task in the background which begins creating /// the assignments/approvals and peer view changes at the begining of each block. - fn produce_messages(mut self, env: &TestEnvironment, all_messages: Vec) { + fn produce_messages( + mut self, + env: &TestEnvironment, + all_messages: Vec, + ) { env.spawn_blocking("produce-messages", async move { let mut initialized_blocks = HashSet::new(); let mut per_candidate_data: HashMap<(Hash, CandidateIndex), CandidateTestData> = self.initialize_candidates_test_data(); - let mut skipped_messages: Vec = Vec::new(); + let mut skipped_messages: Vec = Vec::new(); let mut re_process_skipped = false; let system_clock = @@ -607,9 +611,9 @@ impl PeerMessageProducer { // send the message in our simulation. pub fn process_message( &mut self, - bundle: MessagesBundle, + bundle: test_message::MessagesBundle, per_candidate_data: &mut HashMap<(Hash, CandidateIndex), CandidateTestData>, - skipped_messages: &mut Vec, + skipped_messages: &mut Vec, ) -> bool { let mut reprocess_skipped = false; let block_info = self diff --git a/polkadot/node/subsystem-bench/src/approval/test_message.rs b/polkadot/node/subsystem-bench/src/approval/test_message.rs index ea578776f261..8aaabc3426c8 100644 --- a/polkadot/node/subsystem-bench/src/approval/test_message.rs +++ b/polkadot/node/subsystem-bench/src/approval/test_message.rs @@ -14,12 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -use super::{ApprovalsOptions, BlockTestData, CandidateTestData}; -use crate::core::configuration::TestAuthorities; +use crate::{ + approval::{BlockTestData, CandidateTestData}, + core::configuration::TestAuthorities, + ApprovalsOptions, +}; use itertools::Itertools; use parity_scale_codec::{Decode, Encode}; use polkadot_node_network_protocol::v3 as protocol_v3; - use polkadot_primitives::{CandidateIndex, Hash, ValidatorIndex}; use sc_network::PeerId; use std::collections::{HashMap, HashSet}; diff --git a/polkadot/node/subsystem-bench/src/availability/av_store_helpers.rs b/polkadot/node/subsystem-bench/src/availability/av_store_helpers.rs index e6827f1d8aea..261dbd0376c7 100644 --- a/polkadot/node/subsystem-bench/src/availability/av_store_helpers.rs +++ b/polkadot/node/subsystem-bench/src/availability/av_store_helpers.rs @@ -14,16 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -use crate::core::mock::TestSyncOracle; - -use super::*; - +use crate::core::{environment::TestEnvironmentDependencies, mock::TestSyncOracle}; +use polkadot_node_core_av_store::{AvailabilityStoreSubsystem, Config}; use polkadot_node_metrics::metrics::Metrics; - -use polkadot_node_core_av_store::Config; use polkadot_node_subsystem_util::database::Database; - -use polkadot_node_core_av_store::AvailabilityStoreSubsystem; +use std::sync::Arc; mod columns { pub const DATA: u32 = 0; diff --git a/polkadot/node/subsystem-bench/src/availability/mod.rs b/polkadot/node/subsystem-bench/src/availability/mod.rs index 8ed39525a1e3..ad9a17ff8f47 100644 --- a/polkadot/node/subsystem-bench/src/availability/mod.rs +++ b/polkadot/node/subsystem-bench/src/availability/mod.rs @@ -13,74 +13,73 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . + use crate::{ - core::{environment::BenchmarkUsage, mock::ChainApiState}, - TestEnvironment, + core::{ + configuration::TestConfiguration, + environment::{BenchmarkUsage, TestEnvironmentDependencies}, + mock::{ + av_store, + av_store::MockAvailabilityStore, + chain_api::{ChainApiState, MockChainApi}, + dummy_builder, + network_bridge::{self, MockNetworkBridgeRx, MockNetworkBridgeTx}, + runtime_api, + runtime_api::MockRuntimeApi, + AlwaysSupportsParachains, + }, + network::new_network, + }, + TestEnvironment, TestObjective, GENESIS_HASH, }; use av_store::NetworkAvailabilityState; +use av_store_helpers::new_av_store; use bitvec::bitvec; use colored::Colorize; +use futures::{channel::oneshot, stream::FuturesUnordered, StreamExt}; use itertools::Itertools; +use parity_scale_codec::Encode; use polkadot_availability_bitfield_distribution::BitfieldDistribution; -use polkadot_node_core_av_store::AvailabilityStoreSubsystem; -use polkadot_node_subsystem::{Overseer, OverseerConnector, SpawnGlue}; -use polkadot_node_subsystem_types::{ - messages::{AvailabilityStoreMessage, NetworkBridgeEvent}, - Span, -}; -use polkadot_overseer::{metrics::Metrics as OverseerMetrics, Handle as OverseerHandle}; -use sc_network::{request_responses::ProtocolConfig, PeerId}; -use sp_core::H256; -use std::{collections::HashMap, iter::Cycle, ops::Sub, sync::Arc, time::Instant}; - -use av_store_helpers::new_av_store; -use futures::{channel::oneshot, stream::FuturesUnordered, StreamExt}; use polkadot_availability_distribution::{ AvailabilityDistributionSubsystem, IncomingRequestReceivers, }; -use polkadot_node_metrics::metrics::Metrics; - use polkadot_availability_recovery::AvailabilityRecoverySubsystem; -use polkadot_node_primitives::{AvailableData, ErasureChunk}; - -use crate::GENESIS_HASH; -use parity_scale_codec::Encode; +use polkadot_node_core_av_store::AvailabilityStoreSubsystem; +use polkadot_node_metrics::metrics::Metrics; use polkadot_node_network_protocol::{ request_response::{v1::ChunkFetchingRequest, IncomingRequest, ReqProtocolNames}, OurView, Versioned, VersionedValidationProtocol, }; -use sc_network::request_responses::IncomingRequest as RawIncomingRequest; - -use polkadot_node_primitives::{BlockData, PoV}; -use polkadot_node_subsystem::messages::{AllMessages, AvailabilityRecoveryMessage}; - -use crate::core::{ - environment::TestEnvironmentDependencies, - mock::{ - av_store, - network_bridge::{self, MockNetworkBridgeRx, MockNetworkBridgeTx}, - runtime_api, MockAvailabilityStore, MockChainApi, MockRuntimeApi, - }, +use polkadot_node_primitives::{AvailableData, BlockData, ErasureChunk, PoV}; +use polkadot_node_subsystem::{ + messages::{AllMessages, AvailabilityRecoveryMessage}, + Overseer, OverseerConnector, SpawnGlue, }; - -use super::core::{configuration::TestConfiguration, mock::dummy_builder, network::*}; - -const LOG_TARGET: &str = "subsystem-bench::availability"; - -use super::{core::mock::AlwaysSupportsParachains, TestObjective}; use polkadot_node_subsystem_test_helpers::{ derive_erasure_chunks_with_proofs_and_root, mock::new_block_import_info, }; +use polkadot_node_subsystem_types::{ + messages::{AvailabilityStoreMessage, NetworkBridgeEvent}, + Span, +}; +use polkadot_overseer::{metrics::Metrics as OverseerMetrics, Handle as OverseerHandle}; use polkadot_primitives::{ AvailabilityBitfield, BlockNumber, CandidateHash, CandidateReceipt, GroupIndex, Hash, HeadData, Header, PersistedValidationData, Signed, SigningContext, ValidatorIndex, }; use polkadot_primitives_test_helpers::{dummy_candidate_receipt, dummy_hash}; +use sc_network::{ + request_responses::{IncomingRequest as RawIncomingRequest, ProtocolConfig}, + PeerId, +}; use sc_service::SpawnTaskHandle; +use sp_core::H256; +use std::{collections::HashMap, iter::Cycle, ops::Sub, sync::Arc, time::Instant}; mod av_store_helpers; -mod cli; -pub use cli::{DataAvailabilityReadOptions, NetworkEmulation}; +pub(crate) mod cli; + +const LOG_TARGET: &str = "subsystem-bench::availability"; fn build_overseer_for_availability_read( spawn_task_handle: SpawnTaskHandle, diff --git a/polkadot/node/subsystem-bench/src/core/configuration.rs b/polkadot/node/subsystem-bench/src/core/configuration.rs index d9eec43873aa..00be2a86b173 100644 --- a/polkadot/node/subsystem-bench/src/core/configuration.rs +++ b/polkadot/node/subsystem-bench/src/core/configuration.rs @@ -13,21 +13,18 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -// + //! Test configuration definition and helpers. -use super::*; -use itertools::Itertools; -use keyring::Keyring; -use sc_network::PeerId; -use sp_consensus_babe::AuthorityId; -use std::{collections::HashMap, path::Path}; -use crate::TestObjective; +use crate::{core::keyring::Keyring, TestObjective}; +use itertools::Itertools; use polkadot_primitives::{AssignmentId, AuthorityDiscoveryId, ValidatorId}; use rand::thread_rng; use rand_distr::{Distribution, Normal, Uniform}; - +use sc_network::PeerId; use serde::{Deserialize, Serialize}; +use sp_consensus_babe::AuthorityId; +use std::{collections::HashMap, path::Path}; pub fn random_pov_size(min_pov_size: usize, max_pov_size: usize) -> usize { random_uniform_sample(min_pov_size, max_pov_size) diff --git a/polkadot/node/subsystem-bench/src/core/display.rs b/polkadot/node/subsystem-bench/src/core/display.rs index b130afdcfad5..13a349382e2f 100644 --- a/polkadot/node/subsystem-bench/src/core/display.rs +++ b/polkadot/node/subsystem-bench/src/core/display.rs @@ -13,12 +13,13 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -// + //! Display implementations and helper methods for parsing prometheus metrics //! to a format that can be displayed in the CLI. //! //! Currently histogram buckets are skipped. -use super::{configuration::TestConfiguration, LOG_TARGET}; + +use crate::{TestConfiguration, LOG_TARGET}; use colored::Colorize; use prometheus::{ proto::{MetricFamily, MetricType}, diff --git a/polkadot/node/subsystem-bench/src/core/environment.rs b/polkadot/node/subsystem-bench/src/core/environment.rs index cffda38f2110..ca4c41cf45f9 100644 --- a/polkadot/node/subsystem-bench/src/core/environment.rs +++ b/polkadot/node/subsystem-bench/src/core/environment.rs @@ -13,29 +13,31 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . + //! Test environment implementation + use crate::{ - core::{mock::AlwaysSupportsParachains, network::NetworkEmulatorHandle}, + core::{ + configuration::TestAuthorities, mock::AlwaysSupportsParachains, + network::NetworkEmulatorHandle, + }, TestConfiguration, }; use colored::Colorize; use core::time::Duration; use futures::{Future, FutureExt}; -use polkadot_overseer::{BlockInfo, Handle as OverseerHandle}; -use serde::{Deserialize, Serialize}; - use polkadot_node_subsystem::{messages::AllMessages, Overseer, SpawnGlue, TimeoutExt}; use polkadot_node_subsystem_types::Hash; use polkadot_node_subsystem_util::metrics::prometheus::{ self, Gauge, Histogram, PrometheusError, Registry, U64, }; - +use polkadot_overseer::{BlockInfo, Handle as OverseerHandle}; use sc_service::{SpawnTaskHandle, TaskManager}; +use serde::{Deserialize, Serialize}; use std::net::{Ipv4Addr, SocketAddr}; use tokio::runtime::Handle; const LOG_TARGET: &str = "subsystem-bench::environment"; -use super::configuration::TestAuthorities; /// Test environment/configuration metrics #[derive(Clone)] diff --git a/polkadot/node/subsystem-bench/src/core/mock/av_store.rs b/polkadot/node/subsystem-bench/src/core/mock/av_store.rs index 76609ab5dba6..0a7725c91e04 100644 --- a/polkadot/node/subsystem-bench/src/core/mock/av_store.rs +++ b/polkadot/node/subsystem-bench/src/core/mock/av_store.rs @@ -13,30 +13,24 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! + //! A generic av store subsystem mockup suitable to be used in benchmarks. +use crate::core::network::{HandleNetworkMessage, NetworkMessage}; +use futures::{channel::oneshot, FutureExt}; use parity_scale_codec::Encode; use polkadot_node_network_protocol::request_response::{ v1::{AvailableDataFetchingResponse, ChunkFetchingResponse, ChunkResponse}, Requests, }; -use polkadot_primitives::CandidateHash; -use sc_network::ProtocolName; - -use std::collections::HashMap; - -use futures::{channel::oneshot, FutureExt}; - use polkadot_node_primitives::{AvailableData, ErasureChunk}; - use polkadot_node_subsystem::{ messages::AvailabilityStoreMessage, overseer, SpawnedSubsystem, SubsystemError, }; - use polkadot_node_subsystem_types::OverseerSignal; - -use crate::core::network::{HandleNetworkMessage, NetworkMessage}; +use polkadot_primitives::CandidateHash; +use sc_network::ProtocolName; +use std::collections::HashMap; pub struct AvailabilityStoreState { candidate_hashes: HashMap, diff --git a/polkadot/node/subsystem-bench/src/core/mock/chain_api.rs b/polkadot/node/subsystem-bench/src/core/mock/chain_api.rs index 7a5ee80de800..bee15c3cefdf 100644 --- a/polkadot/node/subsystem-bench/src/core/mock/chain_api.rs +++ b/polkadot/node/subsystem-bench/src/core/mock/chain_api.rs @@ -13,21 +13,19 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! + //! A generic runtime api subsystem mockup suitable to be used in benchmarks. +use futures::FutureExt; use itertools::Itertools; -use polkadot_primitives::Header; - use polkadot_node_subsystem::{ messages::ChainApiMessage, overseer, SpawnedSubsystem, SubsystemError, }; use polkadot_node_subsystem_types::OverseerSignal; +use polkadot_primitives::Header; use sp_core::H256; use std::collections::HashMap; -use futures::FutureExt; - const LOG_TARGET: &str = "subsystem-bench::chain-api-mock"; /// State used to respond to `BlockHeader` requests. diff --git a/polkadot/node/subsystem-bench/src/core/mock/dummy.rs b/polkadot/node/subsystem-bench/src/core/mock/dummy.rs index a0a908750c51..8783b35f1c04 100644 --- a/polkadot/node/subsystem-bench/src/core/mock/dummy.rs +++ b/polkadot/node/subsystem-bench/src/core/mock/dummy.rs @@ -13,10 +13,11 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . + //! Dummy subsystem mocks. -use paste::paste; use futures::FutureExt; +use paste::paste; use polkadot_node_subsystem::{overseer, SpawnedSubsystem, SubsystemError}; use std::time::Duration; use tokio::time::sleep; diff --git a/polkadot/node/subsystem-bench/src/core/mock/mod.rs b/polkadot/node/subsystem-bench/src/core/mock/mod.rs index e766b07e8b16..46fdeb196c01 100644 --- a/polkadot/node/subsystem-bench/src/core/mock/mod.rs +++ b/polkadot/node/subsystem-bench/src/core/mock/mod.rs @@ -16,6 +16,7 @@ use polkadot_node_subsystem::HeadSupportsParachains; use polkadot_node_subsystem_types::Hash; +use sp_consensus::SyncOracle; pub mod av_store; pub mod chain_api; @@ -23,11 +24,8 @@ pub mod dummy; pub mod network_bridge; pub mod runtime_api; -pub use av_store::*; -pub use chain_api::*; -pub use runtime_api::*; - pub struct AlwaysSupportsParachains {} + #[async_trait::async_trait] impl HeadSupportsParachains for AlwaysSupportsParachains { async fn head_supports_parachains(&self, _head: &Hash) -> bool { @@ -38,7 +36,7 @@ impl HeadSupportsParachains for AlwaysSupportsParachains { // An orchestra with dummy subsystems macro_rules! dummy_builder { ($spawn_task_handle: ident, $metrics: ident) => {{ - use super::core::mock::dummy::*; + use $crate::core::mock::dummy::*; // Initialize a mock overseer. // All subsystem except approval_voting and approval_distribution are mock subsystems. @@ -74,9 +72,7 @@ macro_rules! dummy_builder { .spawner(SpawnGlue($spawn_task_handle)) }}; } - pub(crate) use dummy_builder; -use sp_consensus::SyncOracle; #[derive(Clone)] pub struct TestSyncOracle {} diff --git a/polkadot/node/subsystem-bench/src/core/mock/network_bridge.rs b/polkadot/node/subsystem-bench/src/core/mock/network_bridge.rs index a171deb2e715..4682c7ec79ae 100644 --- a/polkadot/node/subsystem-bench/src/core/mock/network_bridge.rs +++ b/polkadot/node/subsystem-bench/src/core/mock/network_bridge.rs @@ -13,28 +13,25 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! + //! Mocked `network-bridge` subsystems that uses a `NetworkInterface` to access //! the emulated network. + +use crate::core::{ + configuration::TestAuthorities, + network::{NetworkEmulatorHandle, NetworkInterfaceReceiver, NetworkMessage, RequestExt}, +}; use futures::{channel::mpsc::UnboundedSender, FutureExt, StreamExt}; +use polkadot_node_network_protocol::Versioned; +use polkadot_node_subsystem::{ + messages::NetworkBridgeTxMessage, overseer, SpawnedSubsystem, SubsystemError, +}; use polkadot_node_subsystem_types::{ messages::{ApprovalDistributionMessage, BitfieldDistributionMessage, NetworkBridgeEvent}, OverseerSignal, }; - use sc_network::{request_responses::ProtocolConfig, RequestFailure}; -use polkadot_node_subsystem::{ - messages::NetworkBridgeTxMessage, overseer, SpawnedSubsystem, SubsystemError, -}; - -use polkadot_node_network_protocol::Versioned; - -use crate::core::{ - configuration::TestAuthorities, - network::{NetworkEmulatorHandle, NetworkInterfaceReceiver, NetworkMessage, RequestExt}, -}; - const LOG_TARGET: &str = "subsystem-bench::network-bridge"; const CHUNK_REQ_PROTOCOL_NAME_V1: &str = "/ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/req_chunk/1"; diff --git a/polkadot/node/subsystem-bench/src/core/mock/runtime_api.rs b/polkadot/node/subsystem-bench/src/core/mock/runtime_api.rs index ca6896dbb29d..0dd76efcbaf0 100644 --- a/polkadot/node/subsystem-bench/src/core/mock/runtime_api.rs +++ b/polkadot/node/subsystem-bench/src/core/mock/runtime_api.rs @@ -13,28 +13,26 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! -//! A generic runtime api subsystem mockup suitable to be used in benchmarks. -use itertools::Itertools; -use polkadot_primitives::{ - vstaging::NodeFeatures, CandidateEvent, CandidateReceipt, CoreState, GroupIndex, IndexedVec, - OccupiedCore, SessionIndex, SessionInfo, ValidatorIndex, -}; +//! A generic runtime api subsystem mockup suitable to be used in benchmarks. +use crate::core::configuration::{TestAuthorities, TestConfiguration}; use bitvec::prelude::BitVec; +use futures::FutureExt; +use itertools::Itertools; use polkadot_node_subsystem::{ messages::{RuntimeApiMessage, RuntimeApiRequest}, overseer, SpawnedSubsystem, SubsystemError, }; use polkadot_node_subsystem_types::OverseerSignal; +use polkadot_primitives::{ + vstaging::NodeFeatures, CandidateEvent, CandidateReceipt, CoreState, GroupIndex, IndexedVec, + OccupiedCore, SessionIndex, SessionInfo, ValidatorIndex, +}; use sp_consensus_babe::Epoch as BabeEpoch; use sp_core::H256; use std::collections::HashMap; -use crate::core::configuration::{TestAuthorities, TestConfiguration}; -use futures::FutureExt; - const LOG_TARGET: &str = "subsystem-bench::runtime-api-mock"; /// Minimal state to answer requests. diff --git a/polkadot/node/subsystem-bench/src/core/mod.rs b/polkadot/node/subsystem-bench/src/core/mod.rs index 507dd1aa83f6..764184c5b377 100644 --- a/polkadot/node/subsystem-bench/src/core/mod.rs +++ b/polkadot/node/subsystem-bench/src/core/mod.rs @@ -14,13 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -const LOG_TARGET: &str = "subsystem-bench::core"; // The validator index that represent the node that is under test. -pub const NODE_UNDER_TEST: u32 = 0; +pub(crate) const NODE_UNDER_TEST: u32 = 0; -pub mod configuration; -pub mod display; -pub mod environment; -pub mod keyring; -pub mod mock; -pub mod network; +pub(crate) mod configuration; +pub(crate) mod display; +pub(crate) mod environment; +pub(crate) mod keyring; +pub(crate) mod mock; +pub(crate) mod network; diff --git a/polkadot/node/subsystem-bench/src/core/network.rs b/polkadot/node/subsystem-bench/src/core/network.rs index 8e7c28140635..e9124726d7c0 100644 --- a/polkadot/node/subsystem-bench/src/core/network.rs +++ b/polkadot/node/subsystem-bench/src/core/network.rs @@ -12,10 +12,10 @@ // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! + //! Implements network emulation and interfaces to control and specialize //! network peer behaviour. -// + // [TestEnvironment] // [NetworkEmulatorHandle] // || @@ -33,20 +33,22 @@ // | // Subsystems under test -use crate::core::configuration::random_latency; - -use super::{ - configuration::{TestAuthorities, TestConfiguration}, +use crate::core::{ + configuration::{random_latency, TestAuthorities, TestConfiguration}, environment::TestEnvironmentDependencies, - *, + NODE_UNDER_TEST, }; use colored::Colorize; use futures::{ - channel::{mpsc, oneshot}, + channel::{ + mpsc, + mpsc::{UnboundedReceiver, UnboundedSender}, + oneshot, + }, lock::Mutex, stream::FuturesUnordered, + Future, FutureExt, StreamExt, }; - use itertools::Itertools; use net_protocol::{ peer_set::{ProtocolVersion, ValidationVersion}, @@ -54,7 +56,11 @@ use net_protocol::{ ObservedRole, VersionedValidationProtocol, }; use parity_scale_codec::Encode; +use polkadot_node_network_protocol::{self as net_protocol, Versioned}; use polkadot_node_subsystem_types::messages::{ApprovalDistributionMessage, NetworkBridgeEvent}; +use polkadot_node_subsystem_util::metrics::prometheus::{ + self, CounterVec, Opts, PrometheusError, Registry, +}; use polkadot_overseer::AllMessages; use polkadot_primitives::AuthorityDiscoveryId; use prometheus_endpoint::U64; @@ -67,14 +73,12 @@ use sc_service::SpawnTaskHandle; use std::{ collections::HashMap, sync::Arc, + task::Poll, time::{Duration, Instant}, }; -use polkadot_node_network_protocol::{self as net_protocol, Versioned}; - -use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender}; +const LOG_TARGET: &str = "subsystem-bench::network"; -use futures::{Future, FutureExt, StreamExt}; // An emulated node egress traffic rate_limiter. #[derive(Debug)] pub struct RateLimit { @@ -202,8 +206,6 @@ struct ProxiedResponse { pub result: Result, RequestFailure>, } -use std::task::Poll; - impl Future for ProxiedRequest { // The sender and result. type Output = ProxiedResponse; @@ -265,9 +267,9 @@ impl NetworkInterface { task_rx_limiter.lock().await.reap(size).await; rx_network.inc_received(size); - // To be able to apply the configured bandwidth limits for responses being sent - // over channels, we need to implement a simple proxy that allows this loop - // to receive the response and enforce the configured bandwidth before + // To be able to apply the configured bandwidth limits for responses being sent + // over channels, we need to implement a simple proxy that allows this loop + // to receive the response and enforce the configured bandwidth before // sending it to the original recipient. if let NetworkMessage::RequestFromPeer(request) = peer_message { let (response_sender, response_receiver) = oneshot::channel(); @@ -914,10 +916,6 @@ impl NetworkEmulatorHandle { } } -use polkadot_node_subsystem_util::metrics::prometheus::{ - self, CounterVec, Opts, PrometheusError, Registry, -}; - /// Emulated network metrics. #[derive(Clone)] pub(crate) struct Metrics { @@ -1036,9 +1034,8 @@ impl RequestExt for Requests { #[cfg(test)] mod tests { - use std::time::Instant; - use super::RateLimit; + use std::time::Instant; #[tokio::test] async fn test_expected_rate() { diff --git a/polkadot/node/subsystem-bench/src/subsystem-bench.rs b/polkadot/node/subsystem-bench/src/subsystem-bench.rs index a5dfbc52d606..0803f175474e 100644 --- a/polkadot/node/subsystem-bench/src/subsystem-bench.rs +++ b/polkadot/node/subsystem-bench/src/subsystem-bench.rs @@ -16,36 +16,33 @@ //! A tool for running subsystem benchmark tests designed for development and //! CI regression testing. -use clap::Parser; -use serde::{Deserialize, Serialize}; - -use colored::Colorize; +use approval::{bench_approvals, ApprovalsOptions}; +use availability::{ + cli::{DataAvailabilityReadOptions, NetworkEmulation}, + prepare_test, TestState, +}; +use clap::Parser; +use clap_num::number_range; use color_eyre::eyre; +use colored::Colorize; +use core::{ + configuration::TestConfiguration, + display::display_configuration, + environment::{TestEnvironment, GENESIS_HASH}, +}; use pyroscope::PyroscopeAgent; use pyroscope_pprofrs::{pprof_backend, PprofConfig}; - +use serde::{Deserialize, Serialize}; use std::path::Path; -pub(crate) mod approval; -pub(crate) mod availability; -pub(crate) mod core; +mod approval; +mod availability; +mod core; mod valgrind; const LOG_TARGET: &str = "subsystem-bench"; -use availability::{prepare_test, NetworkEmulation, TestState}; - -use approval::{bench_approvals, ApprovalsOptions}; -use availability::DataAvailabilityReadOptions; -use core::{ - configuration::TestConfiguration, - display::display_configuration, - environment::{TestEnvironment, GENESIS_HASH}, -}; - -use clap_num::number_range; - fn le_100(s: &str) -> Result { number_range(s, 0, 100) } @@ -213,7 +210,6 @@ fn main() -> eyre::Result<()> { .filter(Some("polkadot_overseer"), log::LevelFilter::Error) .filter(None, log::LevelFilter::Info) .format_timestamp_millis() - // .filter(None, log::LevelFilter::Trace) .try_init() .unwrap();