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};