diff --git a/src/main.rs b/src/main.rs index b633844..0c5dd0e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,6 +42,8 @@ use { path::PathBuf, process::exit, str::FromStr, + thread::sleep, + time::Duration, }, sys::{ app_version, @@ -125,6 +127,25 @@ async fn get_block_date_and_price( )) } +async fn retry_get_block_date_and_price( + rpc_client: &RpcClient, + slot: Slot, + token: MaybeToken, +) -> Result<(NaiveDate, Decimal), Box> { + const NUM_RETRIES: usize = 20; + for _ in 1..NUM_RETRIES { + let date_price = get_block_date_and_price(rpc_client, slot, token).await; + if date_price.is_ok() { + println!("Got block date and price"); + return date_price; + } + println!("Retry get_block_date_and_price"); + //emprically observed cool down period is ~14s + sleep(Duration::from_secs(5)); + } + get_block_date_and_price(rpc_client, slot, token).await +} + fn add_exchange_deposit_address_to_db( db: &mut Db, exchange: Exchange, @@ -3438,9 +3459,19 @@ async fn process_account_sync( account.last_update_balance += inflation_reward.amount; let slot = inflation_reward.effective_slot; + /*let (when, price); + loop { + let res = get_block_date_and_price(rpc_client, slot, account.token).await; + if let Ok(res) = res { + println!("Got block date and price"); + (when, price) = res; + break; + } + println!("Retry block date and price"); + sleep(Duration::from_secs(10)); // emprirically obtained constant + }*/ let (when, price) = - get_block_date_and_price(rpc_client, slot, account.token).await?; - + retry_get_block_date_and_price(rpc_client, slot, account.token).await?; let lot = Lot { lot_number: db.next_lot_number(), acquisition: LotAcquistion::new(