subsystem-bench: polish imports (#3262)

This commit is contained in:
Andrei Eres
2024-02-12 10:17:29 +01:00
committed by GitHub
parent 4883e14482
commit cbd684673b
19 changed files with 217 additions and 247 deletions
@@ -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 <http://www.gnu.org/licenses/>.
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 <http://www.gnu.org/licenses/>.
/// A fake system clock used for driving the approval voting and make
/// it process blocks, assignments and approvals from the past.
#[derive(Clone)]
@@ -14,6 +14,50 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
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;
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},
v3 as protocol_v3,
};
use polkadot_node_primitives::approval::{
self,
v2::{CoreBitfield, IndirectAssignmentCertV2, IndirectSignedApprovalVoteV2},
};
use polkadot_primitives::{
vstaging::ApprovalVoteMultipleCandidates, CandidateEvent, CandidateHash, CandidateIndex,
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 std::{
cmp::max,
collections::{BTreeMap, HashSet},
@@ -23,54 +67,6 @@ use std::{
time::Duration,
};
use futures::SinkExt;
use itertools::Itertools;
use parity_scale_codec::Encode;
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_primitives::approval::{
self,
v2::{CoreBitfield, IndirectAssignmentCertV2, IndirectSignedApprovalVoteV2},
};
use polkadot_primitives::{
vstaging::ApprovalVoteMultipleCandidates, CandidateEvent, CandidateHash, CandidateIndex,
CoreIndex, 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 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 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.
@@ -14,9 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
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};
@@ -14,18 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
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<Vec<MessagesBundle>>,
all_messages: Option<Vec<test_message::MessagesBundle>>,
/// 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<MessagesBundle>) {
fn produce_messages(
mut self,
env: &TestEnvironment,
all_messages: Vec<test_message::MessagesBundle>,
) {
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<MessagesBundle> = Vec::new();
let mut skipped_messages: Vec<test_message::MessagesBundle> = 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<MessagesBundle>,
skipped_messages: &mut Vec<test_message::MessagesBundle>,
) -> bool {
let mut reprocess_skipped = false;
let block_info = self
@@ -14,12 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
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};
@@ -14,16 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
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;
@@ -13,74 +13,73 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
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_availability_distribution::{
AvailabilityDistributionSubsystem, IncomingRequestReceivers,
};
use polkadot_availability_recovery::AvailabilityRecoverySubsystem;
use polkadot_node_core_av_store::AvailabilityStoreSubsystem;
use polkadot_node_subsystem::{Overseer, OverseerConnector, SpawnGlue};
use polkadot_node_metrics::metrics::Metrics;
use polkadot_node_network_protocol::{
request_response::{v1::ChunkFetchingRequest, IncomingRequest, ReqProtocolNames},
OurView, Versioned, VersionedValidationProtocol,
};
use polkadot_node_primitives::{AvailableData, BlockData, ErasureChunk, PoV};
use polkadot_node_subsystem::{
messages::{AllMessages, AvailabilityRecoveryMessage},
Overseer, OverseerConnector, SpawnGlue,
};
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 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_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 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_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,
@@ -13,21 +13,18 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//
//! 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;
//! Test configuration definition and helpers.
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)
@@ -13,12 +13,13 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//
//! 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},
@@ -13,29 +13,31 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! 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)]
@@ -13,30 +13,24 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//!
//! 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<CandidateHash, usize>,
@@ -13,21 +13,19 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//!
//! 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.
@@ -13,10 +13,11 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! 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;
@@ -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 {}
@@ -13,27 +13,24 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//!
//! Mocked `network-bridge` subsystems that uses a `NetworkInterface` to access
//! the emulated network.
use futures::{channel::mpsc::UnboundedSender, FutureExt, StreamExt};
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},
};
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};
const LOG_TARGET: &str = "subsystem-bench::network-bridge";
const CHUNK_REQ_PROTOCOL_NAME_V1: &str =
@@ -13,28 +13,26 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//!
//! 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,
};
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.
@@ -14,13 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
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;
@@ -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 <http://www.gnu.org/licenses/>.
//!
//! 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};
const LOG_TARGET: &str = "subsystem-bench::network";
use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender};
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<Vec<u8>, 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() {
@@ -16,35 +16,32 @@
//! 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 color_eyre::eyre;
use pyroscope::PyroscopeAgent;
use pyroscope_pprofrs::{pprof_backend, PprofConfig};
use std::path::Path;
pub(crate) mod approval;
pub(crate) mod availability;
pub(crate) 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 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;
use clap_num::number_range;
mod approval;
mod availability;
mod core;
mod valgrind;
const LOG_TARGET: &str = "subsystem-bench";
fn le_100(s: &str) -> Result<usize, String> {
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();