From b214b95473c513c457aef40befe4fc730d86aa9d Mon Sep 17 00:00:00 2001 From: godmode galactus Date: Fri, 9 Sep 2022 13:44:08 +0200 Subject: [PATCH] retry fetching block 10 times because of rpc timeouts --- src/main.rs | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index dffa99d..2b7dfa8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -567,7 +567,10 @@ fn confirmations_by_blocks( .name("getting blocks and searching transactions".to_string()) .spawn(move || { for slot in slot_batch { - let block = client + // retry search for block 10 times + let mut block = None; + for i in 0..=10 { + let block_res = client .get_block_with_config( slot, RpcBlockConfig { @@ -577,16 +580,29 @@ fn confirmations_by_blocks( commitment: Some(commitment_confirmation), max_supported_transaction_version: None, }, - ) - .unwrap(); + ); + + match block_res { + Ok(x) => { + block = Some(x); + break; + }, + _=>{ + // do nothing + } + } + } + let block = block.unwrap(); + let mut mm_transaction_count: u64 = 0; let rewards = &block.rewards.unwrap(); - let slot_leader = rewards + let slot_leader = match rewards .iter() .find(|r| r.reward_type == Some(RewardType::Fee)) - .unwrap() - .pubkey - .to_string(); + { + Some(x) => x.pubkey.clone(), + None=> "".to_string(), + }; if let Some(transactions) = block.transactions { let nb_transactions = transactions.len();