Fix dos data-type for non-gossip mode (#20465) (#20478)

(cherry picked from commit b178f3f2d3)

Co-authored-by: sakridge <sakridge@gmail.com>
This commit is contained in:
mergify[bot]
2021-10-06 19:00:34 +00:00
committed by GitHub
parent d922971ec6
commit 414674eba1

View File

@ -12,6 +12,13 @@ use std::process::exit;
use std::str::FromStr; use std::str::FromStr;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
fn get_repair_contact(nodes: &[ContactInfo]) -> ContactInfo {
let source = thread_rng().gen_range(0, nodes.len());
let mut contact = nodes[source].clone();
contact.id = solana_sdk::pubkey::new_rand();
contact
}
fn run_dos( fn run_dos(
nodes: &[ContactInfo], nodes: &[ContactInfo],
iterations: usize, iterations: usize,
@ -56,38 +63,35 @@ fn run_dos(
let mut data = Vec::new(); let mut data = Vec::new();
if !nodes.is_empty() { match data_type.as_str() {
let source = thread_rng().gen_range(0, nodes.len()); "repair_highest" => {
let mut contact = nodes[source].clone(); let slot = 100;
contact.id = solana_sdk::pubkey::new_rand(); let req = RepairProtocol::WindowIndexWithNonce(get_repair_contact(nodes), slot, 0, 0);
match data_type.as_str() { data = bincode::serialize(&req).unwrap();
"repair_highest" => { }
let slot = 100; "repair_shred" => {
let req = RepairProtocol::WindowIndexWithNonce(contact, slot, 0, 0); let slot = 100;
data = bincode::serialize(&req).unwrap(); let req =
} RepairProtocol::HighestWindowIndexWithNonce(get_repair_contact(nodes), slot, 0, 0);
"repair_shred" => { data = bincode::serialize(&req).unwrap();
let slot = 100; }
let req = RepairProtocol::HighestWindowIndexWithNonce(contact, slot, 0, 0); "repair_orphan" => {
data = bincode::serialize(&req).unwrap(); let slot = 100;
} let req = RepairProtocol::OrphanWithNonce(get_repair_contact(nodes), slot, 0);
"repair_orphan" => { data = bincode::serialize(&req).unwrap();
let slot = 100; }
let req = RepairProtocol::OrphanWithNonce(contact, slot, 0); "random" => {
data = bincode::serialize(&req).unwrap(); data.resize(data_size, 0);
} }
"random" => { "transaction" => {
data.resize(data_size, 0); let tx = solana_perf::test_tx::test_tx();
} info!("{:?}", tx);
"transaction" => { data = bincode::serialize(&tx).unwrap();
let tx = solana_perf::test_tx::test_tx(); }
data = bincode::serialize(&tx).unwrap(); "get_account_info" => {}
} "get_program_accounts" => {}
"get_account_info" => {} &_ => {
"get_program_accounts" => {} panic!("unknown data type");
&_ => {
panic!("unknown data type");
}
} }
} }