creating csv file with transaction details

This commit is contained in:
godmode galactus 2022-09-09 11:19:40 +02:00
parent 8020eba325
commit cb2e32db9e
3 changed files with 665 additions and 974 deletions

1512
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -3,4 +3,4 @@ cargo run \
-- -u https://api.testnet.rpcpool.com/dfeb84a5-7fe8-4783-baf9-60cca0babbc7 \ -- -u https://api.testnet.rpcpool.com/dfeb84a5-7fe8-4783-baf9-60cca0babbc7 \
--identity ~/devnet.json \ --identity ~/devnet.json \
--accounts ~/accounts20.json \ --accounts ~/accounts20.json \
--mango ~/ids.json --duration 10 -q 2 --mango ~/ids.json --duration 10 -q 2 --transaction_save_file tlog.txt

View File

@ -99,18 +99,19 @@ struct TransactionSendRecord {
#[derive(Clone, Serialize)] #[derive(Clone, Serialize)]
struct TransactionConfirmRecord { struct TransactionConfirmRecord {
pub signature: Signature, pub signature: String,
pub sent_slot: Slot, pub sent_slot: Slot,
pub sent_at: DateTime<Utc>, pub sent_at: String,
pub confirmed_slot: Slot, pub confirmed_slot: Slot,
pub confirmed_at: DateTime<Utc>, pub confirmed_at: String,
pub successful: bool, pub successful: bool,
pub slot_leader: Pubkey, pub slot_leader: String,
pub error: Option<String>, pub error: String,
pub market_maker: Pubkey, pub market_maker: String,
pub market: Pubkey, pub market: String,
pub block_hash: Pubkey, pub block_hash: String,
pub slot_processed: Slot, pub slot_processed: Slot,
pub timed_out: bool,
} }
#[derive(Clone)] #[derive(Clone)]
@ -333,25 +334,22 @@ fn process_signature_confirmation_batch(
} else { } else {
let mut lock = confirmed.write().unwrap(); let mut lock = confirmed.write().unwrap();
(*lock).push(TransactionConfirmRecord { (*lock).push(TransactionConfirmRecord {
signature: tx_record.signature, signature: tx_record.signature.to_string(),
sent_slot: tx_record.sent_slot, sent_slot: tx_record.sent_slot,
sent_at: tx_record.sent_at, sent_at: tx_record.sent_at.to_string(),
confirmed_at: Utc::now(), confirmed_at: Utc::now().to_string(),
confirmed_slot: s.slot, confirmed_slot: s.slot,
successful: s.err.is_none(), successful: s.err.is_none(),
error: s.err.as_ref().map(|e| { error: match &s.err {
let err_msg = e.to_string(); Some(e) => e.to_string(),
debug!( None=> "".to_string(),
"tx {} returned an error {}", },
tx_record.signature, err_msg, block_hash: Pubkey::default().to_string(),
); slot_leader: Pubkey::default().to_string(),
err_msg market: tx_record.market.to_string(),
}), market_maker: tx_record.market_maker.to_string(),
block_hash: Pubkey::default(),
slot_leader: Pubkey::default(),
market: tx_record.market,
market_maker: tx_record.market_maker,
slot_processed: tx_record.sent_slot, slot_processed: tx_record.sent_slot,
timed_out: false,
}); });
debug!( debug!(
@ -583,15 +581,12 @@ fn confirmations_by_blocks(
.unwrap(); .unwrap();
let mut mm_transaction_count: u64 = 0; let mut mm_transaction_count: u64 = 0;
let rewards = &block.rewards.unwrap(); let rewards = &block.rewards.unwrap();
let slot_leader = Pubkey::from_str( let slot_leader = rewards
rewards
.iter() .iter()
.find(|r| r.reward_type == Some(RewardType::Fee)) .find(|r| r.reward_type == Some(RewardType::Fee))
.unwrap() .unwrap()
.pubkey .pubkey
.as_str(), .to_string();
)
.unwrap();
if let Some(transactions) = block.transactions { if let Some(transactions) = block.transactions {
let nb_transactions = transactions.len(); let nb_transactions = transactions.len();
@ -626,10 +621,10 @@ fn confirmations_by_blocks(
mm_transaction_count += 1; mm_transaction_count += 1;
(*lock).push(TransactionConfirmRecord { (*lock).push(TransactionConfirmRecord {
signature: transaction_record.signature, signature: transaction_record.signature.to_string(),
confirmed_slot: slot, // TODO: should be changed to correct slot confirmed_slot: slot, // TODO: should be changed to correct slot
confirmed_at: Utc::now(), confirmed_at: Utc::now().to_string(),
sent_at: transaction_record.sent_at, sent_at: transaction_record.sent_at.to_string(),
sent_slot: transaction_record.sent_slot, sent_slot: transaction_record.sent_slot,
successful: if let Some(meta) = &meta { successful: if let Some(meta) = &meta {
meta.status.is_ok() meta.status.is_ok()
@ -638,18 +633,18 @@ fn confirmations_by_blocks(
}, },
error: if let Some(meta) = &meta { error: if let Some(meta) = &meta {
match &meta.err { match &meta.err {
Some(x) => Some(x.to_string()), Some(x) => x.to_string(),
None => None, None => "".to_string(),
} }
} else { } else {
None "".to_string()
}, },
block_hash: Pubkey::from_str(block.blockhash.as_str()) block_hash: block.blockhash.clone(),
.unwrap(), market: transaction_record.market.to_string(),
market: transaction_record.market, market_maker: transaction_record.market_maker.to_string(),
market_maker: transaction_record.market_maker,
slot_processed: slot, slot_processed: slot,
slot_leader: slot_leader, slot_leader: slot_leader.clone(),
timed_out: false,
}) })
} }
@ -662,7 +657,7 @@ 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: Pubkey::from_str(block.blockhash.as_str()).unwrap(),
block_leader: slot_leader, block_leader: Pubkey::from_str(slot_leader.as_str()).unwrap(),
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
@ -706,7 +701,23 @@ fn write_transaction_data_into_csv(
let timeout_lk = tx_timeout_records.read().unwrap(); let timeout_lk = tx_timeout_records.read().unwrap();
for timeout_record in timeout_lk.iter() { for timeout_record in timeout_lk.iter() {
writer.serialize(timeout_record).unwrap(); writer.serialize(
TransactionConfirmRecord{
block_hash: "".to_string(),
confirmed_at: "".to_string(),
confirmed_slot: 0,
error: "Timeout".to_string(),
market: timeout_record.market.to_string(),
market_maker: timeout_record.market_maker.to_string(),
sent_at: timeout_record.sent_at.to_string(),
sent_slot: timeout_record.sent_slot,
signature: timeout_record.signature.to_string(),
slot_leader: "".to_string(),
slot_processed: 0,
successful: false,
timed_out: true,
}
).unwrap();
} }
} }
writer.flush().unwrap(); writer.flush().unwrap();
@ -961,7 +972,7 @@ fn main() {
total_signed, total_signed,
(confirmed.len() * 100) / total_signed (confirmed.len() * 100) / total_signed
); );
let error_count = confirmed.iter().filter(|tx| tx.error.is_some()).count(); let error_count = confirmed.iter().filter(|tx| !tx.error.is_empty()).count();
info!( info!(
"errors counted {} rate {}%", "errors counted {} rate {}%",
error_count, error_count,
@ -978,21 +989,21 @@ fn main() {
(timeouts.len() * 100) / total_signed (timeouts.len() * 100) / total_signed
); );
let mut confirmation_times = confirmed // let mut confirmation_times = confirmed
.iter() // .iter()
.map(|r| { // .map(|r| {
r.confirmed_at // r.confirmed_at
.signed_duration_since(r.sent_at) // .signed_duration_since(r.sent_at)
.num_milliseconds() // .num_milliseconds()
}) // })
.collect::<Vec<_>>(); // .collect::<Vec<_>>();
confirmation_times.sort(); // confirmation_times.sort();
info!( // info!(
"confirmation times min={} max={} median={}", // "confirmation times min={} max={} median={}",
confirmation_times.first().unwrap(), // confirmation_times.first().unwrap(),
confirmation_times.last().unwrap(), // confirmation_times.last().unwrap(),
confirmation_times[confirmation_times.len() / 2] // confirmation_times[confirmation_times.len() / 2]
); // );
write_transaction_data_into_csv( write_transaction_data_into_csv(
transaction_save_file, transaction_save_file,