From 78c2a9ef52483fc56da129ef6f6a7562f418c546 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Fri, 22 Jan 2021 19:11:41 -0800 Subject: [PATCH] Fetch blockhash for each transaction simulation to avoid stale blockhashes --- stake-o-matic/src/main.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/stake-o-matic/src/main.rs b/stake-o-matic/src/main.rs index 58df7916aa..996b55a952 100644 --- a/stake-o-matic/src/main.rs +++ b/stake-o-matic/src/main.rs @@ -463,16 +463,11 @@ fn simulate_transactions( rpc_client: &RpcClient, candidate_transactions: Vec<(Transaction, String)>, ) -> client_error::Result> { - let (blockhash, _fee_calculator) = rpc_client.get_recent_blockhash()?; - - info!( - "Simulating {} transactions with blockhash {}", - candidate_transactions.len(), - blockhash - ); + info!("Simulating {} transactions", candidate_transactions.len(),); let mut simulated_transactions = vec![]; for (mut transaction, memo) in candidate_transactions { - transaction.message.recent_blockhash = blockhash; + transaction.message.recent_blockhash = + retry_rpc_operation(10, || rpc_client.get_recent_blockhash())?.0; let sim_result = rpc_client.simulate_transaction_with_config( &transaction, @@ -511,7 +506,7 @@ fn transact( ); let (blockhash, fee_calculator, last_valid_slot) = rpc_client - .get_recent_blockhash_with_commitment(CommitmentConfig::max())? + .get_recent_blockhash_with_commitment(rpc_client.commitment())? .value; info!("{} transactions to send", transactions.len());