Skip to content

Commit

Permalink
enable more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mschneider committed Nov 7, 2024
1 parent 56340af commit 5149b58
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 34 deletions.
10 changes: 6 additions & 4 deletions bin/autobahn-router/src/dex/generic/generic_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ pub async fn build_dex_internal(
let edges_per_pk_src = dex.edges_per_pk();
let mut edges_per_pk = HashMap::new();

info!("build_dex_internal {} enabled={enabled} add_mango_tokens={add_mango_tokens} take_all_mints={take_all_mints} mints={mints:?}", dex.name());
info!("dex {} enabled={enabled} add_mango_tokens={add_mango_tokens} take_all_mints={take_all_mints} mints={mints:?} edges={}", dex.name(), edges_per_pk_src.len());

for (key, edges) in edges_per_pk_src {
trace!("build_dex_internal key={key:?} edges={}", edges.len());
for (key, edge_ids) in edges_per_pk_src {

let edges = edges
let edges = edge_ids.clone()
.into_iter()
.filter(|x| {
let keep = take_all_mints
Expand All @@ -69,6 +68,9 @@ pub async fn build_dex_internal(
})
})
.collect_vec();

trace!("build_dex_internal key={key:?} edge_ids={} edges={}", edge_ids.len(), edges.len());

if edges.len() > 0 {
edges_per_pk.insert(key, edges);
}
Expand Down
2 changes: 1 addition & 1 deletion bin/autobahn-router/src/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl Edge {
let Some(price) = price_cache.price_ui(self.input_mint) else {
let mut state = self.state.write().unwrap();
state.is_valid = false;
info!("update_internal no price for {}", self.input_mint);
// info!("update_internal no price for {}", self.input_mint);
return;
};

Expand Down
20 changes: 13 additions & 7 deletions bin/autobahn-router/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ impl Routing {
bail!(RoutingError::UnsupportedOutputMint(output_mint.clone()));
};

trace!(
info!(
input_index = input_index.idx_raw(),
output_index = output_index.idx_raw(),
max_path_length,
Expand All @@ -1270,13 +1270,15 @@ impl Routing {
.map(|paths| self.lookup_edge_index_paths(paths.iter()));

if (p1.is_none() && p2.is_none()) || ignore_cache {
info!("no cache");
None
} else {
let cached_paths = p1
.unwrap_or(vec![])
.into_iter()
.chain(p2.unwrap_or(vec![]).into_iter())
.collect_vec();
info!("cached {}", cached_paths.len());
Some(cached_paths)
}
};
Expand Down Expand Up @@ -1394,9 +1396,9 @@ impl Routing {
}

// Debug
if tracing::event_enabled!(Level::TRACE) {
if true {
for (path, out_amount, out_amount_dumb) in &path_and_output {
trace!(
info!(
"potential path: [out={}] [dumb={}] {}",
out_amount,
out_amount_dumb,
Expand Down Expand Up @@ -1451,7 +1453,7 @@ impl Routing {
let price_impact = expected_ratio / actual_ratio * 10_000.0 - 10_000.0;
let price_impact_bps = price_impact.round() as u64;

trace!(
info!(
price_impact_bps,
out_amount_for_small_amount,
out_amount_for_request,
Expand Down Expand Up @@ -1487,7 +1489,7 @@ impl Routing {
}

if self.overquote > 0.0 {
debug!(
info!(
actual_in_amount,
actual_out_amount,
overquote_in_amount,
Expand All @@ -1502,6 +1504,7 @@ impl Routing {
let accounts = self
.capture_accounts(chain_data, &out_path, original_amount)
.ok();


return Ok(Route {
input_mint: *input_mint,
Expand Down Expand Up @@ -1547,16 +1550,19 @@ impl Routing {
output_index: MintNodeIndex,
used_cached_paths: bool,
) -> anyhow::Result<Route> {


info!("failsafe triggered");
// It is possible for cache path to became invalid after some account write or failed tx (cooldown)
// If we used cache but can't find any valid path, try again without the cache
let can_try_one_more_hop = max_path_length != self.max_path_length;
if !ignore_cache && (used_cached_paths || can_try_one_more_hop) {
if used_cached_paths {
debug!("Invalid cached path, retrying without cache");
info!("Invalid cached path, retrying without cache");
let mut cache = self.path_discovery_cache.write().unwrap();
cache.invalidate(input_index, output_index, max_accounts);
} else {
debug!("No path within boundaries, retrying with +1 hop");
info!("No path within boundaries, retrying with +1 hop");
}
return self.find_best_route(
chain_data,
Expand Down
22 changes: 22 additions & 0 deletions bin/autobahn-router/src/server/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ impl HttpServer {
swap_mode,
)?;

info!("best route found");

let (bytes, accounts_count) = Self::build_swap_tx(
address_lookup_table_addresses.clone(),
hash_provider.clone(),
Expand All @@ -184,6 +186,9 @@ impl HttpServer {
)
.await?;

info!("tx encoded");


let tx_size = bytes.len();
if accounts_count <= MAX_ACCOUNTS_PER_TX && tx_size < MAX_TX_SIZE {
break Ok(route_candidate);
Expand All @@ -197,6 +202,8 @@ impl HttpServer {
}
};

info!("quote -> err ? {}", route.is_err());

let route: Route = route?;

Self::log_repriced_amount(live_account_provider, reprice_probability, &route);
Expand All @@ -209,6 +216,8 @@ impl HttpServer {
.floor() as u64
};

info!("serialize plan");

let route_plan = route
.steps
.iter()
Expand All @@ -227,6 +236,9 @@ impl HttpServer {
})
.collect_vec();

info!("encode accounts");


let accounts = match route.accounts {
None => None,
Some(a) => Some(
Expand Down Expand Up @@ -368,6 +380,8 @@ impl HttpServer {
) -> Result<(Vec<u8>, usize), AppError> {
let wallet_pk = Pubkey::from_str(&wallet_pk)?;

info!("build_ixs");

let ixs = ix_builder.build_ixs(
&wallet_pk,
route_plan,
Expand All @@ -383,6 +397,8 @@ impl HttpServer {
ComputeBudgetInstruction::set_compute_unit_limit(ixs.cu_estimate),
];

info!("serialize ixs");

let transaction_addresses = ixs.accounts().into_iter().collect();
let instructions = compute_budget_ixs
.into_iter()
Expand All @@ -391,11 +407,16 @@ impl HttpServer {
.chain(ixs.cleanup_instructions.into_iter())
.collect_vec();


info!("load alts");
let all_alts = Self::load_all_alts(address_lookup_table_addresses, alt_provider).await;
info!("optimize alts");
let alts = alt_optimizer::get_best_alt(&all_alts, &transaction_addresses)?;
let accounts = transaction_addresses.iter().unique().count()
+ alts.iter().map(|x| x.key).unique().count();

info!("compile message");

let v0_message = solana_sdk::message::v0::Message::try_compile(
&wallet_pk,
instructions.as_slice(),
Expand All @@ -405,6 +426,7 @@ impl HttpServer {

let message = VersionedMessage::V0(v0_message);
let tx = VersionedTransaction::try_new(message, &[&NullSigner::new(&wallet_pk)])?;
info!("serialize message");
let bytes = bincode::serialize(&tx)?;

Ok((bytes, accounts))
Expand Down
9 changes: 5 additions & 4 deletions bin/autobahn-router/src/source/grpc_plugin_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,11 @@ async fn process_account_updated_from_sources(
metrics::GRPC_SNAPSHOT_ACCOUNT_WRITES.inc();
metrics::GRPC_ACCOUNT_WRITE_QUEUE.set(account_write_queue_sender.len() as i64);

if !filters.contains(&account.pubkey) {
continue;
}

// if !filters.contains(&account.pubkey) && update.program_id.is_none() {
// info!("filtered account {:?}", account.pubkey);
// continue;
// }

updated_accounts.push(account);
}
account_write_queue_sender
Expand Down
28 changes: 10 additions & 18 deletions lib/dex-invariant/src/invariant_dex.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{
collections::{HashMap, HashSet},
sync::Arc,
collections::{HashMap, HashSet}, str::FromStr, sync::Arc
};

use anchor_lang::{AnchorDeserialize, Id};

Check warning on line 5 in lib/dex-invariant/src/invariant_dex.rs

View workflow job for this annotation

GitHub Actions / Router full build

unused import: `Id`
Expand All @@ -15,6 +14,7 @@ use invariant_types::{
structs::{Pool, Tick, Tickmap, TickmapView, TICK_CROSSES_PER_IX, TICK_LIMIT},
ANCHOR_DISCRIMINATOR_SIZE, TICK_SEED,
};
use itertools::Itertools;
use router_feed_lib::router_rpc_client::{RouterRpcClient, RouterRpcClientTrait};
use router_lib::dex::{
AccountProviderView, DexEdge, DexEdgeIdentifier, DexInterface, DexSubscriptionMode, Quote,
Expand All @@ -26,7 +26,7 @@ use solana_client::{
rpc_filter::RpcFilterType,
};
use solana_sdk::{account::ReadableAccount, program_pack::Pack, pubkey::Pubkey};
use tracing::{error, info};
use tracing::{debug, error, info};

use crate::{
invariant_edge::{InvariantEdge, InvariantEdgeIdentifier, InvariantSimulationParams},
Expand Down Expand Up @@ -256,15 +256,11 @@ impl DexInterface for InvariantDex {
.map(|(pk, _)| pk)
.collect::<HashSet<_>>();

info!("Number of banned Invariant reserves {}", banned_reserves.len());

pools.retain(|p| {
!(banned_reserves.contains(&p.1.token_x_reserve)
|| banned_reserves.contains(&p.1.token_y_reserve))
});

info!("Number of Invariant Pools: {:?}", pools.len());

let edge_pairs: Vec<(Arc<InvariantEdgeIdentifier>, Arc<InvariantEdgeIdentifier>)> = pools
.iter()
.map(|(pool_pk, pool)| {
Expand Down Expand Up @@ -297,6 +293,7 @@ impl DexInterface for InvariantDex {
{
let entry: Vec<Arc<dyn DexEdgeIdentifier>> =
vec![edge_x_to_y.clone(), edge_y_to_x.clone()];

map.insert(*pool_pk, entry.clone());
map.insert(*tickmap_pk, entry.clone());

Expand All @@ -311,6 +308,8 @@ impl DexInterface for InvariantDex {
};

info!("inv init done");
let poolpk = Pubkey::from_str("G8Skt6kgqVL9ocYn4aYVGs3gUg8EfQrTJAkA2qt3gcs8").unwrap();
info!("pool edges: {:?}", edges_per_pk.get(&poolpk).map(|ids| ids.iter().map(|id| vec![id.input_mint(), id.output_mint()]).collect_vec()));


Ok(Arc::new(InvariantDex {
Expand Down Expand Up @@ -343,10 +342,9 @@ impl DexInterface for InvariantDex {
.as_any()
.downcast_ref::<InvariantEdgeIdentifier>()
.unwrap();
let edge = Self::load_edge(id, chain_data)?;

info!("load edge with id={id:?} -> {edge:?}");
Ok(Arc::new(edge))
let edge: Result<InvariantEdge, anyhow::Error> = Self::load_edge(id, chain_data);
debug!("load edge with id={id:?} -> {edge:?}");
Ok(Arc::new(edge?))
}

fn quote(
Expand All @@ -368,9 +366,6 @@ impl DexInterface for InvariantDex {
} else {
calculate_price_sqrt(get_max_tick(edge.pool.tick_spacing)?)
};

info!("quote edge with id={id:?} amount={in_amount} -> {edge:?}");


let simulation = edge
.simulate_invariant_swap(&InvariantSimulationParams {
Expand All @@ -379,14 +374,11 @@ impl DexInterface for InvariantDex {
sqrt_price_limit,
by_amount_in: true,
})
.map_err(|e| { error!("quote id={id:?} error: {:?}", e); anyhow::format_err!(e) })
.map_err(|e| { debug!("quote id={id:?} error: {:?}", e); anyhow::format_err!(e) })
.with_context(|| format!("pool {} x_to_y {}", id.pool, id.x_to_y))?;

let fee_mint = if x_to_y { id.token_x } else { id.token_y };

info!("quote edge with id={id:?} amount={in_amount} -> {simulation:?}");


Ok(Quote {
in_amount: simulation.in_amount,
out_amount: simulation.out_amount,
Expand Down
1 change: 1 addition & 0 deletions lib/dex-invariant/src/invariant_ix_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use sha2::{Digest, Sha256};
use solana_program::instruction::Instruction;
use solana_program::pubkey::Pubkey;
use solana_sdk::account::ReadableAccount;
use tracing::info;

pub fn build_swap_ix(
id: &InvariantEdgeIdentifier,
Expand Down

0 comments on commit 5149b58

Please sign in to comment.