@@ -227,8 +227,8 @@ impl Cache {
227227 . await
228228 {
229229 Ok ( accounts) => {
230- let start_time = std:: time:: Instant :: now ( ) ;
231- let total_accounts = accounts. len ( ) ;
230+ // let start_time = std::time::Instant::now();
231+ // let total_accounts = accounts.len();
232232 let tasks: Vec < _ > = accounts
233233 . into_iter ( )
234234 . map ( |( pubkey, account) | {
@@ -247,14 +247,16 @@ impl Cache {
247247 . collect ( ) ;
248248
249249 join_all ( tasks) . await ;
250- let total_duration = start_time. elapsed ( ) ;
251- println ! (
252- "Total deserialization time for {} ClaimStatus accounts: {:?}" ,
253- total_accounts, total_duration
254- ) ;
250+ // let total_duration = start_time.elapsed();
251+ // println!(
252+ // "Total deserialization time for {} ClaimStatus accounts: {:?}",
253+ // total_accounts, total_duration
254+ // );
255255 }
256256 Err ( e) => {
257257 println ! ( "Error in gpa_resp: {:?}" , e) ;
258+ // Continue with next iteration instead of panicking
259+ // The websocket subscription will still provide updates
258260 }
259261 } ;
260262 interval. tick ( ) . await ;
@@ -284,37 +286,64 @@ impl Cache {
284286 let distributors_to_load = self . distributors . clone ( ) ;
285287 let distributor_keys_vec = self . get_distributor_keys ( ) ;
286288 let distributor_keys = distributor_keys_vec. as_slice ( ) ;
287- match rpc_client
288- . get_multiple_accounts_with_commitment ( & distributor_keys, CommitmentConfig :: confirmed ( ) )
289- . await
290- {
291- Ok ( accounts) => {
292- println ! (
293- "Hydrating distributor cache ({} accounts)" ,
294- accounts. value. len( )
295- ) ;
296- for ( index, account) in accounts. value . into_iter ( ) . enumerate ( ) {
297- let distributor = distributors_to_load. get ( index) . unwrap ( ) ;
298- match account {
299- Some ( account) => {
300- let distributor_data =
301- MerkleDistributor :: try_deserialize ( & mut account. data . as_slice ( ) )
302- . map_err ( |err| ApiError :: InternalError ( Box :: new ( err) ) )
303- . unwrap ( ) ;
304- distributor_cache
305- . insert ( distributor. distributor_pubkey . clone ( ) , distributor_data) ;
306- }
307- None => {
308- println ! (
309- "Error in gma for distributor: {}" ,
310- distributor. distributor_pubkey
311- ) ;
289+
290+ // Retry logic for network errors
291+ let mut retry_count = 0 ;
292+ const MAX_RETRIES : u32 = 3 ;
293+ const RETRY_DELAY : Duration = Duration :: from_secs ( 2 ) ;
294+
295+ loop {
296+ match rpc_client
297+ . get_multiple_accounts_with_commitment ( & distributor_keys, CommitmentConfig :: confirmed ( ) )
298+ . await
299+ {
300+ Ok ( accounts) => {
301+ println ! (
302+ "Hydrating distributor cache ({} accounts)" ,
303+ accounts. value. len( )
304+ ) ;
305+ for ( index, account) in accounts. value . into_iter ( ) . enumerate ( ) {
306+ let distributor = distributors_to_load. get ( index) . unwrap ( ) ;
307+ match account {
308+ Some ( account) => {
309+ let distributor_data =
310+ MerkleDistributor :: try_deserialize ( & mut account. data . as_slice ( ) )
311+ . map_err ( |err| ApiError :: InternalError ( Box :: new ( err) ) )
312+ . unwrap ( ) ;
313+ distributor_cache
314+ . insert ( distributor. distributor_pubkey . clone ( ) , distributor_data) ;
315+ }
316+ None => {
317+ println ! (
318+ "Error in gma for distributor: {}" ,
319+ distributor. distributor_pubkey
320+ ) ;
321+ }
312322 }
313323 }
324+ break ; // Success, exit retry loop
325+ }
326+ Err ( e) => {
327+ retry_count += 1 ;
328+ println ! ( "Error in distributor gma (attempt {}/{}): {:?}" , retry_count, MAX_RETRIES , e) ;
329+
330+ if retry_count >= MAX_RETRIES {
331+ println ! ( "Max retries reached for distributor cache update. Skipping this cycle." ) ;
332+ break ;
333+ }
334+
335+ // Check if it's a network error that's worth retrying
336+ let error_string = format ! ( "{:?}" , e) ;
337+ if error_string. contains ( "IncompleteMessage" ) ||
338+ error_string. contains ( "timeout" ) ||
339+ error_string. contains ( "connection" ) {
340+ println ! ( "Retrying after {} seconds..." , RETRY_DELAY . as_secs( ) ) ;
341+ tokio:: time:: sleep ( RETRY_DELAY ) . await ;
342+ } else {
343+ // Non-retriable error, exit
344+ break ;
345+ }
314346 }
315- }
316- Err ( e) => {
317- println ! ( "Error in distributor gma: {:?}" , e) ;
318347 }
319348 }
320349 }
0 commit comments