From ef69148940bcaee330a44ec6d6f4cc67807ff0c6 Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Thu, 30 Nov 2023 15:24:46 +0100 Subject: [PATCH] address feedbacks --- src/agent/solana/oracle.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/agent/solana/oracle.rs b/src/agent/solana/oracle.rs index 723a2bb..148d412 100644 --- a/src/agent/solana/oracle.rs +++ b/src/agent/solana/oracle.rs @@ -146,9 +146,7 @@ pub fn spawn_oracle( let (updates_tx, updates_rx) = mpsc::channel(config.updates_channel_capacity); if config.subscriber_enabled { let subscriber = Subscriber::new( - rpc_url.to_string(), wss_url.to_string(), - rpc_timeout, config.commitment, key_store.program_key, updates_tx, @@ -658,14 +656,9 @@ mod subscriber { /// Subscriber subscribes to all changes on the given account, and sends those changes /// on updates_tx. This is a convenience wrapper around the Blockchain Shadow crate. pub struct Subscriber { - /// HTTP RPC endpoint - rpc_url: String, /// WSS RPC endpoint wss_url: String, - /// Timeout for RPC requests - rpc_timeout: Duration, - /// Commitment level used to read account data commitment: CommitmentLevel, @@ -681,18 +674,14 @@ mod subscriber { impl Subscriber { pub fn new( - rpc_url: String, wss_url: String, - rpc_timeout: Duration, commitment: CommitmentLevel, program_key: Pubkey, updates_tx: mpsc::Sender<(Pubkey, solana_sdk::account::Account)>, logger: Logger, ) -> Self { Subscriber { - rpc_url, wss_url, - rpc_timeout, commitment, program_key, updates_tx, @@ -707,7 +696,8 @@ mod subscriber { error!(self.logger, "{}", err); debug!(self.logger, "error context"; "context" => format!("{:?}", err)); if current_time.elapsed() < Duration::from_secs(30) { - tracing::error!( + warn!( + self.logger, "Subscriber restarting too quickly. Sleeping for 1 second." ); tokio::time::sleep(Duration::from_secs(1)).await; @@ -725,7 +715,9 @@ mod subscriber { let config = RpcProgramAccountsConfig { account_config: RpcAccountInfoConfig { - commitment: Some(CommitmentConfig::confirmed()), + commitment: Some(CommitmentConfig { + commitment: self.commitment, + }), encoding: Some(UiAccountEncoding::Base64Zstd), ..Default::default() }, @@ -754,7 +746,8 @@ mod subscriber { .map_err(|_| anyhow!("failed to send update to oracle"))?; } None => { - return Err(anyhow!("Subscriber closed connection")); + info!(self.logger, "subscriber closed connection"); + return Ok(()); } } }