Skip to content

Commit

Permalink
adding fixes to run autobahn on eclipse
Browse files Browse the repository at this point in the history
  • Loading branch information
godmodegalactus committed Nov 5, 2024
1 parent 2a409c7 commit 5db0946
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 16 deletions.
15 changes: 11 additions & 4 deletions lib/dex-orca/src/orca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,17 @@ pub async fn fetch_all_whirlpools(
.await?;
let result = whirlpools
.iter()
.map(|account| {
let whirlpool: Whirlpool =
AnchorDeserialize::deserialize(&mut &account.data[8..]).unwrap();
(account.pubkey, whirlpool)
.filter_map(|account| {
let pubkey = account.pubkey;
let whirlpool: Result<Whirlpool, std::io::Error> =
AnchorDeserialize::deserialize(&mut &account.data[8..]);
match whirlpool {
Ok(whirlpool) => Some((account.pubkey, whirlpool)),
Err(e) => {
error!("Error deserializing whirlpool account : {pubkey:?} error: {e:?}");
None
}
}
})
.collect_vec();
Ok(result)
Expand Down
14 changes: 11 additions & 3 deletions lib/dex-orca/src/orca_dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;

use anchor_lang::Id;
use anchor_spl::token::spl_token;
use anchor_spl::token::spl_token::state::AccountState;
use anchor_spl::token::spl_token::state::{Account, AccountState};
use anchor_spl::token_2022::Token2022;
use anyhow::Context;
use itertools::Itertools;
Expand Down Expand Up @@ -229,7 +229,12 @@ impl OrcaDex {
.iter()
.filter(|x| {
x.1.owner == Token2022::id()
|| spl_token::state::Account::unpack(x.1.data()).unwrap().state
|| spl_token::state::Account::unpack(x.1.data())
.unwrap_or(Account {
state: AccountState::Frozen,
..Default::default()
})
.state
== AccountState::Frozen
})
.map(|x| x.0)
Expand All @@ -246,7 +251,10 @@ impl OrcaDex {
// TODO: actually need to dynamically adjust subscriptions based on the tick?
let tick_arrays = filtered_pools
.iter()
.map(|(pk, wp)| whirlpool_tick_array_pks(wp, pk, program_id))
.map(|(pk, wp)| {
println!("whirlpool : {pk}, {}", wp.tick_spacing);
whirlpool_tick_array_pks(wp, pk, program_id)
})
.collect_vec();

let edge_pairs = filtered_pools
Expand Down
10 changes: 10 additions & 0 deletions lib/dex-orca/tests/test_cropper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ use router_lib::test_tools::{generate_dex_rpc_dump, rpc};

#[tokio::test]
async fn test_dump_input_data_cropper() -> anyhow::Result<()> {
let is_eclipse = std::env::var("ECLIPSE")
.map(|x| {
let value: bool = x.parse().unwrap();
value
})
.unwrap_or_default();
if is_eclipse {
// crooper is not yet on eclipse
return Ok(());
}
let options = HashMap::from([
(
"program_id".to_string(),
Expand Down
41 changes: 41 additions & 0 deletions lib/router-feed-lib/src/get_program_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,47 @@ pub async fn get_compressed_program_account_rpc(
Ok((min_slot, snap_result))
}

// called on startup to get the required accounts, few calls with some 100 thousand accounts
#[tracing::instrument(skip_all, level = "trace")]
pub async fn get_uncompressed_program_account_rpc(
rpc_client: &RpcClient,
filters: &HashSet<Pubkey>,
config: RpcProgramAccountsConfig,
) -> anyhow::Result<(u64, Vec<AccountWrite>)> {
let slot = rpc_client.get_slot().await?;
let config = RpcProgramAccountsConfig {
with_context: Some(true),
account_config: RpcAccountInfoConfig {
encoding: Some(UiAccountEncoding::Base64),
min_context_slot: Some(slot),
commitment: config.account_config.commitment,
data_slice: config.account_config.data_slice,
},
filters: config.filters,
};

let mut snap_result = vec![];
let mut min_slot = u64::MAX;

// use getGPA compressed if available
for program_id in filters.iter() {
info!("gPA for {}", program_id);
min_slot = slot.min(min_slot);
let account_snapshot = rpc_client
.get_program_accounts_with_config(&program_id, config.clone())
.await
.map_err_anyhow()?;
tracing::log::debug!("gpa snapshot received {}", program_id);

let iter = account_snapshot.iter().map(|(pk, account)| {
account_write_from(*pk, slot, SNAP_ACCOUNT_WRITE_VERSION, account.clone())
});
snap_result.extend(iter);
}

Ok((min_slot, snap_result))
}

// called on startup to get the required accounts, few calls with some 100 thousand accounts
#[tracing::instrument(skip_all, level = "trace")]
pub async fn get_uncompressed_program_account(
Expand Down
26 changes: 20 additions & 6 deletions lib/router-feed-lib/src/router_rpc_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use solana_sdk::account::Account;
use solana_sdk::pubkey::Pubkey;

use crate::account_write::AccountWrite;
use crate::get_program_account::{fetch_multiple_accounts, get_compressed_program_account_rpc};
use crate::get_program_account::{
fetch_multiple_accounts, get_compressed_program_account_rpc,
get_uncompressed_program_account_rpc,
};
use crate::router_rpc_client::RouterRpcClientTrait;

pub struct RouterRpcWrapper {
Expand Down Expand Up @@ -52,10 +55,21 @@ impl RouterRpcClientTrait for RouterRpcWrapper {
pubkey: &Pubkey,
config: RpcProgramAccountsConfig,
) -> anyhow::Result<Vec<AccountWrite>> {
Ok(
get_compressed_program_account_rpc(&self.rpc, &HashSet::from([*pubkey]), config)
.await?
.1,
)
let disable_compressed = std::env::var::<String>("DISABLE_COMRPESSED_GPA".to_string())
.unwrap_or("false".to_string());
let disable_compressed: bool = disable_compressed.trim().parse().unwrap();
if disable_compressed {
Ok(
get_uncompressed_program_account_rpc(&self.rpc, &HashSet::from([*pubkey]), config)
.await?
.1,
)
} else {
Ok(
get_compressed_program_account_rpc(&self.rpc, &HashSet::from([*pubkey]), config)
.await?
.1,
)
}
}
}
1 change: 0 additions & 1 deletion lib/router-lib/src/dex/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ pub trait DexInterface: Sync + Send {
/// simulation tests.
fn program_ids(&self) -> HashSet<Pubkey>;


/// Initializes an Edge from ChainData (production) or BanksClient (test).
/// The Edge will be dropped once a new Edge for the same EdgeIndentifier
/// has been initialized. After calling initialize the DexInterface needs
Expand Down
2 changes: 1 addition & 1 deletion lib/router-lib/src/test_tools/generate_dex_rpc_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub async fn run_dump_swap_ix_with_custom_amount(
continue;
};

debug!(
println!(
"#{} || quote: {} => {} : {} => {}",
success,
id.input_mint(),
Expand Down
4 changes: 3 additions & 1 deletion scripts/smoke-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export DUMP_MAINNET_DATA=1 RUST_LOG=info

# define in addition
# RPC_HTTP_URL="http://fcs-ams1._peer.internal:18899"

# for eclipse
# export ECLIPSE=true
# export DISABLE_COMRPESSED_GPA=true

# saber
DUMP_SABER_START=$(date)
Expand Down

0 comments on commit 5db0946

Please sign in to comment.