Remove client-side retry service

This commit is contained in:
Michael Vines
2020-06-04 14:22:21 -07:00
parent 832d324a23
commit 2da9b12d67

View File

@ -13,6 +13,7 @@ use solana_notifier::Notifier;
use solana_sdk::{ use solana_sdk::{
account_utils::StateMut, account_utils::StateMut,
clock::{Epoch, Slot}, clock::{Epoch, Slot},
commitment_config::CommitmentConfig,
message::Message, message::Message,
native_token::*, native_token::*,
pubkey::Pubkey, pubkey::Pubkey,
@ -20,7 +21,6 @@ use solana_sdk::{
transaction::Transaction, transaction::Transaction,
}; };
use solana_stake_program::{stake_instruction, stake_state::StakeState}; use solana_stake_program::{stake_instruction, stake_state::StakeState};
use solana_transaction_status::TransactionStatus;
use std::{ use std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
@ -31,7 +31,7 @@ use std::{
process, process,
str::FromStr, str::FromStr,
thread::sleep, thread::sleep,
time::{Duration, Instant}, time::Duration,
}; };
mod validator_list; mod validator_list;
@ -381,7 +381,6 @@ fn simulate_transactions(
Ok(simulated_transactions) Ok(simulated_transactions)
} }
#[allow(clippy::cognitive_complexity)] // Yeah I know...
fn transact( fn transact(
rpc_client: &RpcClient, rpc_client: &RpcClient,
dry_run: bool, dry_run: bool,
@ -394,7 +393,9 @@ fn transact(
lamports_to_sol(authorized_staker_balance) lamports_to_sol(authorized_staker_balance)
); );
let (blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?; let (blockhash, fee_calculator, last_valid_slot) = rpc_client
.get_recent_blockhash_with_commitment(CommitmentConfig::max())?
.value;
info!("{} transactions to send", transactions.len()); info!("{} transactions to send", transactions.len());
let required_fee = transactions.iter().fold(0, |fee, (transaction, _)| { let required_fee = transactions.iter().fold(0, |fee, (transaction, _)| {
@ -405,29 +406,14 @@ fn transact(
return Err("Authorized staker has insufficient funds".into()); return Err("Authorized staker has insufficient funds".into());
} }
struct PendingTransaction {
transaction: Transaction,
memo: String,
last_status: Option<TransactionStatus>,
last_status_update: Instant,
};
let mut pending_transactions = HashMap::new(); let mut pending_transactions = HashMap::new();
for (mut transaction, memo) in transactions.into_iter() { for (mut transaction, memo) in transactions.into_iter() {
transaction.sign(&[authorized_staker], blockhash); transaction.sign(&[authorized_staker], blockhash);
pending_transactions.insert(transaction.signatures[0], memo);
if !dry_run { if !dry_run {
rpc_client.send_transaction(&transaction)?; rpc_client.send_transaction(&transaction)?;
} }
pending_transactions.insert(
transaction.signatures[0],
PendingTransaction {
transaction,
memo,
last_status: None,
last_status_update: Instant::now(),
},
);
} }
let mut finalized_transactions = vec![]; let mut finalized_transactions = vec![];
@ -436,21 +422,26 @@ fn transact(
break; break;
} }
if rpc_client let slot = rpc_client.get_slot_with_commitment(CommitmentConfig::max())?;
.get_fee_calculator_for_blockhash(&blockhash)? info!(
.is_none() "Current slot={}, last_valid_slot={} (slots remaining: {}) ",
{ slot,
last_valid_slot,
last_valid_slot.saturating_sub(slot)
);
if slot > last_valid_slot {
error!( error!(
"Blockhash {} expired with {} pending transactions", "Blockhash {} expired with {} pending transactions",
blockhash, blockhash,
pending_transactions.len() pending_transactions.len()
); );
for (signature, pending_transaction) in pending_transactions.into_iter() { for (signature, memo) in pending_transactions.into_iter() {
finalized_transactions.push(ConfirmedTransaction { finalized_transactions.push(ConfirmedTransaction {
success: false, success: false,
signature, signature,
memo: pending_transaction.memo, memo,
}); });
} }
break; break;
@ -474,17 +465,12 @@ fn transact(
} }
assert_eq!(statuses.len(), pending_signatures.len()); assert_eq!(statuses.len(), pending_signatures.len());
let now = Instant::now();
let mut progressing_pending_transactions = 0;
for (signature, status) in pending_signatures.into_iter().zip(statuses.into_iter()) { for (signature, status) in pending_signatures.into_iter().zip(statuses.into_iter()) {
let mut pending_transaction = pending_transactions.get_mut(&signature).unwrap(); info!("{}: status={:?}", signature, status);
let completed = if dry_run {
trace!("{}: status={:?}", signature, status);
let confirmed = if dry_run {
Some(true) Some(true)
} else if let Some(status) = &status { } else if let Some(status) = &status {
if status.confirmations.is_none() { if status.confirmations.is_none() || status.err.is_some() {
Some(status.err.is_none()) Some(status.err.is_none())
} else { } else {
None None
@ -493,42 +479,17 @@ fn transact(
None None
}; };
if let Some(success) = confirmed { if let Some(success) = completed {
debug!("{}: confirmed", signature); warn!("{}: completed. success={}", signature, success);
let pending_transaction = pending_transactions.remove(&signature).unwrap(); let memo = pending_transactions.remove(&signature).unwrap();
finalized_transactions.push(ConfirmedTransaction { finalized_transactions.push(ConfirmedTransaction {
success, success,
signature, signature,
memo: pending_transaction.memo, memo,
}); });
} else if pending_transaction.last_status != status {
debug!("{}: made progress", signature);
progressing_pending_transactions += 1;
pending_transaction.last_status = status;
pending_transaction.last_status_update = now;
} else if now
.duration_since(pending_transaction.last_status_update)
.as_secs()
> 10
{
info!("{} - stale transaction, resending", signature);
if !dry_run {
rpc_client.send_transaction(&pending_transaction.transaction)?;
}
pending_transaction.last_status = None;
pending_transaction.last_status_update = now;
} else {
debug!("{}: no progress", signature);
} }
} }
sleep(Duration::from_secs(5));
info!(
"{} pending transactions ({} of which made progress), {} finalized transactions",
pending_transactions.len(),
progressing_pending_transactions,
finalized_transactions.len()
);
sleep(Duration::from_millis(4000));
} }
Ok(finalized_transactions) Ok(finalized_transactions)