3636 tokio:: task:: JoinHandle ,
3737 tokio_stream:: StreamExt ,
3838 tracing:: instrument,
39+ url:: Url ,
3940} ;
4041
4142#[ instrument( skip( config, state) ) ]
@@ -64,12 +65,14 @@ where
6465 if config. oracle . subscriber_enabled {
6566 let min_elapsed_time = config. oracle . subscriber_finished_min_time ;
6667 let sleep_time = config. oracle . subscriber_finished_sleep_time ;
68+ let mut wss_url_index: usize = 0 ;
6769
6870 handles. push ( tokio:: spawn ( async move {
6971 loop {
7072 let current_time = Instant :: now ( ) ;
7173 if let Err ( ref err) = subscriber (
7274 config. clone ( ) ,
75+ & config. wss_urls [ wss_url_index] ,
7376 network,
7477 state. clone ( ) ,
7578 key_store. pyth_oracle_program_key ,
8184 tracing:: warn!( ?sleep_time, "Subscriber restarting too quickly. Sleeping" ) ;
8285 tokio:: time:: sleep ( sleep_time) . await ;
8386 }
87+
88+ // Round robin to the next WSS provider
89+ wss_url_index += 1 ;
90+ if wss_url_index >= config. wss_urls . len ( ) {
91+ wss_url_index = 0 ;
92+ }
8493 }
8594 }
8695 } ) ) ;
@@ -89,14 +98,15 @@ where
8998 handles
9099}
91100
92- /// When an account RPC Subscription update is receiveed .
101+ /// When an account RPC Subscription update is received .
93102///
94103/// We check if the account is one we're aware of and tracking, and if so, spawn
95104/// a small background task that handles that update. We only do this for price
96105/// accounts, all other accounts are handled below in the poller.
97- #[ instrument( skip( config, state) ) ]
106+ #[ instrument( skip( config, wss_url , state) ) ]
98107async fn subscriber < S > (
99108 config : Config ,
109+ wss_url : & Url ,
100110 network : Network ,
101111 state : Arc < S > ,
102112 program_key : Pubkey ,
@@ -106,7 +116,7 @@ where
106116 S : Send + Sync + ' static ,
107117{
108118 // Setup PubsubClient to listen for account changes on the Oracle program.
109- let client = PubsubClient :: new ( config . wss_url . as_str ( ) ) . await ?;
119+ let client = PubsubClient :: new ( wss_url. as_str ( ) ) . await ?;
110120
111121 let ( mut notifier, _unsub) = {
112122 let commitment = config. oracle . commitment ;
0 commit comments