@@ -27,7 +27,7 @@ use tokio_native_tls::TlsConnector;
2727use tracing:: { debug, error, info, warn} ;
2828use url:: Url ;
2929
30- use crate :: args:: { get_auth_header, get_channel, get_price_feeds, get_private_key, get_solana_cluster, get_ws_url , Args } ;
30+ use crate :: args:: { get_auth_header, get_channel, get_price_feeds, get_private_key, get_solana_cluster, get_ws_urls , Args } ;
3131use crate :: pyth_lazer:: chain_pusher:: PythChainPusher ;
3232use crate :: stork:: chain_pusher:: StorkChainPusher ;
3333use crate :: types:: ChainPusher ;
@@ -39,27 +39,38 @@ async fn main() {
3939 let args = Args :: parse ( ) ;
4040 let private_key = get_private_key ( args. private_key ) ;
4141 let auth_header = get_auth_header ( args. auth_header ) ;
42- let ws_url = get_ws_url ( args. ws_url ) ;
42+ let ws_urls = get_ws_urls ( args. ws_url , args . ws_urls ) ;
4343 let cluster_url = get_solana_cluster ( args. cluster ) ;
4444 let price_feeds = get_price_feeds ( args. price_feeds ) ;
4545 let channel = get_channel ( args. channel ) ;
4646
4747 let payer = Keypair :: from_base58_string ( & private_key) ;
4848 info ! ( wallet_pubkey = ?payer. pubkey( ) , "Identity initialized" ) ;
4949
50- let chain_pusher: Arc < dyn ChainPusher > = if ws_url . contains ( "stork" ) {
50+ let chain_pusher: Arc < dyn ChainPusher > = if ws_urls . iter ( ) . any ( |url| url . contains ( "stork" ) ) {
5151 Arc :: new ( StorkChainPusher :: new ( & cluster_url, payer) . await )
5252 } else {
5353 Arc :: new ( PythChainPusher :: new ( & cluster_url, payer) . await )
5454 } ;
5555
5656 loop {
57- if let Err ( e) =
58- run_websocket_client ( & chain_pusher, & ws_url, & auth_header, & price_feeds, & channel) . await
59- {
60- error ! ( error = ?e, "WebSocket connection error, attempting reconnection" ) ;
57+ let mut last_error = None ;
58+
59+ for ws_url in & ws_urls {
60+ match run_websocket_client ( & chain_pusher, ws_url, & auth_header, & price_feeds, & channel) . await {
61+ Ok ( _) => break ,
62+ Err ( e) => {
63+ error ! ( error = ?e, url = ws_url, "WebSocket connection failed, trying next URL" ) ;
64+ last_error = Some ( e) ;
65+ }
66+ }
67+ }
68+
69+ // if all URLs fail, wait before trying again
70+ if let Some ( e) = last_error {
71+ error ! ( error = ?e, "All WebSocket URLs failed, retrying in 5 seconds" ) ;
72+ time:: sleep ( Duration :: from_secs ( 5 ) ) . await ;
6173 }
62- time:: sleep ( Duration :: from_secs ( 5 ) ) . await ;
6374 }
6475}
6576
0 commit comments