Skip to content

Commit 23b629e

Browse files
committed
chore: don't multiplex laser gRPC connections
1 parent 60a79cb commit 23b629e

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

magicblock-api/src/external_config.rs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::HashSet;
22

33
use magicblock_accounts::{AccountsConfig, RemoteCluster};
4+
use magicblock_chainlink::remote_account_provider::chain_laser_client::is_helius_laser_url;
45
use magicblock_config::{errors::ConfigResult, RemoteConfig};
56
use solana_sdk::pubkey::Pubkey;
67

@@ -59,19 +60,29 @@ pub fn remote_cluster_from_remote(
5960
.map(|ws_urls| ws_urls.iter().map(|x| x.to_string()).collect())
6061
.unwrap_or_else(|| {
6162
let mut ws_url = rpc_url.clone();
62-
ws_url
63-
.set_scheme(if rpc_url.scheme() == "https" {
64-
"wss"
65-
} else {
66-
"ws"
67-
})
68-
.expect("valid scheme");
69-
if let Some(port) = ws_url.port() {
63+
// We only multiplex if the ws urls are actually websockets and only
64+
// then do we adjust the protocol.
65+
// We do not need to do this if we subscribe via GRPC, i.e. helius
66+
// laser which is more stable.
67+
let is_grpc = is_grpc_url(&ws_url.to_string());
68+
if !is_grpc {
7069
ws_url
71-
.set_port(Some(port + 1))
72-
.expect("valid url with port");
70+
.set_scheme(if rpc_url.scheme() == "https" {
71+
"wss"
72+
} else {
73+
"ws"
74+
})
75+
.expect("valid scheme");
76+
if let Some(port) = ws_url.port() {
77+
ws_url
78+
.set_port(Some(port + 1))
79+
.expect("valid url with port");
80+
}
7381
}
74-
vec![ws_url.to_string(); WS_MULTIPLEX_COUNT]
82+
vec![
83+
ws_url.to_string();
84+
if is_grpc { 1 } else { WS_MULTIPLEX_COUNT }
85+
]
7586
});
7687
(rpc_url.to_string(), ws_urls)
7788
}
@@ -88,10 +99,14 @@ pub fn remote_cluster_from_remote(
8899
.first()
89100
.expect("at least one ws url must be set for CustomWithWs")
90101
.to_string();
91-
let ws_urls = vec![ws_url; 3];
102+
let is_grpc = is_grpc_url(&ws_url.to_string());
103+
let ws_urls =
104+
vec![ws_url; if is_grpc { 1 } else { WS_MULTIPLEX_COUNT }];
92105
(rpc_url, ws_urls)
93106
}
94107
CustomWithMultipleWs => {
108+
// NOTE: we assume that if multple ws urls are provided the user wants
109+
// to multiplex no matter if any is a GRPC based pubsub.
95110
let rpc_url = remote_config
96111
.url
97112
.as_ref()
@@ -138,3 +153,7 @@ fn allowed_program_ids_from_allowed_programs(
138153
None
139154
}
140155
}
156+
157+
fn is_grpc_url(url: &str) -> bool {
158+
is_helius_laser_url(url)
159+
}

0 commit comments

Comments
 (0)