add transaction options to dos
This commit is contained in:
125
dos/src/main.rs
125
dos/src/main.rs
@ -7,6 +7,12 @@ use {
|
|||||||
solana_core::serve_repair::RepairProtocol,
|
solana_core::serve_repair::RepairProtocol,
|
||||||
solana_gossip::{contact_info::ContactInfo, gossip_service::discover},
|
solana_gossip::{contact_info::ContactInfo, gossip_service::discover},
|
||||||
solana_sdk::pubkey::Pubkey,
|
solana_sdk::pubkey::Pubkey,
|
||||||
|
solana_sdk::timing::timestamp,
|
||||||
|
// TODO(klykov): maybe later will move to test_tx.rs
|
||||||
|
solana_sdk::{
|
||||||
|
hash::Hash, instruction::CompiledInstruction, signature::Keypair, stake,
|
||||||
|
system_instruction::SystemInstruction, system_program, transaction::Transaction,
|
||||||
|
},
|
||||||
solana_streamer::socket::SocketAddrSpace,
|
solana_streamer::socket::SocketAddrSpace,
|
||||||
std::{
|
std::{
|
||||||
net::{SocketAddr, UdpSocket},
|
net::{SocketAddr, UdpSocket},
|
||||||
@ -14,16 +20,6 @@ use {
|
|||||||
str::FromStr,
|
str::FromStr,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
},
|
},
|
||||||
// TODO(klykov): maybe later will move to test_tx.rs
|
|
||||||
solana_sdk::{
|
|
||||||
transaction::Transaction,
|
|
||||||
signature::Keypair,
|
|
||||||
hash::Hash,
|
|
||||||
stake,
|
|
||||||
system_program,
|
|
||||||
instruction::CompiledInstruction,
|
|
||||||
system_instruction::SystemInstruction,
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn get_repair_contact(nodes: &[ContactInfo]) -> ContactInfo {
|
fn get_repair_contact(nodes: &[ContactInfo]) -> ContactInfo {
|
||||||
@ -33,10 +29,21 @@ fn get_repair_contact(nodes: &[ContactInfo]) -> ContactInfo {
|
|||||||
contact
|
contact
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_multisig_tx(nsign: usize, blockhash: Hash) -> Transaction {
|
fn test_multisig_tx(
|
||||||
let kpvals: Vec<Keypair> = (0..nsign).map( |_| Keypair::new() ).collect();
|
transaction_params: &TransactionParams,
|
||||||
|
rpc_client: &Option<RpcClient>,
|
||||||
|
) -> Transaction {
|
||||||
|
let kpvals: Vec<Keypair> = (0..transaction_params.num_sign)
|
||||||
|
.map(|_| Keypair::new())
|
||||||
|
.collect();
|
||||||
let keypairs: Vec<&Keypair> = kpvals.iter().collect();
|
let keypairs: Vec<&Keypair> = kpvals.iter().collect();
|
||||||
|
|
||||||
|
let blockhash = if transaction_params.valid_block_hash {
|
||||||
|
rpc_client.as_ref().unwrap().get_latest_blockhash().unwrap()
|
||||||
|
} else {
|
||||||
|
Hash::default()
|
||||||
|
};
|
||||||
|
|
||||||
let lamports = 5;
|
let lamports = 5;
|
||||||
let transfer_instruction = SystemInstruction::Transfer { lamports };
|
let transfer_instruction = SystemInstruction::Transfer { lamports };
|
||||||
|
|
||||||
@ -48,20 +55,25 @@ fn test_multisig_tx(nsign: usize, blockhash: Hash) -> Transaction {
|
|||||||
vec![0, 1],
|
vec![0, 1],
|
||||||
)];
|
)];
|
||||||
|
|
||||||
let tx = Transaction::new_with_compiled_instructions(
|
let mut tx = Transaction::new_with_compiled_instructions(
|
||||||
&keypairs,
|
&keypairs,
|
||||||
&[],
|
&[],
|
||||||
blockhash,
|
blockhash,
|
||||||
program_ids,
|
program_ids,
|
||||||
instructions,
|
instructions,
|
||||||
);
|
);
|
||||||
|
if !transaction_params.valid_signatures {
|
||||||
|
tx.signatures = vec![Transaction::get_invalid_signature(); transaction_params.num_sign];
|
||||||
|
}
|
||||||
tx
|
tx
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_invalid_multisig_tx(nsign: usize, blockhash: Hash) -> Transaction {
|
/// Options for data_type=transaction
|
||||||
let mut tx = test_multisig_tx(nsign, blockhash);
|
struct TransactionParams {
|
||||||
tx.signatures = vec![Transaction::get_invalid_signature(); nsign];
|
unique_transactons: bool, // use unique transactions
|
||||||
tx
|
num_sign: usize, // number of signatures in a transaction
|
||||||
|
valid_block_hash: bool, // use valid blockhash or random
|
||||||
|
valid_signatures: bool, // use valid signatures or not
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_dos(
|
fn run_dos(
|
||||||
@ -72,8 +84,7 @@ fn run_dos(
|
|||||||
data_size: usize,
|
data_size: usize,
|
||||||
mode: String,
|
mode: String,
|
||||||
data_input: Option<String>,
|
data_input: Option<String>,
|
||||||
num_sign: usize, // makes sense only with transaction mode
|
transaction_params: Option<TransactionParams>,
|
||||||
valid_block_hash: bool, // makes sense only with transaction mode
|
|
||||||
) {
|
) {
|
||||||
let mut target = None;
|
let mut target = None;
|
||||||
let mut rpc_client = None;
|
let mut rpc_client = None;
|
||||||
@ -92,7 +103,7 @@ fn run_dos(
|
|||||||
"tpu" => {
|
"tpu" => {
|
||||||
rpc_client = Some(RpcClient::new_socket(node.rpc));
|
rpc_client = Some(RpcClient::new_socket(node.rpc));
|
||||||
Some(node.tpu)
|
Some(node.tpu)
|
||||||
},
|
}
|
||||||
"tpu_forwards" => Some(node.tpu_forwards),
|
"tpu_forwards" => Some(node.tpu_forwards),
|
||||||
"repair" => Some(node.repair),
|
"repair" => Some(node.repair),
|
||||||
"serve_repair" => Some(node.serve_repair),
|
"serve_repair" => Some(node.serve_repair),
|
||||||
@ -134,14 +145,15 @@ fn run_dos(
|
|||||||
data.resize(data_size, 0);
|
data.resize(data_size, 0);
|
||||||
}
|
}
|
||||||
"transaction" => {
|
"transaction" => {
|
||||||
let blockhash = if valid_block_hash {
|
if transaction_params.is_none() {
|
||||||
rpc_client.as_ref().unwrap().get_latest_blockhash().unwrap()
|
panic!("transaction parameters are not specified");
|
||||||
} else {
|
}
|
||||||
Hash::default()
|
let tp = transaction_params.as_ref().unwrap();
|
||||||
};
|
if tp.unique_transactons {
|
||||||
let tx = test_multisig_tx(num_sign, blockhash);
|
let tx = test_multisig_tx(tp, &rpc_client);
|
||||||
info!("{:?}", tx);
|
info!("{:?}", tx);
|
||||||
data = bincode::serialize(&tx).unwrap();
|
data = bincode::serialize(&tx).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"get_account_info" => {}
|
"get_account_info" => {}
|
||||||
"get_program_accounts" => {}
|
"get_program_accounts" => {}
|
||||||
@ -181,6 +193,13 @@ fn run_dos(
|
|||||||
if data_type == "random" {
|
if data_type == "random" {
|
||||||
thread_rng().fill(&mut data[..]);
|
thread_rng().fill(&mut data[..]);
|
||||||
}
|
}
|
||||||
|
if let Some(tp) = transaction_params.as_ref() {
|
||||||
|
if tp.unique_transactons {
|
||||||
|
let tx = test_multisig_tx(tp, &rpc_client);
|
||||||
|
info!("{:?}", tx);
|
||||||
|
data = bincode::serialize(&tx).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
let res = socket.send_to(&data, target);
|
let res = socket.send_to(&data, target);
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
error_count += 1;
|
error_count += 1;
|
||||||
@ -283,6 +302,20 @@ fn main() {
|
|||||||
.help("Generate a valid blockhash for transaction")
|
.help("Generate a valid blockhash for transaction")
|
||||||
.hidden(true),
|
.hidden(true),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("valid_sign")
|
||||||
|
.long("generate-valid-signatures")
|
||||||
|
.takes_value(false)
|
||||||
|
.help("Generate valid signature(s) for transaction")
|
||||||
|
.hidden(true),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("unique_trans")
|
||||||
|
.long("generate-unique-transactions")
|
||||||
|
.takes_value(false)
|
||||||
|
.help("Generate unique transaction")
|
||||||
|
.hidden(true),
|
||||||
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let mut entrypoint_addr = SocketAddr::from(([127, 0, 0, 1], 8001));
|
let mut entrypoint_addr = SocketAddr::from(([127, 0, 0, 1], 8001));
|
||||||
@ -298,8 +331,16 @@ fn main() {
|
|||||||
let mode = value_t_or_exit!(matches, "mode", String);
|
let mode = value_t_or_exit!(matches, "mode", String);
|
||||||
let data_type = value_t_or_exit!(matches, "data_type", String);
|
let data_type = value_t_or_exit!(matches, "data_type", String);
|
||||||
let data_input = value_t!(matches, "data_input", String).ok();
|
let data_input = value_t!(matches, "data_input", String).ok();
|
||||||
let num_sign = value_t!(matches, "num_sign", usize).unwrap_or(2);
|
|
||||||
let valid_blockhash = matches.is_present("valid_blockhash");
|
let transaction_params = match data_type.as_str() {
|
||||||
|
"transaction" => Some(TransactionParams {
|
||||||
|
unique_transactons: matches.is_present("unique_trans"),
|
||||||
|
num_sign: value_t!(matches, "num_sign", usize).unwrap_or(2),
|
||||||
|
valid_block_hash: matches.is_present("valid_blockhash"),
|
||||||
|
valid_signatures: matches.is_present("valid_sign"),
|
||||||
|
}),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
|
||||||
let mut nodes = vec![];
|
let mut nodes = vec![];
|
||||||
if !skip_gossip {
|
if !skip_gossip {
|
||||||
@ -333,8 +374,7 @@ fn main() {
|
|||||||
data_size,
|
data_size,
|
||||||
mode,
|
mode,
|
||||||
data_input,
|
data_input,
|
||||||
num_sign,
|
transaction_params,
|
||||||
valid_blockhash,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,8 +401,7 @@ pub mod test {
|
|||||||
10,
|
10,
|
||||||
"tvu".to_string(),
|
"tvu".to_string(),
|
||||||
None,
|
None,
|
||||||
2,
|
None,
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
run_dos(
|
run_dos(
|
||||||
@ -373,8 +412,7 @@ pub mod test {
|
|||||||
10,
|
10,
|
||||||
"repair".to_string(),
|
"repair".to_string(),
|
||||||
None,
|
None,
|
||||||
2,
|
None,
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
run_dos(
|
run_dos(
|
||||||
@ -385,8 +423,7 @@ pub mod test {
|
|||||||
10,
|
10,
|
||||||
"serve_repair".to_string(),
|
"serve_repair".to_string(),
|
||||||
None,
|
None,
|
||||||
2,
|
None,
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -402,16 +439,22 @@ pub mod test {
|
|||||||
let nodes = cluster.get_node_pubkeys();
|
let nodes = cluster.get_node_pubkeys();
|
||||||
let node = cluster.get_contact_info(&nodes[0]).unwrap().clone();
|
let node = cluster.get_contact_info(&nodes[0]).unwrap().clone();
|
||||||
|
|
||||||
|
let tp = Some(TransactionParams {
|
||||||
|
unique_transactons: false,
|
||||||
|
num_sign: 2,
|
||||||
|
valid_block_hash: false, // use valid blockhash or random
|
||||||
|
valid_signatures: false, // use valid signatures or not
|
||||||
|
});
|
||||||
|
|
||||||
run_dos(
|
run_dos(
|
||||||
&[node],
|
&[node],
|
||||||
1, // was 10_000_000
|
1_000_000, // was 10_000_000
|
||||||
cluster.entry_point_info.gossip,
|
cluster.entry_point_info.gossip,
|
||||||
"transaction".to_string(),
|
"transaction".to_string(),
|
||||||
1000,
|
1000,
|
||||||
"tpu".to_string(),
|
"tpu".to_string(),
|
||||||
None,
|
None,
|
||||||
3,
|
tp,
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user