reset pub_sub client

This commit is contained in:
aniketfuryrocks 2023-02-05 15:08:17 +05:30
parent b890ee4052
commit a20d23e924
No known key found for this signature in database
GPG Key ID: FA6BFCFAA7D4B764
4 changed files with 176 additions and 178 deletions

View File

@ -18,16 +18,13 @@ use log::info;
use jsonrpsee::{server::ServerBuilder, types::SubscriptionResult, SubscriptionSink};
use solana_pubsub_client::nonblocking::pubsub_client::PubsubClient;
use solana_rpc_client::{nonblocking::rpc_client::RpcClient, rpc_client::SerializableTransaction};
use solana_rpc_client_api::{
config::{RpcContextConfig, RpcRequestAirdropConfig, RpcSignatureStatusConfig},
response::{Response as RpcResponse, RpcBlockhash, RpcResponseContext, RpcVersionInfo},
};
use solana_sdk::{
commitment_config::{CommitmentConfig},
hash::Hash,
pubkey::Pubkey,
commitment_config::CommitmentConfig, hash::Hash, pubkey::Pubkey,
transaction::VersionedTransaction,
};
use solana_transaction_status::TransactionStatus;
@ -51,7 +48,6 @@ pub struct LiteBridge {
impl LiteBridge {
pub async fn new(rpc_url: String, ws_addr: String, fanout_slots: u64) -> anyhow::Result<Self> {
let rpc_client = Arc::new(RpcClient::new(rpc_url.clone()));
let pub_sub_client = Arc::new(PubsubClient::new(&ws_addr).await?);
let tpu_manager =
Arc::new(TpuManager::new(rpc_client.clone(), ws_addr, fanout_slots).await?);
@ -60,11 +56,7 @@ impl LiteBridge {
let block_store = BlockStore::new(&rpc_client).await?;
let block_listner = BlockListener::new(
pub_sub_client.clone(),
tx_sender.clone(),
block_store.clone(),
);
let block_listner = BlockListener::new(tx_sender.clone(), block_store.clone());
Ok(Self {
rpc_client,

View File

@ -4,7 +4,7 @@ use anyhow::{bail, Context};
use dashmap::DashMap;
use futures::StreamExt;
use jsonrpsee::SubscriptionSink;
use log::info;
use log::{info, warn};
use prometheus::{histogram_opts, opts, register_counter, register_histogram, Counter, Histogram};
use solana_pubsub_client::nonblocking::pubsub_client::PubsubClient;
use solana_rpc_client::rpc_client::SerializableTransaction;
@ -49,7 +49,6 @@ lazy_static::lazy_static! {
/// and keeps a track of confirmed txs
#[derive(Clone)]
pub struct BlockListener {
pub_sub_client: Arc<PubsubClient>,
tx_sender: TxSender,
block_store: BlockStore,
pub signature_subscribers: Arc<DashMap<String, SubscriptionSink>>,
@ -67,13 +66,8 @@ pub struct BlockListnerNotificatons {
}
impl BlockListener {
pub fn new(
pub_sub_client: Arc<PubsubClient>,
tx_sender: TxSender,
block_store: BlockStore,
) -> Self {
pub fn new(tx_sender: TxSender, block_store: BlockStore) -> Self {
Self {
pub_sub_client,
tx_sender,
block_store,
signature_subscribers: Default::default(),
@ -98,12 +92,12 @@ impl BlockListener {
self.signature_subscribers.remove(&signature);
}
pub fn listen(
pub async fn listen_from_pubsub(
self,
pubsub_client: &PubsubClient,
commitment_config: CommitmentConfig,
postgres: Option<PostgresMpscSend>,
) -> JoinHandle<anyhow::Result<()>> {
tokio::spawn(async move {
postgres: &Option<PostgresMpscSend>,
) -> anyhow::Result<()> {
let commitment = commitment_config.commitment;
let comfirmation_status = match commitment {
@ -113,16 +107,13 @@ impl BlockListener {
info!("Subscribing to {commitment:?} blocks");
let (mut recv, _) = self
.pub_sub_client
let (mut recv, _) = pubsub_client
.block_subscribe(
RpcBlockSubscribeFilter::All,
Some(RpcBlockSubscribeConfig {
commitment: Some(commitment_config),
encoding: None,
transaction_details: Some(
solana_transaction_status::TransactionDetails::Full,
),
transaction_details: Some(solana_transaction_status::TransactionDetails::Full),
show_rewards: None,
max_supported_transaction_version: None,
}),
@ -261,6 +252,24 @@ impl BlockListener {
}
}
}
}
pub fn listen(
self,
commitment_config: CommitmentConfig,
postgres: Option<PostgresMpscSend>,
) -> JoinHandle<anyhow::Result<()>> {
tokio::spawn(async move {
loop {
let ws_addr = &self.tx_sender.tpu_manager.ws_addr;
let pub_sub_client = PubsubClient::new(ws_addr).await?;
let err = self
.clone()
.listen_from_pubsub(&pub_sub_client, commitment_config, &postgres)
.await
.unwrap_err();
warn!("{commitment_config:?} Block Subscribe error {err}");
}
})
}
}

View File

@ -34,7 +34,7 @@ pub struct TxSender {
/// Tx(s) forwarded to tpu
pub txs_sent: Arc<DashMap<String, TxProps>>,
/// TpuClient to call the tpu port
tpu_manager: Arc<TpuManager>,
pub tpu_manager: Arc<TpuManager>,
}
/// Transaction Properties

View File

@ -10,7 +10,6 @@ use lite_rpc::{
DEFAULT_LITE_RPC_ADDR, DEFAULT_RPC_ADDR, DEFAULT_TX_BATCH_INTERVAL_MS, DEFAULT_TX_BATCH_SIZE,
DEFAULT_WS_ADDR,
};
use solana_pubsub_client::nonblocking::pubsub_client::PubsubClient;
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::commitment_config::CommitmentConfig;
@ -33,12 +32,10 @@ async fn send_and_confirm_txs() {
.unwrap(),
);
let pub_sub_client = Arc::new(PubsubClient::new(DEFAULT_WS_ADDR).await.unwrap());
let tx_sender = TxSender::new(tpu_client);
let block_store = BlockStore::new(&rpc_client).await.unwrap();
let block_listener = BlockListener::new(pub_sub_client.clone(), tx_sender.clone(), block_store);
let block_listener = BlockListener::new(tx_sender.clone(), block_store);
let (tx_send, tx_recv) = mpsc::unbounded_channel();