solana_exec/
execution_context.rs1use crate::jito::get_be_url_from_region::get_be_url_from_region;
2use jito_protos::{
3 auth::auth_service_client::AuthServiceClient,
4 searcher::searcher_service_client::SearcherServiceClient,
5};
6use jito_searcher_client::{
7 client_interceptor::ClientInterceptor, cluster_data_impl::ClusterDataImpl, grpc_connect,
8 SearcherClient,
9};
10use solana_metrics::set_host_id;
11use solana_sdk::signature::{Keypair, Signer};
12use std::env;
13use std::sync::atomic::AtomicBool;
14use std::sync::Arc;
15use tonic::transport::channel::Channel;
16use tonic::service::interceptor::InterceptedService;
17
18pub struct ExecutionContext {
25 pub jito_be_client: SearcherClient<ClusterDataImpl, InterceptedService<Channel, ClientInterceptor>>,
27}
28
29impl ExecutionContext {
30 pub async fn new() -> Self {
32 let auth_keypair = env::var("JITO_AUTH_SECRET_KEY").expect("JITO_AUTH_SECRET_KEY must be set");
33 let auth_keypair = Keypair::from_base58_string(&auth_keypair);
34 set_host_id(auth_keypair.pubkey().to_string());
36 let auth_keypair = Arc::new(auth_keypair);
37
38 let be_url = get_be_url_from_region();
39 let auth_channel = grpc_connect(&*be_url).await.unwrap();
40 let client_interceptor =
41 ClientInterceptor::new(AuthServiceClient::new(auth_channel), &auth_keypair)
42 .await
43 .unwrap();
44 let searcher_channel = grpc_connect(&*be_url).await.unwrap();
45 let searcher_service_client =
46 SearcherServiceClient::with_interceptor(searcher_channel, client_interceptor);
47 let exit = Arc::new(AtomicBool::new(false));
48 let rpc_url = env::var("RPC_NODE_URL").expect("RPC_NODE_URL must be set");
49 let cluster_data_impl =
50 ClusterDataImpl::new(rpc_url, searcher_service_client.clone(), exit.clone()).await;
51
52 let client = SearcherClient::new(
53 cluster_data_impl.clone(),
54 searcher_service_client,
55 exit.clone(),
56 );
57
58 Self { jito_be_client: client }
59 }
60}