Skip to content

Commit

Permalink
[pipelines] init settlement fails to load created accounts from chain…
Browse files Browse the repository at this point in the history
…, trying to address the issue
  • Loading branch information
ochaloup committed Oct 15, 2024
1 parent 6a21952 commit 8d84eb5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
29 changes: 28 additions & 1 deletion common-rs/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use anchor_client::anchor_lang::AccountDeserialize;
use anyhow::anyhow;
use log::error;
use log::{debug, error};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_client::rpc_config::RpcAccountInfoConfig;

use solana_program::pubkey::Pubkey;

use solana_sdk::account::Account;
use std::sync::Arc;
use tokio::time::sleep;

pub async fn get_account_infos_for_pubkeys(
rpc_client: Arc<RpcClient>,
Expand Down Expand Up @@ -60,3 +61,29 @@ pub async fn get_accounts_for_pubkeys<T: AccountDeserialize>(
})
.collect())
}

pub async fn try_get_all_account_infos_for_pubkeys(
rpc_client: Arc<RpcClient>,
pubkeys: &[Pubkey],
retry_count: usize,
) -> anyhow::Result<Vec<(Pubkey, Option<Account>)>> {
let mut counter: usize = 0;
let accounts = loop {
let accounts = get_account_infos_for_pubkeys(rpc_client.clone(), pubkeys).await?;
counter += 1;
if accounts.iter().all(|(_, account)| account.is_some()) {
break accounts;
}
if counter > retry_count {
debug!(
"Retry limit {} reached while trying to fetch all provided pubkeys, expected length: {}, actual length: {}",
retry_count,
pubkeys.len(),
accounts.iter().filter(|(_, account)| account.is_some()).count()
);
break accounts;
}
sleep(std::time::Duration::from_secs((counter * 2) as u64)).await;
};
Ok(accounts)
}
11 changes: 4 additions & 7 deletions settlement-pipelines/src/bin/init_settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use settlement_pipelines::json_data::{
use settlement_pipelines::reporting::{with_reporting, PrintReportable, ReportHandler};
use settlement_pipelines::reporting_data::SettlementsReportData;
use settlement_pipelines::settlement_data::SettlementRecord;
use settlement_pipelines::FINALIZATION_WAIT_TIMEOUT;
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::native_token::lamports_to_sol;
use solana_sdk::pubkey::Pubkey;
Expand All @@ -31,13 +30,13 @@ use std::future::Future;
use std::path::PathBuf;
use std::pin::Pin;
use std::sync::Arc;
use tokio::time::sleep;

use validator_bonds::instructions::InitSettlementArgs;
use validator_bonds::state::settlement::find_settlement_claims_address;
use validator_bonds::ID as validator_bonds_id;
use validator_bonds_common::constants::find_event_authority;
use validator_bonds_common::settlements::get_settlements_for_pubkeys;
use validator_bonds_common::utils::get_account_infos_for_pubkeys;
use validator_bonds_common::utils::try_get_all_account_infos_for_pubkeys;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand Down Expand Up @@ -138,9 +137,6 @@ async fn real_main(reporting: &mut ReportHandler<InitSettlementReport>) -> anyho
)
.await?;

// waiting for data finalization on-chain
sleep(FINALIZATION_WAIT_TIMEOUT).await;

upsize_settlements(
&program,
rpc_client.clone(),
Expand Down Expand Up @@ -324,7 +320,8 @@ async fn upsize_settlements(
.map(|(settlement_address, _)| find_settlement_claims_address(settlement_address).0)
.collect::<Vec<Pubkey>>();
let settlement_claims_infos =
get_account_infos_for_pubkeys(rpc_client.clone(), &settlement_claims_pubkeys).await?;
try_get_all_account_infos_for_pubkeys(rpc_client.clone(), &settlement_claims_pubkeys, 5)
.await?;

for (
(settlement_claims_address, settlement_claims_info),
Expand Down

0 comments on commit 8d84eb5

Please sign in to comment.