Adding way to airdrop accounts and saving block infos
This commit is contained in:
parent
b214b95473
commit
0b307126cd
|
@ -4,4 +4,4 @@
|
||||||
[submodule "deps/solana"]
|
[submodule "deps/solana"]
|
||||||
path = deps/solana
|
path = deps/solana
|
||||||
url = https://github.com/solana-labs/solana
|
url = https://github.com/solana-labs/solana
|
||||||
branch = v1.10.26
|
branch = v1.11.10
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
27
src/cli.rs
27
src/cli.rs
|
@ -17,6 +17,8 @@ pub struct Config {
|
||||||
pub account_keys: String,
|
pub account_keys: String,
|
||||||
pub mango_keys: String,
|
pub mango_keys: String,
|
||||||
pub transaction_save_file: String,
|
pub transaction_save_file: String,
|
||||||
|
pub block_data_save_file: String,
|
||||||
|
pub airdrop_accounts: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
|
@ -31,6 +33,8 @@ impl Default for Config {
|
||||||
account_keys: String::new(),
|
account_keys: String::new(),
|
||||||
mango_keys: String::new(),
|
mango_keys: String::new(),
|
||||||
transaction_save_file : String::new(),
|
transaction_save_file : String::new(),
|
||||||
|
block_data_save_file : String::new(),
|
||||||
|
airdrop_accounts : false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,6 +141,23 @@ pub fn build_args<'a, 'b>(version: &'b str) -> App<'a, 'b> {
|
||||||
.required(false)
|
.required(false)
|
||||||
.help("To save details of all transactions during a run")
|
.help("To save details of all transactions during a run")
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("block_data_save_file")
|
||||||
|
.short("bdsf")
|
||||||
|
.long("block_data_save_file")
|
||||||
|
.value_name("FILENAME")
|
||||||
|
.takes_value(true)
|
||||||
|
.required(false)
|
||||||
|
.help("To save details of all block containing mm transactions")
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("airdrop_accounts")
|
||||||
|
.long("airdrop_accounts")
|
||||||
|
.value_name("BOOL")
|
||||||
|
.takes_value(false)
|
||||||
|
.required(false)
|
||||||
|
.help("Airdrop all MM accounts before stating")
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a clap `ArgMatches` structure into a `Config`
|
/// Parses a clap `ArgMatches` structure into a `Config`
|
||||||
|
@ -200,6 +221,12 @@ pub fn extract_args(matches: &ArgMatches) -> Config {
|
||||||
Some(x) => x.to_string(),
|
Some(x) => x.to_string(),
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
};
|
};
|
||||||
|
args.block_data_save_file = match matches.value_of("block_data_save_file") {
|
||||||
|
Some(x) => x.to_string(),
|
||||||
|
None => String::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
args.airdrop_accounts = matches.is_present("airdrop_accounts");
|
||||||
args
|
args
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
52
src/main.rs
52
src/main.rs
|
@ -21,6 +21,7 @@ use solana_client::{
|
||||||
connection_cache::ConnectionCache, rpc_client::RpcClient, rpc_config::RpcBlockConfig,
|
connection_cache::ConnectionCache, rpc_client::RpcClient, rpc_config::RpcBlockConfig,
|
||||||
tpu_client::TpuClient,
|
tpu_client::TpuClient,
|
||||||
};
|
};
|
||||||
|
use solana_program::native_token::LAMPORTS_PER_SOL;
|
||||||
use solana_runtime::bank::RewardType;
|
use solana_runtime::bank::RewardType;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
clock::{Slot, DEFAULT_MS_PER_SLOT},
|
clock::{Slot, DEFAULT_MS_PER_SLOT},
|
||||||
|
@ -487,10 +488,11 @@ fn confirmation_by_querying_rpc(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Serialize)]
|
||||||
struct BlockData {
|
struct BlockData {
|
||||||
pub block_hash: Pubkey,
|
pub block_hash: String,
|
||||||
pub block_slot: Slot,
|
pub block_slot: Slot,
|
||||||
pub block_leader: Pubkey,
|
pub block_leader: String,
|
||||||
pub total_transactions: u64,
|
pub total_transactions: u64,
|
||||||
pub number_of_mm_transactions: u64,
|
pub number_of_mm_transactions: u64,
|
||||||
pub block_time: u64,
|
pub block_time: u64,
|
||||||
|
@ -672,8 +674,8 @@ fn confirmations_by_blocks(
|
||||||
{
|
{
|
||||||
let mut blockstats_writer = tx_block_data.write().unwrap();
|
let mut blockstats_writer = tx_block_data.write().unwrap();
|
||||||
blockstats_writer.push(BlockData {
|
blockstats_writer.push(BlockData {
|
||||||
block_hash: Pubkey::from_str(block.blockhash.as_str()).unwrap(),
|
block_hash: block.blockhash,
|
||||||
block_leader: Pubkey::from_str(slot_leader.as_str()).unwrap(),
|
block_leader: slot_leader,
|
||||||
block_slot: slot,
|
block_slot: slot,
|
||||||
block_time: if let Some(time) = block.block_time {
|
block_time: if let Some(time) = block.block_time {
|
||||||
time as u64
|
time as u64
|
||||||
|
@ -739,6 +741,24 @@ fn write_transaction_data_into_csv(
|
||||||
writer.flush().unwrap();
|
writer.flush().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn write_block_data_into_csv(
|
||||||
|
block_data_csv: String,
|
||||||
|
tx_block_data: Arc<RwLock<Vec<BlockData>>>,
|
||||||
|
) {
|
||||||
|
if block_data_csv.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let mut writer = csv::Writer::from_path(block_data_csv).unwrap();
|
||||||
|
let data = tx_block_data.read().unwrap();
|
||||||
|
|
||||||
|
for d in data.iter().filter(|x| x.number_of_mm_transactions > 0) {
|
||||||
|
writer.serialize(d).unwrap();
|
||||||
|
}
|
||||||
|
writer.flush().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
solana_logger::setup_with_default("solana=info");
|
solana_logger::setup_with_default("solana=info");
|
||||||
solana_metrics::set_panic_hook("bench-mango", /*version:*/ None);
|
solana_metrics::set_panic_hook("bench-mango", /*version:*/ None);
|
||||||
|
@ -755,10 +775,14 @@ fn main() {
|
||||||
duration,
|
duration,
|
||||||
quotes_per_second,
|
quotes_per_second,
|
||||||
transaction_save_file,
|
transaction_save_file,
|
||||||
|
block_data_save_file,
|
||||||
|
airdrop_accounts,
|
||||||
..
|
..
|
||||||
} = &cli_config;
|
} = &cli_config;
|
||||||
|
|
||||||
let transaction_save_file = transaction_save_file.clone();
|
let transaction_save_file = transaction_save_file.clone();
|
||||||
|
let block_data_save_file = block_data_save_file.clone();
|
||||||
|
let airdrop_accounts = *airdrop_accounts;
|
||||||
|
|
||||||
info!("Connecting to the cluster");
|
info!("Connecting to the cluster");
|
||||||
|
|
||||||
|
@ -902,6 +926,21 @@ fn main() {
|
||||||
let mango_account_signer =
|
let mango_account_signer =
|
||||||
Keypair::from_bytes(account_keys.secret_key.as_slice()).unwrap();
|
Keypair::from_bytes(account_keys.secret_key.as_slice()).unwrap();
|
||||||
|
|
||||||
|
if airdrop_accounts {
|
||||||
|
println!("Transfering 1 SOL to {}", mango_account_signer.pubkey());
|
||||||
|
let inx = solana_sdk::system_instruction::transfer( &id.pubkey(), &mango_account_signer.pubkey(), LAMPORTS_PER_SOL);
|
||||||
|
|
||||||
|
let mut tx = Transaction::new_unsigned(Message::new(
|
||||||
|
&[inx],
|
||||||
|
Some(&id.pubkey()),
|
||||||
|
));
|
||||||
|
|
||||||
|
if let Ok(recent_blockhash) = blockhash.read() {
|
||||||
|
tx.sign(&[id], *recent_blockhash);
|
||||||
|
}
|
||||||
|
rpc_client.send_and_confirm_transaction_with_spinner(&tx).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"wallet:{:?} https://testnet.mango.markets/account?pubkey={:?}",
|
"wallet:{:?} https://testnet.mango.markets/account?pubkey={:?}",
|
||||||
mango_account_signer.pubkey(),
|
mango_account_signer.pubkey(),
|
||||||
|
@ -1026,6 +1065,11 @@ fn main() {
|
||||||
tx_confirm_records,
|
tx_confirm_records,
|
||||||
tx_timeout_records,
|
tx_timeout_records,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
write_block_data_into_csv(
|
||||||
|
block_data_save_file,
|
||||||
|
tx_block_data
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue