Skip to content

Commit

Permalink
fix compiler error (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil Acharya authored Jun 5, 2023
1 parent 2c453f6 commit 7d9bb2b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
10 changes: 5 additions & 5 deletions tools/acc_forwarder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use {
},
std::{collections::HashSet, env, str::FromStr, sync::Arc},
tokio::sync::Mutex,
txn_forwarder::{find_signatures, read_lines, rpc_send_with_retries},
txn_forwarder::{find_signatures, read_lines, rpc_tx_with_retries},
};

#[derive(Parser)]
Expand Down Expand Up @@ -146,7 +146,7 @@ async fn main() -> anyhow::Result<()> {
let collection = Pubkey::from_str(&collection)
.with_context(|| format!("failed to parse collection {collection}"))?;
let stream = Arc::new(Mutex::new(find_signatures(
collection, client, None, None, 2_000,
collection, client, None, None, 2_000, false,
)));

try_join_all((0..concurrency).map(|_| {
Expand Down Expand Up @@ -210,7 +210,7 @@ async fn collection_get_tx_info(
max_supported_transaction_version: Some(u8::MAX),
};

let tx: EncodedConfirmedTransactionWithStatusMeta = rpc_send_with_retries(
let tx: EncodedConfirmedTransactionWithStatusMeta = rpc_tx_with_retries(
client,
RpcRequest::GetTransaction,
serde_json::json!([signature.to_string(), CONFIG]),
Expand Down Expand Up @@ -306,7 +306,7 @@ async fn fetch_metadata_and_send_accounts(

// returns largest (NFT related) token account belonging to mint
async fn get_token_largest_account(client: &RpcClient, mint: Pubkey) -> anyhow::Result<Pubkey> {
let response: RpcResponse<Vec<RpcTokenAccountBalance>> = rpc_send_with_retries(
let response: RpcResponse<Vec<RpcTokenAccountBalance>> = rpc_tx_with_retries(
client,
RpcRequest::Custom {
method: "getTokenLargestAccounts",
Expand Down Expand Up @@ -335,7 +335,7 @@ async fn fetch_account(pubkey: Pubkey, client: &RpcClient) -> anyhow::Result<(Ac
min_context_slot: None,
};

let response: RpcResponse<Option<UiAccount>> = rpc_send_with_retries(
let response: RpcResponse<Option<UiAccount>> = rpc_tx_with_retries(
client,
RpcRequest::GetAccountInfo,
serde_json::json!([pubkey.to_string(), CONFIG]),
Expand Down
6 changes: 3 additions & 3 deletions tools/tree-status/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use {
io::{stdout, AsyncWrite, AsyncWriteExt},
sync::{mpsc, Mutex},
},
txn_forwarder::{find_signatures, read_lines, rpc_send_with_retries},
txn_forwarder::{find_signatures, read_lines, rpc_tx_with_retries},
};

const RPC_GET_TXN_RETRIES: u8 = 5;
Expand Down Expand Up @@ -534,7 +534,7 @@ async fn send_txn(
client: &RpcClient,
messenger: &Mutex<Box<dyn plerkle_messenger::Messenger>>,
) -> anyhow::Result<()> {
let txn = rpc_send_with_retries(
let txn: EncodedConfirmedTransactionWithStatusMeta = rpc_tx_with_retries(
&client,
RpcRequest::GetTransaction,
serde_json::json!([signature.to_string(), RPC_TXN_CONFIG,]),
Expand Down Expand Up @@ -927,7 +927,7 @@ async fn process_tx(
max_supported_transaction_version: Some(0),
};

let tx: EncodedConfirmedTransactionWithStatusMeta = rpc_send_with_retries(
let tx: EncodedConfirmedTransactionWithStatusMeta = rpc_tx_with_retries(
client,
RpcRequest::GetTransaction,
serde_json::json!([signature.to_string(), CONFIG]),
Expand Down
32 changes: 32 additions & 0 deletions tools/txn_forwarder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use {
log::{debug, error, info},
plerkle_messenger::TRANSACTION_STREAM,
plerkle_serialization::serializer::seralize_encoded_transaction_with_status,
serde::de::DeserializeOwned,
solana_client::client_error::Result as RpcClientResult,
solana_client::{
client_error::ClientError, nonblocking::rpc_client::RpcClient,
rpc_client::GetConfirmedSignaturesForAddress2Config,
Expand Down Expand Up @@ -114,6 +116,36 @@ pub fn find_signatures(
rx
}

pub async fn rpc_tx_with_retries<T, E>(
client: &RpcClient,
request: RpcRequest,
value: serde_json::Value,
max_retries: u8,
error_key: E,
) -> RpcClientResult<T>
where
T: DeserializeOwned,
E: fmt::Debug,
{
let mut retries = 0;
let mut delay = Duration::from_millis(500);
loop {
match client.send(request, value.clone()).await {
Ok(value) => return Ok(value),
Err(error) => {
if retries < max_retries {
error!("retrying {request} {error_key:?}: {error}");
sleep(delay).await;
delay *= 2;
retries += 1;
} else {
return Err(error);
}
}
}
}
}

pub async fn rpc_send_with_retries(
client: &RpcClient,
request: RpcRequest,
Expand Down

0 comments on commit 7d9bb2b

Please sign in to comment.