2024-02-07 06:51:22 -08:00
|
|
|
use crate::rpc_polling::vote_accounts_and_cluster_info_polling::{
|
|
|
|
poll_cluster_info, poll_vote_accounts,
|
|
|
|
};
|
2023-08-31 03:34:13 -07:00
|
|
|
use crate::{
|
|
|
|
endpoint_stremers::EndpointStreaming,
|
2024-02-07 06:51:22 -08:00
|
|
|
rpc_polling::{poll_blocks::poll_block, poll_slots::poll_slots},
|
2023-08-31 03:34:13 -07:00
|
|
|
};
|
|
|
|
use solana_client::nonblocking::rpc_client::RpcClient;
|
|
|
|
use solana_lite_rpc_core::AnyhowJoinHandle;
|
|
|
|
use solana_sdk::commitment_config::CommitmentConfig;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
pub fn create_json_rpc_polling_subscription(
|
|
|
|
rpc_client: Arc<RpcClient>,
|
2024-01-22 06:22:11 -08:00
|
|
|
num_parallel_tasks: usize,
|
2023-08-31 03:34:13 -07:00
|
|
|
) -> anyhow::Result<(EndpointStreaming, Vec<AnyhowJoinHandle>)> {
|
2024-01-22 06:22:11 -08:00
|
|
|
let (slot_sx, slot_notifier) = tokio::sync::broadcast::channel(16);
|
|
|
|
let (block_sx, blocks_notifier) = tokio::sync::broadcast::channel(16);
|
|
|
|
let (cluster_info_sx, cluster_info_notifier) = tokio::sync::broadcast::channel(16);
|
|
|
|
let (va_sx, vote_account_notifier) = tokio::sync::broadcast::channel(16);
|
2024-02-14 10:20:25 -08:00
|
|
|
// does not support accounts support with rpc polling
|
2023-08-31 03:34:13 -07:00
|
|
|
|
2023-09-01 23:29:50 -07:00
|
|
|
let mut endpoint_tasks =
|
|
|
|
poll_slots(rpc_client.clone(), CommitmentConfig::processed(), slot_sx)?;
|
2023-08-31 03:34:13 -07:00
|
|
|
|
2024-01-22 06:22:11 -08:00
|
|
|
let mut block_polling_tasks = poll_block(
|
|
|
|
rpc_client.clone(),
|
|
|
|
block_sx,
|
|
|
|
slot_notifier.resubscribe(),
|
|
|
|
num_parallel_tasks,
|
|
|
|
);
|
2023-08-31 03:34:13 -07:00
|
|
|
endpoint_tasks.append(&mut block_polling_tasks);
|
|
|
|
|
2024-02-07 06:51:22 -08:00
|
|
|
let cluster_info_polling = poll_cluster_info(rpc_client.clone(), cluster_info_sx);
|
2023-08-31 03:34:13 -07:00
|
|
|
endpoint_tasks.push(cluster_info_polling);
|
|
|
|
|
2024-02-07 06:51:22 -08:00
|
|
|
let vote_accounts_polling = poll_vote_accounts(rpc_client.clone(), va_sx);
|
|
|
|
endpoint_tasks.push(vote_accounts_polling);
|
|
|
|
|
2023-08-31 03:34:13 -07:00
|
|
|
let streamers = EndpointStreaming {
|
|
|
|
blocks_notifier,
|
|
|
|
slot_notifier,
|
|
|
|
cluster_info_notifier,
|
|
|
|
vote_account_notifier,
|
2024-02-14 10:20:25 -08:00
|
|
|
// does not support accounts support with rpc polling
|
|
|
|
processed_account_stream: None,
|
2023-08-31 03:34:13 -07:00
|
|
|
};
|
|
|
|
Ok((streamers, endpoint_tasks))
|
|
|
|
}
|