|
61 | 61 | BTreeMap, |
62 | 62 | HashMap, |
63 | 63 | }, |
| 64 | + sync::Arc, |
64 | 65 | time::Duration, |
65 | 66 | }, |
66 | 67 | tokio::{ |
@@ -228,7 +229,7 @@ pub fn spawn_exporter( |
228 | 229 | /// Exporter is responsible for exporting data held in the local store |
229 | 230 | /// to the global Pyth Network. |
230 | 231 | pub struct Exporter { |
231 | | - rpc_client: RpcClient, |
| 232 | + rpc_client: Arc<RpcClient>, |
232 | 233 |
|
233 | 234 | config: Config, |
234 | 235 |
|
@@ -292,7 +293,10 @@ impl Exporter { |
292 | 293 | ) -> Self { |
293 | 294 | let publish_interval = time::interval(config.publish_interval_duration); |
294 | 295 | Exporter { |
295 | | - rpc_client: RpcClient::new_with_timeout(rpc_url.to_string(), rpc_timeout), |
| 296 | + rpc_client: Arc::new(RpcClient::new_with_timeout( |
| 297 | + rpc_url.to_string(), |
| 298 | + rpc_timeout, |
| 299 | + )), |
296 | 300 | config, |
297 | 301 | network, |
298 | 302 | publish_interval, |
@@ -536,7 +540,7 @@ impl Exporter { |
536 | 540 | let mut batch_send_interval = time::interval( |
537 | 541 | self.config |
538 | 542 | .publish_interval_duration |
539 | | - .div_f64(num_batches as f64), |
| 543 | + .div_f64((num_batches + 1) as f64), // +1 to give enough time for the last batch |
540 | 544 | ); |
541 | 545 | let mut batch_state = HashMap::new(); |
542 | 546 | let mut batch_futures = vec![]; |
@@ -796,19 +800,37 @@ impl Exporter { |
796 | 800 | network_state.blockhash, |
797 | 801 | ); |
798 | 802 |
|
799 | | - let signature = self |
800 | | - .rpc_client |
801 | | - .send_transaction_with_config( |
802 | | - &transaction, |
803 | | - RpcSendTransactionConfig { |
804 | | - skip_preflight: true, |
805 | | - ..RpcSendTransactionConfig::default() |
806 | | - }, |
807 | | - ) |
808 | | - .await?; |
809 | | - debug!(self.logger, "sent upd_price transaction"; "signature" => signature.to_string(), "instructions" => instructions.len(), "price_accounts" => format!("{:?}", price_accounts)); |
| 803 | + let tx = self.inflight_transactions_tx.clone(); |
| 804 | + let logger = self.logger.clone(); |
| 805 | + let rpc_client = self.rpc_client.clone(); |
| 806 | + |
| 807 | + // Fire this off in a separate task so we don't block the main thread of the exporter |
| 808 | + tokio::spawn(async move { |
| 809 | + let signature = match rpc_client |
| 810 | + .send_transaction_with_config( |
| 811 | + &transaction, |
| 812 | + RpcSendTransactionConfig { |
| 813 | + skip_preflight: true, |
| 814 | + ..RpcSendTransactionConfig::default() |
| 815 | + }, |
| 816 | + ) |
| 817 | + .await |
| 818 | + { |
| 819 | + Ok(signature) => signature, |
| 820 | + Err(err) => { |
| 821 | + error!(logger, "{}", err); |
| 822 | + debug!(logger, "error context"; "context" => format!("{:?}", err)); |
| 823 | + return; |
| 824 | + } |
| 825 | + }; |
| 826 | + |
| 827 | + debug!(logger, "sent upd_price transaction"; "signature" => signature.to_string(), "instructions" => instructions.len(), "price_accounts" => format!("{:?}", price_accounts)); |
810 | 828 |
|
811 | | - self.inflight_transactions_tx.send(signature).await?; |
| 829 | + if let Err(err) = tx.send(signature).await { |
| 830 | + error!(logger, "{}", err); |
| 831 | + debug!(logger, "error context"; "context" => format!("{:?}", err)); |
| 832 | + } |
| 833 | + }); |
812 | 834 |
|
813 | 835 | Ok(()) |
814 | 836 | } |
|
0 commit comments