Skip to content

Commit

Permalink
feat: add retry logic on rpc calls, remove unnecessary deps, fix warn…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
wiseaidev committed Jun 5, 2024
1 parent c0cf159 commit 75c5ec4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
14 changes: 13 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions lib/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cargo-features = ["workspace-inheritance"]

[package]
edition = "2021"
name = "openbook-v2-client"
Expand All @@ -21,7 +19,6 @@ async-channel = "1.6"
async-once-cell = {version = "0.4.2", features = ["unpin"]}
async-trait = "0.1.52"
base64 = "0.13.0"
bincode = "1.3.3"
fixed = {workspace = true, features = ["serde", "borsh"]}
futures = "0.3.25"
itertools = "0.10.3"
Expand All @@ -45,6 +42,7 @@ thiserror = "1.0.31"
tokio = {version = "1", features = ["full"]}
tokio-stream = {version = "0.1.9"}
jupiter-amm-interface = "0.1.1"
backon = "0.4.4"

[dev-dependencies]
solana-program-test = { workspace = true }
23 changes: 17 additions & 6 deletions lib/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ use solana_sdk::instruction::Instruction;
use solana_sdk::signature::{Keypair, Signature};
use solana_sdk::{commitment_config::CommitmentConfig, pubkey::Pubkey, signer::Signer};

use backon::ExponentialBuilder;
use backon::Retryable;

// very close to anchor_client::Client, which unfortunately has no accessors or Clone
#[derive(Clone, Debug)]
pub struct Client {
Expand Down Expand Up @@ -744,18 +747,26 @@ impl<'a> TransactionBuilder<'a> {
pub async fn send(self, client: &Client) -> anyhow::Result<Signature> {
let rpc = client.rpc_async();
let tx = self.transaction(&rpc).await?;
rpc.send_transaction_with_config(&tx, client.rpc_send_transaction_config)
.await
.map_err(prettify_solana_client_error)
(|| async {
rpc.send_transaction_with_config(&tx, client.rpc_send_transaction_config)
.await
.map_err(prettify_solana_client_error)
})
.retry(&ExponentialBuilder::default())
.await
}

pub async fn send_and_confirm(self, client: &Client) -> anyhow::Result<Signature> {
let rpc = client.rpc_async();
let tx = self.transaction(&rpc).await?;
// TODO: Wish we could use client.rpc_send_transaction_config here too!
rpc.send_and_confirm_transaction(&tx)
.await
.map_err(prettify_solana_client_error)
(|| async {
rpc.send_and_confirm_transaction(&tx)
.await
.map_err(prettify_solana_client_error)
})
.retry(&ExponentialBuilder::default())
.await
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/client/src/jup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Amm for OpenBookMarket {
EventHeap::try_deserialize_from_slice(&mut event_heap_data.data.as_slice()).unwrap();

let clock_data = account_map.get(&clock::ID).unwrap();
let clock: Clock = bincode::deserialize(clock_data.data.as_slice())?;
let clock: Clock = serde_json::from_slice(clock_data.data.as_slice())?;

let oracle_acc =
|nonzero_pubkey: NonZeroPubkeyOption| -> Option<accounts_zerocopy::KeyedAccount> {
Expand Down
2 changes: 0 additions & 2 deletions programs/openbook-v2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cargo-features = ["workspace-inheritance"]

[package]
description = "Created with Anchor"
edition = "2021"
Expand Down

0 comments on commit 75c5ec4

Please sign in to comment.