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

feat: add dedicated websocket cli parameter #337

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions crates/topos-sequencer-subnet-runtime/tests/subnet_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,11 @@ async fn test_subnet_certificate_get_checkpoints_call(
let context = context_running_subnet_node.await;
let subnet_smart_contract_address =
"0x".to_string() + &hex::encode(context.i_topos_core.address());
let subnet_jsonrpc_endpoint = context.jsonrpc();
let subnet_jsonrpc_http = context.jsonrpc();

// Get checkpoints when contract is empty
let subnet_client = topos_sequencer_subnet_client::SubnetClient::new(
&subnet_jsonrpc_endpoint,
&subnet_jsonrpc_http,
Some(hex::decode(TEST_SECRET_ETHEREUM_KEY).unwrap()),
&subnet_smart_contract_address,
)
Expand Down Expand Up @@ -908,11 +908,11 @@ async fn test_subnet_id_call(
let context = context_running_subnet_node.await;
let subnet_smart_contract_address =
"0x".to_string() + &hex::encode(context.i_topos_core.address());
let subnet_jsonrpc_endpoint = context.jsonrpc();
let subnet_jsonrpc_http = context.jsonrpc();

// Create subnet client
let subnet_client = topos_sequencer_subnet_client::SubnetClient::new(
&subnet_jsonrpc_endpoint,
&subnet_jsonrpc_http,
Some(hex::decode(TEST_SECRET_ETHEREUM_KEY).unwrap()),
&subnet_smart_contract_address,
)
Expand Down Expand Up @@ -954,7 +954,7 @@ async fn test_subnet_send_token_processing(
) -> Result<(), Box<dyn std::error::Error>> {
let context = context_running_subnet_node.await;
let test_private_key = hex::decode(TEST_SECRET_ETHEREUM_KEY).unwrap();
let subnet_jsonrpc_endpoint = context.jsonrpc();
let subnet_jsonrpc_http = context.jsonrpc();
let subnet_smart_contract_address =
"0x".to_string() + &hex::encode(context.i_topos_core.address());

Expand Down Expand Up @@ -985,7 +985,7 @@ async fn test_subnet_send_token_processing(
// Deploy token contract
let i_erc20 = deploy_test_token(
&hex::encode(&test_private_key),
&subnet_jsonrpc_endpoint,
&subnet_jsonrpc_http,
context.i_topos_messaging.address(),
)
.await?;
Expand Down Expand Up @@ -1072,15 +1072,15 @@ async fn test_sync_from_genesis_and_particular_source_head(
) -> Result<(), Box<dyn std::error::Error>> {
let context = context_running_subnet_node.await;
let test_private_key = hex::decode(TEST_SECRET_ETHEREUM_KEY).unwrap();
let subnet_jsonrpc_endpoint = context.jsonrpc();
let subnet_jsonrpc_http = context.jsonrpc();
let subnet_smart_contract_address =
"0x".to_string() + &hex::encode(context.i_topos_core.address());

// Wait for some time to simulate network history
tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;

// Get block height
let http_provider = Provider::<Http>::try_from(subnet_jsonrpc_endpoint.clone())?
let http_provider = Provider::<Http>::try_from(subnet_jsonrpc_http.clone())?
.interval(std::time::Duration::from_millis(20u64));
let subnet_height = http_provider.get_block_number().await?.as_u64();

Expand Down Expand Up @@ -1148,7 +1148,7 @@ async fn test_sync_from_genesis_and_particular_source_head(
//---------------------------------------------------------------------
//
// Get block height
let http_provider = Provider::<Http>::try_from(subnet_jsonrpc_endpoint)?
let http_provider = Provider::<Http>::try_from(subnet_jsonrpc_http)?
.interval(std::time::Duration::from_millis(20u64));
let subnet_height = http_provider.get_block_number().await?.as_u64();
const SYNC_START_BLOCK_NUMBER: u64 = 11;
Expand Down Expand Up @@ -1235,15 +1235,15 @@ async fn test_sync_from_start_block(
) -> Result<(), Box<dyn std::error::Error>> {
let context = context_running_subnet_node.await;
let test_private_key = hex::decode(TEST_SECRET_ETHEREUM_KEY).unwrap();
let subnet_jsonrpc_endpoint = context.jsonrpc();
let subnet_jsonrpc_http = context.jsonrpc();
let subnet_smart_contract_address =
"0x".to_string() + &hex::encode(context.i_topos_core.address());

// Wait for some time to simulate network history
tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;

// Get block height
let http_provider = Provider::<Http>::try_from(subnet_jsonrpc_endpoint.clone())?
let http_provider = Provider::<Http>::try_from(subnet_jsonrpc_http.clone())?
.interval(std::time::Duration::from_millis(20u64));
let subnet_height = http_provider.get_block_number().await?.as_u64();

Expand Down Expand Up @@ -1332,7 +1332,7 @@ async fn test_subnet_multiple_send_token_in_a_block(
) -> Result<(), Box<dyn std::error::Error>> {
let context = context_running_subnet_node.await;
let test_private_key = hex::decode(TEST_SECRET_ETHEREUM_KEY).unwrap();
let subnet_jsonrpc_endpoint = context.jsonrpc();
let subnet_jsonrpc_http = context.jsonrpc();
let subnet_smart_contract_address =
"0x".to_string() + &hex::encode(context.i_topos_core.address());
let number_of_send_token_transactions: usize = 4;
Expand Down Expand Up @@ -1366,7 +1366,7 @@ async fn test_subnet_multiple_send_token_in_a_block(
// Deploy token contract
let i_erc20 = deploy_test_token(
&hex::encode(&test_private_key),
&subnet_jsonrpc_endpoint,
&subnet_jsonrpc_http,
context.i_topos_messaging.address(),
)
.await?;
Expand Down Expand Up @@ -1409,28 +1409,28 @@ async fn test_subnet_multiple_send_token_in_a_block(
let mut erc20_clients = vec![
create_new_erc20_client(
TEST_SECRET_ETHEREUM_KEY,
&subnet_jsonrpc_endpoint,
&subnet_jsonrpc_http,
i_erc20.address(),
)
.await
.expect("Valid erc20 client"),
create_new_erc20_client(
TEST_ACCOUNT_ALITH_KEY,
&subnet_jsonrpc_endpoint,
&subnet_jsonrpc_http,
i_erc20.address(),
)
.await
.expect("Valid erc20 client"),
create_new_erc20_client(
TEST_ACCOUNT_BALATHAR_KEY,
&subnet_jsonrpc_endpoint,
&subnet_jsonrpc_http,
i_erc20.address(),
)
.await
.expect("Valid erc20 client"),
create_new_erc20_client(
TEST_ACCOUNT_CEZAR_KEY,
&subnet_jsonrpc_endpoint,
&subnet_jsonrpc_http,
i_erc20.address(),
)
.await
Expand Down Expand Up @@ -1460,7 +1460,7 @@ async fn test_subnet_multiple_send_token_in_a_block(
TARGET_SUBNET_ID_5,
create_new_erc20msg_client(
TEST_SECRET_ETHEREUM_KEY,
&subnet_jsonrpc_endpoint,
&subnet_jsonrpc_http,
context.i_erc20_messaging.address(),
)
.await
Expand All @@ -1470,7 +1470,7 @@ async fn test_subnet_multiple_send_token_in_a_block(
TARGET_SUBNET_ID_4,
create_new_erc20msg_client(
TEST_ACCOUNT_ALITH_KEY,
&subnet_jsonrpc_endpoint,
&subnet_jsonrpc_http,
context.i_erc20_messaging.address(),
)
.await
Expand All @@ -1480,7 +1480,7 @@ async fn test_subnet_multiple_send_token_in_a_block(
TARGET_SUBNET_ID_3,
create_new_erc20msg_client(
TEST_ACCOUNT_BALATHAR_KEY,
&subnet_jsonrpc_endpoint,
&subnet_jsonrpc_http,
context.i_erc20_messaging.address(),
)
.await
Expand All @@ -1490,7 +1490,7 @@ async fn test_subnet_multiple_send_token_in_a_block(
TARGET_SUBNET_ID_2,
create_new_erc20msg_client(
TEST_ACCOUNT_CEZAR_KEY,
&subnet_jsonrpc_endpoint,
&subnet_jsonrpc_http,
context.i_erc20_messaging.address(),
)
.await
Expand Down
14 changes: 10 additions & 4 deletions crates/topos-sequencer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ mod app_context;
pub struct SequencerConfiguration {
pub subnet_id: Option<String>,
pub public_key: Option<Vec<u8>>,
pub subnet_jsonrpc_endpoint: String,
pub subnet_jsonrpc_http: String,
pub subnet_jsonrpc_ws: Option<String>,
pub subnet_contract_address: String,
pub tce_grpc_endpoint: String,
pub signing_key: SecretKey,
Expand Down Expand Up @@ -50,7 +51,7 @@ pub async fn launch(
// It will retry using backoff algorithm, but if it fails (default max backoff elapsed time is 15 min) we can not proceed
else {
let http_endpoint =
topos_sequencer_subnet_runtime::derive_endpoints(&config.subnet_jsonrpc_endpoint)
topos_sequencer_subnet_runtime::derive_endpoints(&config.subnet_jsonrpc_http)
.map_err(|e| {
Box::new(std::io::Error::new(
InvalidInput,
Expand All @@ -74,8 +75,13 @@ pub async fn launch(
}
};

let (http_endpoint, ws_endpoint) =
topos_sequencer_subnet_runtime::derive_endpoints(&config.subnet_jsonrpc_endpoint)?;
let (http_endpoint, mut ws_endpoint) =
topos_sequencer_subnet_runtime::derive_endpoints(&config.subnet_jsonrpc_http)?;

if let Some(config_ws_endpoint) = config.subnet_jsonrpc_ws.as_ref() {
// Use explicitly provided websocket subnet endpoint
ws_endpoint = config_ws_endpoint.clone();
}

// Instantiate subnet runtime proxy, handling interaction with subnet node
let subnet_runtime_proxy_worker = match SubnetRuntimeProxyWorker::new(
Expand Down
3 changes: 2 additions & 1 deletion crates/topos/src/components/node/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ pub(crate) fn spawn_sequencer_process(
let config = SequencerConfiguration {
subnet_id: None,
public_key: keys.validator_pubkey(),
subnet_jsonrpc_endpoint: config.subnet_jsonrpc_endpoint,
subnet_jsonrpc_http: config.subnet_jsonrpc_http,
subnet_jsonrpc_ws: config.subnet_jsonrpc_ws,
subnet_contract_address: config.subnet_contract_address,
tce_grpc_endpoint: config.tce_grpc_endpoint,
signing_key: keys.validator.clone().unwrap(),
Expand Down
17 changes: 12 additions & 5 deletions crates/topos/src/components/sequencer/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@ pub struct Run {
#[clap(long, env = "TOPOS_LOCAL_SUBNET_ID")]
pub subnet_id: Option<String>,

// Subnet endpoint in the form [ip address]:[port]
// Topos sequencer expects both websocket and http protocol available
// on this subnet endpoint
/// 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.
#[clap(
long,
default_value = "127.0.0.1:8545",
env = "SUBNET_JSONRPC_ENDPOINT"
env = "TOPOS_SUBNET_JSONRPC_HTTP"
)]
pub subnet_jsonrpc_endpoint: String,
pub subnet_jsonrpc_http: String,

/// 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`
#[clap(long, env = "TOPOS_SUBNET_JSONRPC_WS")]
pub subnet_jsonrpc_ws: Option<String>,

// Core contract address
#[clap(long, env = "SUBNET_CONTRACT_ADDRESS")]
Expand Down
3 changes: 2 additions & 1 deletion crates/topos/src/components/sequencer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pub(crate) async fn handle_command(
let config = SequencerConfiguration {
subnet_id: cmd.subnet_id,
public_key: None,
subnet_jsonrpc_endpoint: cmd.subnet_jsonrpc_endpoint,
subnet_jsonrpc_http: cmd.subnet_jsonrpc_http,
subnet_jsonrpc_ws: cmd.subnet_jsonrpc_ws,
subnet_contract_address: cmd.subnet_contract_address,
tce_grpc_endpoint: cmd.base_tce_api_url,
signing_key: keys.validator.clone().unwrap(),
Expand Down
7 changes: 6 additions & 1 deletion crates/topos/src/config/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ pub struct SequencerConfig {
/// JSON-RPC endpoint of the Edge node, websocket and http support expected
/// If the endpoint address starts with `https`, ssl will be used with http/websocket
#[serde(default = "default_subnet_jsonrpc_endpoint")]
pub subnet_jsonrpc_endpoint: String,
pub subnet_jsonrpc_http: String,

// 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`
pub subnet_jsonrpc_ws: Option<String>,

/// Address where the Topos Core contract is deployed
#[serde(default = "default_subnet_contract_address")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ Options:
Defines the verbosity level
--home <HOME>
Home directory for the configuration [env: TOPOS_HOME=] [default: /home/runner/.config/topos]
--subnet-jsonrpc-endpoint <SUBNET_JSONRPC_ENDPOINT>
[env: SUBNET_JSONRPC_ENDPOINT=] [default: 127.0.0.1:8545]
--subnet-jsonrpc-http <SUBNET_JSONRPC_HTTP>
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]
--subnet-jsonrpc-ws <SUBNET_JSONRPC_WS>
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=]
--subnet-contract-address <SUBNET_CONTRACT_ADDRESS>
[env: SUBNET_CONTRACT_ADDRESS=]
--base-tce-api-url <BASE_TCE_API_URL>
Expand Down