Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 0ef58b1

Browse files
committed
feat: add dedicated websocket cli parameter (#337)
1 parent 0838c63 commit 0ef58b1

File tree

8 files changed

+1632
-17
lines changed

8 files changed

+1632
-17
lines changed

crates/topos-sequencer-subnet-runtime/tests/subnet_contract.rs.orig

Lines changed: 1593 additions & 0 deletions
Large diffs are not rendered by default.

crates/topos-sequencer/src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ mod app_context;
2020
pub struct SequencerConfiguration {
2121
pub subnet_id: Option<String>,
2222
pub public_key: Option<Vec<u8>>,
23-
pub subnet_jsonrpc_endpoint: String,
23+
pub subnet_jsonrpc_http: String,
24+
pub subnet_jsonrpc_ws: Option<String>,
2425
pub subnet_contract_address: String,
2526
pub tce_grpc_endpoint: String,
2627
pub signing_key: SecretKey,
@@ -49,7 +50,7 @@ pub async fn launch(
4950
// It will retry using backoff algorithm, but if it fails (default max backoff elapsed time is 15 min) we can not proceed
5051
else {
5152
let http_endpoint =
52-
topos_sequencer_subnet_runtime::derive_endpoints(&config.subnet_jsonrpc_endpoint)
53+
topos_sequencer_subnet_runtime::derive_endpoints(&config.subnet_jsonrpc_http)
5354
.map_err(|e| {
5455
Box::new(std::io::Error::new(
5556
InvalidInput,
@@ -73,8 +74,13 @@ pub async fn launch(
7374
}
7475
};
7576

76-
let (http_endpoint, ws_endpoint) =
77-
topos_sequencer_subnet_runtime::derive_endpoints(&config.subnet_jsonrpc_endpoint)?;
77+
let (http_endpoint, mut ws_endpoint) =
78+
topos_sequencer_subnet_runtime::derive_endpoints(&config.subnet_jsonrpc_http)?;
79+
80+
if let Some(config_ws_endpoint) = config.subnet_jsonrpc_ws.as_ref() {
81+
// Use explicitly provided websocket subnet endpoint
82+
ws_endpoint = config_ws_endpoint.clone();
83+
}
7884

7985
// Instantiate subnet runtime proxy, handling interaction with subnet node
8086
let subnet_runtime_proxy_worker = match SubnetRuntimeProxyWorker::new(

crates/topos-tce-broadcast/src/task_manager_futures/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl TaskManager {
127127
let prev = self.validator_store.get_certificate(&cert.prev_id);
128128
if matches!(prev, Ok(Some(_))) || cert.prev_id == topos_core::uci::INITIAL_CERTIFICATE_ID {
129129
Self::start_task(
130-
&mut self.running_tasks,
130+
&self.running_tasks,
131131
task,
132132
task_context.sink.clone(),
133133
self.buffered_messages.remove(&cert.id),
@@ -155,7 +155,7 @@ impl TaskManager {
155155

156156
let certificate_id= task.certificate_id;
157157
Self::start_task(
158-
&mut self.running_tasks,
158+
&self.running_tasks,
159159
task,
160160
context.sink.clone(),
161161
self.buffered_messages.remove(&certificate_id),
@@ -182,7 +182,7 @@ impl TaskManager {
182182
}
183183

184184
fn start_task(
185-
running_tasks: &mut RunningTasks,
185+
running_tasks: &RunningTasks,
186186
task: Task,
187187
sink: mpsc::Sender<DoubleEchoCommand>,
188188
messages: Option<Vec<DoubleEchoCommand>>,

crates/topos/src/components/node/services.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ pub(crate) fn spawn_sequencer_process(
5959
let config = SequencerConfiguration {
6060
subnet_id: None,
6161
public_key: keys.validator_pubkey(),
62-
subnet_jsonrpc_endpoint: config.subnet_jsonrpc_endpoint,
62+
subnet_jsonrpc_http: config.subnet_jsonrpc_http,
63+
subnet_jsonrpc_ws: config.subnet_jsonrpc_ws,
6364
subnet_contract_address: config.subnet_contract_address,
6465
tce_grpc_endpoint: config.tce_grpc_endpoint,
6566
signing_key: keys.validator.clone().unwrap(),

crates/topos/src/components/sequencer/commands/run.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,22 @@ pub struct Run {
99
#[clap(long, env = "TOPOS_LOCAL_SUBNET_ID")]
1010
pub subnet_id: Option<String>,
1111

12-
// Subnet endpoint in the form [ip address]:[port]
13-
// Topos sequencer expects both websocket and http protocol available
14-
// on this subnet endpoint
12+
/// Subnet endpoint in the form [ip address]:[port]
13+
/// Topos sequencer expects both websocket and http protocol available
14+
/// on this subnet endpoint. If optional `subnet_jsonrpc_ws` is not provided websocket endpoint
15+
/// will be deduced from this parameter.
1516
#[clap(
1617
long,
1718
default_value = "127.0.0.1:8545",
18-
env = "SUBNET_JSONRPC_ENDPOINT"
19+
env = "TOPOS_SUBNET_JSONRPC_HTTP"
1920
)]
20-
pub subnet_jsonrpc_endpoint: String,
21+
pub subnet_jsonrpc_http: String,
22+
23+
/// Optional explicit websocket endpoint for the subnet jsonrpc api. If this parameter is not provided,
24+
/// it will be derived from the `subnet_jsonrpc_http`.
25+
/// Full uri value is expected, e.g. `wss://arbitrum.infura.com/v3/ws/mykey` or `ws://127.0.0.1/ws`
26+
#[clap(long, env = "TOPOS_SUBNET_JSONRPC_WS")]
27+
pub subnet_jsonrpc_ws: Option<String>,
2128

2229
// Core contract address
2330
#[clap(long, env = "SUBNET_CONTRACT_ADDRESS")]

crates/topos/src/components/sequencer/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ pub(crate) async fn handle_command(
2121
let config = SequencerConfiguration {
2222
subnet_id: cmd.subnet_id,
2323
public_key: None,
24-
subnet_jsonrpc_endpoint: cmd.subnet_jsonrpc_endpoint,
24+
subnet_jsonrpc_http: cmd.subnet_jsonrpc_http,
25+
subnet_jsonrpc_ws: cmd.subnet_jsonrpc_ws,
2526
subnet_contract_address: cmd.subnet_contract_address,
2627
tce_grpc_endpoint: cmd.base_tce_api_url,
2728
signing_key: keys.validator.clone().unwrap(),

crates/topos/src/config/sequencer.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ pub struct SequencerConfig {
1717
/// JSON-RPC endpoint of the Edge node, websocket and http support expected
1818
/// If the endpoint address starts with `https`, ssl will be used with http/websocket
1919
#[serde(default = "default_subnet_jsonrpc_endpoint")]
20-
pub subnet_jsonrpc_endpoint: String,
20+
pub subnet_jsonrpc_http: String,
21+
22+
// Optional explicit websocket endpoint for the subnet jsonrpc api. If this parameter is not provided,
23+
// it will be derived from the `subnet_jsonrpc_http`.
24+
// Full uri value is expected, e.g. `wss://arbitrum.infura.com/v3/ws/mykey` or `ws://127.0.0.1/ws`
25+
pub subnet_jsonrpc_ws: Option<String>,
2126

2227
/// Address where the Topos Core contract is deployed
2328
#[serde(default = "default_subnet_contract_address")]

crates/topos/tests/snapshots/sequencer__sequencer_help_display.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ Options:
1313
Defines the verbosity level
1414
--home <HOME>
1515
Home directory for the configuration [env: TOPOS_HOME=] [default: /home/runner/.config/topos]
16-
--subnet-jsonrpc-endpoint <SUBNET_JSONRPC_ENDPOINT>
17-
[env: SUBNET_JSONRPC_ENDPOINT=] [default: 127.0.0.1:8545]
16+
--subnet-jsonrpc-http <SUBNET_JSONRPC_HTTP>
17+
Subnet endpoint in the form [ip address]:[port] Topos sequencer expects both websocket and http protocol available on this subnet endpoint. If optional `subnet_jsonrpc_ws` is not provided websocket endpoint will be deduced from this parameter [env: TOPOS_SUBNET_JSONRPC_HTTP=] [default: 127.0.0.1:8545]
18+
--subnet-jsonrpc-ws <SUBNET_JSONRPC_WS>
19+
Optional explicit websocket endpoint for the subnet jsonrpc api. If this parameter is not provided, it will be derived from the `subnet_jsonrpc_http`. Full uri value is expected, e.g. `wss://arbitrum.infura.com/v3/ws/mykey` or `ws://127.0.0.1/ws` [env: TOPOS_SUBNET_JSONRPC_WS=]
1820
--subnet-contract-address <SUBNET_CONTRACT_ADDRESS>
1921
[env: SUBNET_CONTRACT_ADDRESS=]
2022
--base-tce-api-url <BASE_TCE_API_URL>

0 commit comments

Comments
 (0)