Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subsystem-bench: polish imports #3262

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions polkadot/node/subsystem-bench/src/approval/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)]
Expand Down
56 changes: 26 additions & 30 deletions polkadot/node/subsystem-bench/src/approval/message_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,59 @@
// 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::{
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;
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,
v2::{CoreBitfield, IndirectAssignmentCertV2, IndirectSignedApprovalVoteV2},
};
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
32 changes: 18 additions & 14 deletions polkadot/node/subsystem-bench/src/approval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,27 @@
// 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,
environment::{
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,
Expand Down Expand Up @@ -92,15 +91,16 @@ 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 {
col_approval_data: DATA_COL,
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;
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions polkadot/node/subsystem-bench/src/approval/test_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
81 changes: 40 additions & 41 deletions polkadot/node/subsystem-bench/src/availability/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_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,
Expand Down
Loading
Loading