Adding config to support config and using env variable for tests and … (#45)
* Adding config to support config and using env variable for tests and value from file for others * avoid passing enable compression everywhere * avoiding adding environment variable everywhere
This commit is contained in:
parent
6608fc804a
commit
05f6125440
|
@ -235,10 +235,13 @@ async fn main() -> anyhow::Result<()> {
|
|||
);
|
||||
cropper.insert("program_name".to_string(), "Cropper".to_string());
|
||||
|
||||
let gpa_compression_enabled = source_config.rpc_support_compression.unwrap_or_default();
|
||||
let mut router_rpc = RouterRpcClient {
|
||||
rpc: Box::new(RouterRpcWrapper {
|
||||
rpc: build_rpc(&source_config),
|
||||
gpa_compression_enabled,
|
||||
}),
|
||||
gpa_compression_enabled,
|
||||
};
|
||||
|
||||
let dexs: Vec<Dex> = [
|
||||
|
@ -267,7 +270,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
&config.saber.mints
|
||||
),
|
||||
dex::generic::build_dex!(
|
||||
dex_raydium_cp::RaydiumCpDex::initialize(&mut router_rpc, HashMap::new()).await?,
|
||||
dex_raydium_cp::RaydiumCpDex::initialize(&mut router_rpc, HashMap::new(),).await?,
|
||||
&mango_data,
|
||||
config.raydium_cp.enabled,
|
||||
config.raydium_cp.add_mango_tokens,
|
||||
|
@ -275,7 +278,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
&config.raydium_cp.mints
|
||||
),
|
||||
dex::generic::build_dex!(
|
||||
dex_raydium::RaydiumDex::initialize(&mut router_rpc, HashMap::new()).await?,
|
||||
dex_raydium::RaydiumDex::initialize(&mut router_rpc, HashMap::new(),).await?,
|
||||
&mango_data,
|
||||
config.raydium.enabled,
|
||||
config.raydium.add_mango_tokens,
|
||||
|
@ -283,7 +286,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
&config.raydium.mints
|
||||
),
|
||||
dex::generic::build_dex!(
|
||||
dex_openbook_v2::OpenbookV2Dex::initialize(&mut router_rpc, HashMap::new()).await?,
|
||||
dex_openbook_v2::OpenbookV2Dex::initialize(&mut router_rpc, HashMap::new(),).await?,
|
||||
&mango_data,
|
||||
config.openbook_v2.enabled,
|
||||
config.openbook_v2.add_mango_tokens,
|
||||
|
@ -291,7 +294,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
&config.openbook_v2.mints
|
||||
),
|
||||
dex::generic::build_dex!(
|
||||
dex_infinity::InfinityDex::initialize(&mut router_rpc, HashMap::new()).await?,
|
||||
dex_infinity::InfinityDex::initialize(&mut router_rpc, HashMap::new(),).await?,
|
||||
&mango_data,
|
||||
config.infinity.enabled,
|
||||
false,
|
||||
|
@ -299,7 +302,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
&vec![]
|
||||
),
|
||||
dex::generic::build_dex!(
|
||||
dex_invariant::InvariantDex::initialize(&mut router_rpc, HashMap::new()).await?,
|
||||
dex_invariant::InvariantDex::initialize(&mut router_rpc, HashMap::new(),).await?,
|
||||
&mango_data,
|
||||
config.invariant.enabled,
|
||||
config.invariant.take_all_mints,
|
||||
|
|
|
@ -30,6 +30,7 @@ pub async fn get_all_dex(
|
|||
dex_raydium::RaydiumDex::initialize(&mut rpc_client, HashMap::new()).await?,
|
||||
dex_openbook_v2::OpenbookV2Dex::initialize(&mut rpc_client, HashMap::new()).await?,
|
||||
dex_infinity::InfinityDex::initialize(&mut rpc_client, HashMap::new()).await?,
|
||||
dex_invariant::InvariantDex::initialize(&mut rpc_client, HashMap::new()).await?,
|
||||
];
|
||||
|
||||
Ok(dexs.into_iter().collect())
|
||||
|
|
|
@ -9,7 +9,6 @@ use solana_program::pubkey::Pubkey;
|
|||
use solana_sdk::clock::Clock;
|
||||
use solana_sdk::instruction::AccountMeta;
|
||||
use solana_sdk::sysvar::SysvarId;
|
||||
use std::str::FromStr;
|
||||
|
||||
pub const INCLUDED_MAKERS_COUNT: usize = 2;
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ use solana_program_test::tokio;
|
|||
#[tokio::test]
|
||||
async fn test_dump_input_data_openbook_v2() -> anyhow::Result<()> {
|
||||
let options = HashMap::from([]);
|
||||
|
||||
if router_test_lib::config_should_dump_mainnet_data() {
|
||||
openbook_v2_step_1(&options).await?;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ async fn test_dump_input_data_orca() -> anyhow::Result<()> {
|
|||
("program_id".to_string(), whirlpools_client::ID.to_string()),
|
||||
("program_name".to_string(), "Orca".to_string()),
|
||||
]);
|
||||
|
||||
if router_test_lib::config_should_dump_mainnet_data() {
|
||||
orca_step_1(&options).await?;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ use router_lib::test_tools::{generate_dex_rpc_dump, rpc};
|
|||
#[tokio::test]
|
||||
async fn test_dump_input_data_raydium() -> anyhow::Result<()> {
|
||||
let options = HashMap::from([]);
|
||||
|
||||
if router_test_lib::config_should_dump_mainnet_data() {
|
||||
raydium_step_1(&options).await?;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ use yellowstone_grpc_proto::tonic::{
|
|||
use async_channel::Sender;
|
||||
use solana_sdk::signature::Signature;
|
||||
use std::time::Instant;
|
||||
use std::{collections::HashMap, env, str::FromStr, time::Duration};
|
||||
use std::{collections::HashMap, env, time::Duration};
|
||||
use tracing::*;
|
||||
|
||||
use yellowstone_grpc_proto::prelude::{
|
||||
|
|
|
@ -19,10 +19,13 @@ pub trait RouterRpcClientTrait: Sync + Send {
|
|||
pubkey: &Pubkey,
|
||||
config: RpcProgramAccountsConfig,
|
||||
) -> anyhow::Result<Vec<AccountWrite>>;
|
||||
|
||||
fn is_gpa_compression_enabled(&self) -> bool;
|
||||
}
|
||||
|
||||
pub struct RouterRpcClient {
|
||||
pub rpc: Box<dyn RouterRpcClientTrait + Send + Sync + 'static>,
|
||||
pub gpa_compression_enabled: bool,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
|
@ -47,4 +50,8 @@ impl RouterRpcClientTrait for RouterRpcClient {
|
|||
.get_program_accounts_with_config(pubkey, config)
|
||||
.await
|
||||
}
|
||||
|
||||
fn is_gpa_compression_enabled(&self) -> bool {
|
||||
self.gpa_compression_enabled
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ use crate::router_rpc_client::RouterRpcClientTrait;
|
|||
|
||||
pub struct RouterRpcWrapper {
|
||||
pub rpc: RpcClient,
|
||||
pub gpa_compression_enabled: bool,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
@ -55,21 +56,22 @@ impl RouterRpcClientTrait for RouterRpcWrapper {
|
|||
pubkey: &Pubkey,
|
||||
config: RpcProgramAccountsConfig,
|
||||
) -> anyhow::Result<Vec<AccountWrite>> {
|
||||
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 {
|
||||
if self.is_gpa_compression_enabled() {
|
||||
Ok(
|
||||
get_compressed_program_account_rpc(&self.rpc, &HashSet::from([*pubkey]), config)
|
||||
.await?
|
||||
.1,
|
||||
)
|
||||
} else {
|
||||
Ok(
|
||||
get_uncompressed_program_account_rpc(&self.rpc, &HashSet::from([*pubkey]), config)
|
||||
.await?
|
||||
.1,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn is_gpa_compression_enabled(&self) -> bool {
|
||||
self.gpa_compression_enabled
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,6 +79,10 @@ impl RouterRpcClientTrait for ReplayerRpcClient {
|
|||
None => anyhow::bail!("Invalid gpa"),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_gpa_compression_enabled(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
|
@ -150,6 +154,10 @@ impl RouterRpcClientTrait for DumpRpcClient {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_gpa_compression_enabled(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for DumpRpcClient {
|
||||
|
@ -159,6 +167,10 @@ impl Drop for DumpRpcClient {
|
|||
}
|
||||
|
||||
pub fn rpc_dumper_client(url: String, out_path: &str) -> (RouterRpcClient, ChainDataArcRw) {
|
||||
let disable_compressed_gpa =
|
||||
std::env::var::<String>("DISABLE_COMRPESSED_GPA".to_string()).unwrap_or("true".to_string());
|
||||
let gpa_compression_enabled: bool = !disable_compressed_gpa.trim().parse::<bool>().unwrap();
|
||||
|
||||
let chain_data = ChainDataArcRw::new(RwLock::new(ChainData::new()));
|
||||
let rpc_client = RouterRpcClient {
|
||||
rpc: Box::new(DumpRpcClient {
|
||||
|
@ -174,10 +186,13 @@ pub fn rpc_dumper_client(url: String, out_path: &str) -> (RouterRpcClient, Chain
|
|||
Duration::from_secs(60 * 20),
|
||||
CommitmentConfig::finalized(),
|
||||
),
|
||||
gpa_compression_enabled,
|
||||
}),
|
||||
gpa_compression_enabled,
|
||||
},
|
||||
path: out_path.to_string(),
|
||||
}),
|
||||
gpa_compression_enabled,
|
||||
};
|
||||
|
||||
(rpc_client, chain_data)
|
||||
|
@ -213,7 +228,10 @@ pub fn rpc_replayer_client(in_path: &str) -> (RouterRpcClient, ChainDataArcRw) {
|
|||
}
|
||||
|
||||
let rpc = ReplayerRpcClient { dump };
|
||||
let replayer = RouterRpcClient { rpc: Box::new(rpc) };
|
||||
let replayer = RouterRpcClient {
|
||||
rpc: Box::new(rpc),
|
||||
gpa_compression_enabled: false,
|
||||
};
|
||||
let chain_data = ChainDataArcRw::new(RwLock::new(chain_data));
|
||||
|
||||
(replayer, chain_data)
|
||||
|
|
|
@ -5,7 +5,7 @@ function pad () { [ "$#" -gt 1 ] && [ -n "$2" ] && printf "%$2.${2#-}s" "$1"; }
|
|||
|
||||
# env settings
|
||||
export DUMP_MAINNET_DATA=1 RUST_LOG=info
|
||||
|
||||
export RPC_HTTP_URL="http://fcs-da1._peer.internal:18899"
|
||||
# define in addition
|
||||
# RPC_HTTP_URL="http://fcs-ams1._peer.internal:18899"
|
||||
# for eclipse
|
||||
|
|
Loading…
Reference in New Issue