From ee5a93dd9a9481fb46c4807334c56a91d000524e Mon Sep 17 00:00:00 2001 From: haoran Date: Mon, 2 Jan 2023 14:19:40 +0000 Subject: [PATCH 1/9] retry get_latest_blockhash --- accounts-cluster-bench/src/main.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/accounts-cluster-bench/src/main.rs b/accounts-cluster-bench/src/main.rs index 3de2020dc82747..5e254227201b45 100644 --- a/accounts-cluster-bench/src/main.rs +++ b/accounts-cluster-bench/src/main.rs @@ -54,8 +54,24 @@ pub fn airdrop_lamports( id.pubkey(), ); - let blockhash = client.get_latest_blockhash().unwrap(); - match request_airdrop_transaction(faucet_addr, &id.pubkey(), airdrop_amount, blockhash) { + let mut num_retries = 5; + let blockhash = loop { + let blockhash = client.get_latest_blockhash(); + if blockhash.is_ok() { + break blockhash; + } + if num_retries == 0 { + panic!("failed to get_latest_blockhash(), rpc node down?") + } + num_retries -= 1; + }; + + match request_airdrop_transaction( + faucet_addr, + &id.pubkey(), + airdrop_amount, + blockhash.unwrap(), + ) { Ok(transaction) => { let mut tries = 0; loop { From 2cf031b73f2f43c83f5db88124b9e2edda2fb3aa Mon Sep 17 00:00:00 2001 From: haoran Date: Mon, 2 Jan 2023 15:10:13 +0000 Subject: [PATCH 2/9] more retries for get_latest_blockhash --- accounts-cluster-bench/src/main.rs | 34 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/accounts-cluster-bench/src/main.rs b/accounts-cluster-bench/src/main.rs index 5e254227201b45..e30a210fc7282d 100644 --- a/accounts-cluster-bench/src/main.rs +++ b/accounts-cluster-bench/src/main.rs @@ -11,6 +11,7 @@ use { solana_gossip::gossip_service::discover, solana_rpc_client::rpc_client::RpcClient, solana_runtime::inline_spl_token, + solana_sdk::hash::Hash, solana_sdk::{ commitment_config::CommitmentConfig, instruction::{AccountMeta, Instruction}, @@ -36,6 +37,20 @@ use { }, }; +pub fn get_latest_blockhash(client: &RpcClient) -> Option { + let mut num_retries = 5; + loop { + let blockhash = client.get_latest_blockhash(); + if blockhash.is_ok() { + return Some(blockhash.unwrap()); + } + if num_retries == 0 { + panic!("failed to get_latest_blockhash(), rpc node down?") + } + num_retries -= 1; + } +} + pub fn airdrop_lamports( client: &RpcClient, faucet_addr: &SocketAddr, @@ -54,18 +69,7 @@ pub fn airdrop_lamports( id.pubkey(), ); - let mut num_retries = 5; - let blockhash = loop { - let blockhash = client.get_latest_blockhash(); - if blockhash.is_ok() { - break blockhash; - } - if num_retries == 0 { - panic!("failed to get_latest_blockhash(), rpc node down?") - } - num_retries -= 1; - }; - + let blockhash = get_latest_blockhash(client); match request_airdrop_transaction( faucet_addr, &id.pubkey(), @@ -243,7 +247,7 @@ fn run_accounts_bench( let mut latest_blockhash = Instant::now(); let mut last_log = Instant::now(); let mut count = 0; - let mut blockhash = client.get_latest_blockhash().expect("blockhash"); + let mut blockhash = get_latest_blockhash(&client).expect("blockhash"); let mut tx_sent_count = 0; let mut total_accounts_created = 0; let mut total_accounts_closed = 0; @@ -290,7 +294,7 @@ fn run_accounts_bench( loop { if latest_blockhash.elapsed().as_millis() > 10_000 { - blockhash = client.get_latest_blockhash().expect("blockhash"); + blockhash = get_latest_blockhash(&client).expect("blockhash"); latest_blockhash = Instant::now(); } @@ -418,7 +422,7 @@ fn run_accounts_bench( let max_created_seed = seed_tracker.max_created.load(Ordering::Relaxed); if latest_blockhash.elapsed().as_millis() > 10_000 { - blockhash = client.get_latest_blockhash().expect("blockhash"); + blockhash = get_latest_blockhash(&client).expect("blockhash"); latest_blockhash = Instant::now(); } message.recent_blockhash = blockhash; From 81b0949f5171434db07a453061840d522f9238ce Mon Sep 17 00:00:00 2001 From: haoran Date: Mon, 2 Jan 2023 15:26:33 +0000 Subject: [PATCH 3/9] retry for get_fee too --- accounts-cluster-bench/src/main.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/accounts-cluster-bench/src/main.rs b/accounts-cluster-bench/src/main.rs index e30a210fc7282d..ca41f587c1e042 100644 --- a/accounts-cluster-bench/src/main.rs +++ b/accounts-cluster-bench/src/main.rs @@ -6,6 +6,7 @@ use { rayon::prelude::*, solana_account_decoder::parse_token::spl_token_pubkey, solana_clap_utils::input_parsers::pubkey_of, + solana_client::rpc_client::SerializableMessage, solana_client::transaction_executor::TransactionExecutor, solana_faucet::faucet::{request_airdrop_transaction, FAUCET_PORT}, solana_gossip::gossip_service::discover, @@ -51,6 +52,20 @@ pub fn get_latest_blockhash(client: &RpcClient) -> Option { } } +pub fn get_fee_for_message(client: &RpcClient, message: &impl SerializableMessage) -> Option { + let mut num_retries = 5; + loop { + let fee = client.get_fee_for_message(message); + if fee.is_ok() { + return Some(fee.unwrap()); + } + if num_retries == 0 { + panic!("failed to get_fee_for_message(), rpc node down?") + } + num_retries -= 1; + } +} + pub fn airdrop_lamports( client: &RpcClient, faucet_addr: &SocketAddr, @@ -299,9 +314,7 @@ fn run_accounts_bench( } message.recent_blockhash = blockhash; - let fee = client - .get_fee_for_message(&message) - .expect("get_fee_for_message"); + let fee = get_fee_for_message(&client, &message).expect("get_fee_for_message"); let lamports = min_balance + fee; for (i, balance) in balances.iter_mut().enumerate() { @@ -426,9 +439,7 @@ fn run_accounts_bench( latest_blockhash = Instant::now(); } message.recent_blockhash = blockhash; - let fee = client - .get_fee_for_message(&message) - .expect("get_fee_for_message"); + let fee = get_fee_for_message(&client, &message).expect("get_fee_for_message"); let sigs_len = executor.num_outstanding(); if sigs_len < batch_size && max_closed_seed < max_created_seed { From 03f3db4f4a963a4bdbf2fac171d3807603dd4762 Mon Sep 17 00:00:00 2001 From: haoran Date: Mon, 2 Jan 2023 16:15:32 +0000 Subject: [PATCH 4/9] clippy --- accounts-cluster-bench/src/main.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/accounts-cluster-bench/src/main.rs b/accounts-cluster-bench/src/main.rs index ca41f587c1e042..ecfddd9cbe460a 100644 --- a/accounts-cluster-bench/src/main.rs +++ b/accounts-cluster-bench/src/main.rs @@ -38,31 +38,33 @@ use { }, }; +pub const MAX_RPC_CALL_RETRIES: usize = 5; + pub fn get_latest_blockhash(client: &RpcClient) -> Option { - let mut num_retries = 5; + let mut num_retries = MAX_RPC_CALL_RETRIES; loop { - let blockhash = client.get_latest_blockhash(); - if blockhash.is_ok() { - return Some(blockhash.unwrap()); + if let Ok(blockhash) = client.get_latest_blockhash() { + return Some(blockhash); + } else { + num_retries -= 1; } if num_retries == 0 { panic!("failed to get_latest_blockhash(), rpc node down?") } - num_retries -= 1; } } pub fn get_fee_for_message(client: &RpcClient, message: &impl SerializableMessage) -> Option { - let mut num_retries = 5; + let mut num_retries = MAX_RPC_CALL_RETRIES; loop { - let fee = client.get_fee_for_message(message); - if fee.is_ok() { - return Some(fee.unwrap()); + if let Ok(fee) = client.get_fee_for_message(message) { + return Some(fee); + } else { + num_retries -= 1; } if num_retries == 0 { panic!("failed to get_fee_for_message(), rpc node down?") } - num_retries -= 1; } } From 6360aafdce8f642fad8e794092b8f96e77c8b90f Mon Sep 17 00:00:00 2001 From: haoran Date: Mon, 2 Jan 2023 16:34:17 +0000 Subject: [PATCH 5/9] fmt --- accounts-cluster-bench/src/main.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/accounts-cluster-bench/src/main.rs b/accounts-cluster-bench/src/main.rs index ecfddd9cbe460a..2b18baf2b2407a 100644 --- a/accounts-cluster-bench/src/main.rs +++ b/accounts-cluster-bench/src/main.rs @@ -6,15 +6,14 @@ use { rayon::prelude::*, solana_account_decoder::parse_token::spl_token_pubkey, solana_clap_utils::input_parsers::pubkey_of, - solana_client::rpc_client::SerializableMessage, - solana_client::transaction_executor::TransactionExecutor, + solana_client::{rpc_client::SerializableMessage, transaction_executor::TransactionExecutor}, solana_faucet::faucet::{request_airdrop_transaction, FAUCET_PORT}, solana_gossip::gossip_service::discover, solana_rpc_client::rpc_client::RpcClient, solana_runtime::inline_spl_token, - solana_sdk::hash::Hash, solana_sdk::{ commitment_config::CommitmentConfig, + hash::Hash, instruction::{AccountMeta, Instruction}, message::Message, pubkey::Pubkey, From 6b3b0f7481d88e8356adc39484cf7e08f546de3e Mon Sep 17 00:00:00 2001 From: haoran Date: Tue, 3 Jan 2023 14:38:22 +0000 Subject: [PATCH 6/9] sleep --- accounts-cluster-bench/src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/accounts-cluster-bench/src/main.rs b/accounts-cluster-bench/src/main.rs index 2b18baf2b2407a..5a64d13252c84b 100644 --- a/accounts-cluster-bench/src/main.rs +++ b/accounts-cluster-bench/src/main.rs @@ -50,6 +50,7 @@ pub fn get_latest_blockhash(client: &RpcClient) -> Option { if num_retries == 0 { panic!("failed to get_latest_blockhash(), rpc node down?") } + sleep(Duration::from_millis(100)); } } @@ -64,6 +65,7 @@ pub fn get_fee_for_message(client: &RpcClient, message: &impl SerializableMessag if num_retries == 0 { panic!("failed to get_fee_for_message(), rpc node down?") } + sleep(Duration::from_millis(100)); } } From d1b4ad9db72e1aeb720691de7f9e2eb37c2fda15 Mon Sep 17 00:00:00 2001 From: HaoranYi Date: Tue, 3 Jan 2023 12:50:06 -0600 Subject: [PATCH 7/9] Update accounts-cluster-bench/src/main.rs Co-authored-by: Tyera --- accounts-cluster-bench/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts-cluster-bench/src/main.rs b/accounts-cluster-bench/src/main.rs index 5a64d13252c84b..78689318c3a233 100644 --- a/accounts-cluster-bench/src/main.rs +++ b/accounts-cluster-bench/src/main.rs @@ -39,7 +39,7 @@ use { pub const MAX_RPC_CALL_RETRIES: usize = 5; -pub fn get_latest_blockhash(client: &RpcClient) -> Option { +pub fn poll_get_latest_blockhash(client: &RpcClient) -> Option { let mut num_retries = MAX_RPC_CALL_RETRIES; loop { if let Ok(blockhash) = client.get_latest_blockhash() { From e925028c0ce9b26a54fd10d6b6e0f2c3913dbead Mon Sep 17 00:00:00 2001 From: HaoranYi Date: Tue, 3 Jan 2023 12:50:16 -0600 Subject: [PATCH 8/9] Update accounts-cluster-bench/src/main.rs Co-authored-by: Tyera --- accounts-cluster-bench/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts-cluster-bench/src/main.rs b/accounts-cluster-bench/src/main.rs index 78689318c3a233..779932e118c66d 100644 --- a/accounts-cluster-bench/src/main.rs +++ b/accounts-cluster-bench/src/main.rs @@ -54,7 +54,7 @@ pub fn poll_get_latest_blockhash(client: &RpcClient) -> Option { } } -pub fn get_fee_for_message(client: &RpcClient, message: &impl SerializableMessage) -> Option { +pub fn poll_get_fee_for_message(client: &RpcClient, message: &impl SerializableMessage) -> Option { let mut num_retries = MAX_RPC_CALL_RETRIES; loop { if let Ok(fee) = client.get_fee_for_message(message) { From c8f912852604f42da4168a06dbe9772915c81abc Mon Sep 17 00:00:00 2001 From: haoran Date: Tue, 3 Jan 2023 18:54:12 +0000 Subject: [PATCH 9/9] rename --- accounts-cluster-bench/src/main.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/accounts-cluster-bench/src/main.rs b/accounts-cluster-bench/src/main.rs index 779932e118c66d..74bad5a4315eb1 100644 --- a/accounts-cluster-bench/src/main.rs +++ b/accounts-cluster-bench/src/main.rs @@ -54,7 +54,10 @@ pub fn poll_get_latest_blockhash(client: &RpcClient) -> Option { } } -pub fn poll_get_fee_for_message(client: &RpcClient, message: &impl SerializableMessage) -> Option { +pub fn poll_get_fee_for_message( + client: &RpcClient, + message: &impl SerializableMessage, +) -> Option { let mut num_retries = MAX_RPC_CALL_RETRIES; loop { if let Ok(fee) = client.get_fee_for_message(message) { @@ -87,7 +90,7 @@ pub fn airdrop_lamports( id.pubkey(), ); - let blockhash = get_latest_blockhash(client); + let blockhash = poll_get_latest_blockhash(client); match request_airdrop_transaction( faucet_addr, &id.pubkey(), @@ -265,7 +268,7 @@ fn run_accounts_bench( let mut latest_blockhash = Instant::now(); let mut last_log = Instant::now(); let mut count = 0; - let mut blockhash = get_latest_blockhash(&client).expect("blockhash"); + let mut blockhash = poll_get_latest_blockhash(&client).expect("blockhash"); let mut tx_sent_count = 0; let mut total_accounts_created = 0; let mut total_accounts_closed = 0; @@ -312,12 +315,12 @@ fn run_accounts_bench( loop { if latest_blockhash.elapsed().as_millis() > 10_000 { - blockhash = get_latest_blockhash(&client).expect("blockhash"); + blockhash = poll_get_latest_blockhash(&client).expect("blockhash"); latest_blockhash = Instant::now(); } message.recent_blockhash = blockhash; - let fee = get_fee_for_message(&client, &message).expect("get_fee_for_message"); + let fee = poll_get_fee_for_message(&client, &message).expect("get_fee_for_message"); let lamports = min_balance + fee; for (i, balance) in balances.iter_mut().enumerate() { @@ -438,11 +441,11 @@ fn run_accounts_bench( let max_created_seed = seed_tracker.max_created.load(Ordering::Relaxed); if latest_blockhash.elapsed().as_millis() > 10_000 { - blockhash = get_latest_blockhash(&client).expect("blockhash"); + blockhash = poll_get_latest_blockhash(&client).expect("blockhash"); latest_blockhash = Instant::now(); } message.recent_blockhash = blockhash; - let fee = get_fee_for_message(&client, &message).expect("get_fee_for_message"); + let fee = poll_get_fee_for_message(&client, &message).expect("get_fee_for_message"); let sigs_len = executor.num_outstanding(); if sigs_len < batch_size && max_closed_seed < max_created_seed {