36
36
tokio:: task:: JoinHandle ,
37
37
tokio_stream:: StreamExt ,
38
38
tracing:: instrument,
39
+ url:: Url ,
39
40
} ;
40
41
41
42
#[ instrument( skip( config, state) ) ]
@@ -64,12 +65,14 @@ where
64
65
if config. oracle . subscriber_enabled {
65
66
let min_elapsed_time = config. oracle . subscriber_finished_min_time ;
66
67
let sleep_time = config. oracle . subscriber_finished_sleep_time ;
68
+ let mut wss_url_index: usize = 0 ;
67
69
68
70
handles. push ( tokio:: spawn ( async move {
69
71
loop {
70
72
let current_time = Instant :: now ( ) ;
71
73
if let Err ( ref err) = subscriber (
72
74
config. clone ( ) ,
75
+ & config. wss_urls [ wss_url_index] ,
73
76
network,
74
77
state. clone ( ) ,
75
78
key_store. pyth_oracle_program_key ,
81
84
tracing:: warn!( ?sleep_time, "Subscriber restarting too quickly. Sleeping" ) ;
82
85
tokio:: time:: sleep ( sleep_time) . await ;
83
86
}
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
+ }
84
93
}
85
94
}
86
95
} ) ) ;
@@ -89,14 +98,15 @@ where
89
98
handles
90
99
}
91
100
92
- /// When an account RPC Subscription update is receiveed .
101
+ /// When an account RPC Subscription update is received .
93
102
///
94
103
/// We check if the account is one we're aware of and tracking, and if so, spawn
95
104
/// a small background task that handles that update. We only do this for price
96
105
/// accounts, all other accounts are handled below in the poller.
97
- #[ instrument( skip( config, state) ) ]
106
+ #[ instrument( skip( config, wss_url , state) ) ]
98
107
async fn subscriber < S > (
99
108
config : Config ,
109
+ wss_url : & Url ,
100
110
network : Network ,
101
111
state : Arc < S > ,
102
112
program_key : Pubkey ,
@@ -106,7 +116,7 @@ where
106
116
S : Send + Sync + ' static ,
107
117
{
108
118
// 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 ?;
110
120
111
121
let ( mut notifier, _unsub) = {
112
122
let commitment = config. oracle . commitment ;
0 commit comments