update swqos config

This commit is contained in:
wood
2025-07-07 03:28:02 +08:00
parent f772e26aa2
commit def16e6b92
7 changed files with 144 additions and 107 deletions
+74 -14
View File
@@ -6,12 +6,14 @@ pub mod zeroslot;
pub mod temporal;
pub mod bloxroute;
use solana_sdk::transaction::VersionedTransaction;
use std::sync::Arc;
use solana_sdk::{commitment_config::CommitmentConfig, transaction::VersionedTransaction};
use tokio::sync::RwLock;
use anyhow::Result;
use crate::constants::swqos::{SWQOS_ENDPOINTS_BLOX, SWQOS_ENDPOINTS_JITO, SWQOS_ENDPOINTS_NEXTBLOCK, SWQOS_ENDPOINTS_TEMPORAL, SWQOS_ENDPOINTS_ZERO_SLOT};
use crate::{common::SolanaRpcClient, constants::swqos::{SWQOS_ENDPOINTS_BLOX, SWQOS_ENDPOINTS_JITO, SWQOS_ENDPOINTS_NEXTBLOCK, SWQOS_ENDPOINTS_TEMPORAL, SWQOS_ENDPOINTS_ZERO_SLOT}, swqos::{bloxroute::BloxrouteClient, jito::JitoClient, nextblock::NextBlockClient, solana_rpc::SolRpcClient, temporal::TemporalClient, zeroslot::ZeroSlotClient}};
lazy_static::lazy_static! {
static ref TIP_ACCOUNT_CACHE: RwLock<Vec<String>> = RwLock::new(Vec::new());
@@ -44,7 +46,7 @@ pub enum SwqosType {
ZeroSlot,
Temporal,
Bloxroute,
Rpc,
Default,
}
pub type SwqosClient = dyn SwqosClientTrait + Send + Sync + 'static;
@@ -69,25 +71,83 @@ pub enum SwqosRegion {
Default,
}
#[derive(Debug, Clone)]
pub struct SwqosConfig {
pub endpoint: String,
pub auth_token: String,
pub swqos_type: SwqosType,
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SwqosConfig {
Default(String),
Jito(SwqosRegion),
NextBlock(String, SwqosRegion),
Bloxroute(String, SwqosRegion),
Temporal(String, SwqosRegion),
ZeroSlot(String, SwqosRegion),
}
impl SwqosConfig {
pub fn new(endpoint: Option<String>, auth_token: Option<String>, swqos_type: SwqosType, region: SwqosRegion) -> Self {
let auth_token = auth_token.unwrap_or_else(|| "".to_string());
let endpoint = endpoint.unwrap_or_else(|| match swqos_type {
pub fn get_endpoint(swqos_type: SwqosType, region: SwqosRegion) -> String {
match swqos_type {
SwqosType::Jito => SWQOS_ENDPOINTS_JITO[region as usize].to_string(),
SwqosType::NextBlock => SWQOS_ENDPOINTS_NEXTBLOCK[region as usize].to_string(),
SwqosType::ZeroSlot => SWQOS_ENDPOINTS_ZERO_SLOT[region as usize].to_string(),
SwqosType::Temporal => SWQOS_ENDPOINTS_TEMPORAL[region as usize].to_string(),
SwqosType::Bloxroute => SWQOS_ENDPOINTS_BLOX[region as usize].to_string(),
SwqosType::Rpc => "".to_string(),
});
SwqosType::Default => "".to_string(),
}
}
Self { endpoint, auth_token, swqos_type }
pub fn get_swqos_client(rpc_url: String, commitment: CommitmentConfig, swqos_config: SwqosConfig) -> Arc<SwqosClient> {
match swqos_config {
SwqosConfig::Jito(region) => {
let endpoint = SwqosConfig::get_endpoint(SwqosType::Jito, region);
let jito_client = JitoClient::new(
rpc_url.clone(),
endpoint,
"".to_string()
);
Arc::new(jito_client)
}
SwqosConfig::NextBlock(auth_token, region) => {
let endpoint = SwqosConfig::get_endpoint(SwqosType::NextBlock, region);
let nextblock_client = NextBlockClient::new(
rpc_url.clone(),
endpoint.to_string(),
auth_token
);
Arc::new(nextblock_client)
},
SwqosConfig::ZeroSlot(auth_token, region) => {
let endpoint = SwqosConfig::get_endpoint(SwqosType::ZeroSlot, region);
let zeroslot_client = ZeroSlotClient::new(
rpc_url.clone(),
endpoint.to_string(),
auth_token
);
Arc::new(zeroslot_client)
},
SwqosConfig::Temporal(auth_token, region) => {
let endpoint = SwqosConfig::get_endpoint(SwqosType::Temporal, region);
let temporal_client = TemporalClient::new(
rpc_url.clone(),
endpoint.to_string(),
auth_token
);
Arc::new(temporal_client)
},
SwqosConfig::Bloxroute(auth_token, region) => {
let endpoint = SwqosConfig::get_endpoint(SwqosType::Bloxroute, region);
let bloxroute_client = BloxrouteClient::new(
rpc_url.clone(),
endpoint.to_string(),
auth_token
);
Arc::new(bloxroute_client)
},
SwqosConfig::Default(endpoint) => {
let rpc = SolanaRpcClient::new_with_commitment(
endpoint,
commitment
);
let rpc_client = SolRpcClient::new(Arc::new(rpc));
Arc::new(rpc_client)
}
}
}
}
+1 -1
View File
@@ -50,7 +50,7 @@ impl SwqosClientTrait for SolRpcClient {
}
fn get_swqos_type(&self) -> SwqosType {
SwqosType::Rpc
SwqosType::Default
}
}