Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve overlay connection #581

Merged
merged 11 commits into from
Feb 4, 2025
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"connection_info": {
"address": "154.12.251.105",
"port": 11625
"endpoints": [
{ "address": "154.12.251.105", "port": 11625 }
]
},
"node_info": {
"ledger_version": 22,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"connection_info": {
"endpoints": [
{
"address": "54.166.220.249",
"port": 11625
},
{
"address": "54.159.138.198",
"port": 11625
},
{
"address": "44.223.45.116",
"port": 11625
}
]
},
"node_info": {
"ledger_version": 22,
"overlay_version": 35,
"overlay_min_version": 33,
"version_str": "stellar-core 22.0.0 (721fd0a654d5e82d38c748a91053e530a475193d)",
"is_pub_net": false
},
"stellar_history_archive_urls": [
"http://history.stellar.org/prd/core-testnet/core_testnet_001",
"http://history.stellar.org/prd/core-testnet/core_testnet_002",
"http://history.stellar.org/prd/core-testnet/core_testnet_003"
]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"connection_info": {
"address": "54.166.220.249",
"port": 11625
"endpoints": [
{
"address": "54.166.220.249",
"port": 11625
}
]
},
"node_info": {
"ledger_version": 22,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"connection_info": {
"address": "54.159.138.198",
"port": 11625
"endpoints": [
{
"address": "54.159.138.198",
"port": 11625
}
]
},
"node_info": {
"ledger_version": 22,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"connection_info": {
"address": "44.223.45.116",
"port": 11625
"endpoints": [
{
"address": "44.223.45.116",
"port": 11625
}
]
},
"node_info": {
"ledger_version": 22,
Expand Down
62 changes: 46 additions & 16 deletions clients/stellar-relay-lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
node::NodeInfo,
StellarOverlayConnection,
};
use rand::seq::SliceRandom;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, BytesOrString};
use std::fmt::Debug;
Expand Down Expand Up @@ -51,13 +52,17 @@ impl StellarOverlayConfig {
tracing::info!(
"connection_info(): Connecting to Stellar overlay network using public key: {public_key}"
);
let endpoint = cfg.endpoints.choose(&mut rand::thread_rng()).ok_or(Error::ConfigError(
"No endpoints found in config for connecting to overlay".to_string(),
))?;

let address = std::str::from_utf8(&cfg.address)
let address = std::str::from_utf8(&endpoint.address)
.map_err(|e| Error::ConfigError(format!("Address: {:?}", e)))?;
let port = endpoint.port;

Ok(ConnectionInfo::new_with_timeout(
address,
cfg.port,
port,
secret_key,
cfg.auth_cert_expiration,
cfg.recv_tx_msgs,
Expand All @@ -80,13 +85,19 @@ pub struct NodeInfoCfg {
pub is_pub_net: bool,
}

/// The config structure of the ConnectionInfo
#[serde_as]
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ConnectionInfoCfg {
pub struct ConnectionEndpoint {
#[serde_as(as = "BytesOrString")]
pub address: Vec<u8>,
pub port: u32,
}

#[serde_as]
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ConnectionInfoCfg {
#[serde(default)]
pub endpoints: Vec<ConnectionEndpoint>,

#[serde(default = "ConnectionInfoCfg::default_auth_cert_exp")]
pub auth_cert_expiration: u64,
Expand Down Expand Up @@ -160,8 +171,9 @@ mod test {
fn missing_fields_in_connection_info_config() {
// missing port
let json = r#"
{
"address": "1.2.3.4"
"endpoints": [
{ "address": "1.2.3.4" }
],
"recv_scp_msgs": true,
"remote_called_us": false
}
Expand All @@ -172,7 +184,9 @@ mod test {
// missing address
let json = r#"
{
"port": 11625,
"endpoints": [
{"port": 11625}
],
"auth_cert_expiration": 0,
"recv_tx_msgs": false,
"recv_scp_msgs": true
Expand Down Expand Up @@ -227,9 +241,13 @@ mod test {
fn stellar_relay_config_conversion_successful() {
let json = r#"
{
"connection_info": {
"address": "1.2.3.4",
"port": 11625,
"connection_info":{
"endpoints": [
{
"address": "1.2.3.4",
"port": 11625
}
],
"auth_cert_expiration": 0,
"recv_scp_msgs": true
},
Expand All @@ -254,7 +272,11 @@ mod test {
let json = r#"
{
"connection_info": {
"port": 11625
"endpoints": [
{
"port": 11625
}
]
},
"node_info": {
"ledger_version": 19,
Expand All @@ -271,8 +293,12 @@ mod test {
let json = r#"
{
"connection_info": {
"address": "1.2.3.4",
"port": 11625
"endpoints": [
{
"address": "1.2.3.4",
"port": 11625
}
],
"auth_cert_expiration": 0,
"recv_scp_msgs": true
},
Expand All @@ -290,9 +316,13 @@ mod test {
// missing stellar_history_base_url
let json = r#"
{
"connection_info": {
"address": "1.2.3.4",
"port": 11625,
"connection_info": {
"endpoints": [
{
"address": "1.2.3.4",
"port": 11625
}
],
"auth_cert_expiration": 0,
"recv_scp_msgs": true
},
Expand Down
4 changes: 2 additions & 2 deletions clients/vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.17"
[features]
std = [ "base64/std", "primitives/std", "stellar-relay-lib/std" ]

integration = [ "rand", "wallet/testing-utils" ]
integration = [ "wallet/testing-utils" ]
standalone-metadata = [ "runtime/standalone-metadata" ]
parachain-metadata-pendulum = [ "runtime/parachain-metadata-pendulum" ]
parachain-metadata-amplitude = [ "runtime/parachain-metadata-amplitude" ]
Expand All @@ -23,7 +23,7 @@ base64 = { workspace = true, features = ['alloc'] }
bincode = { workspace = true }
clap = { workspace = true, features = ["env"] }
cfg-if = { workspace = true }
rand = { workspace = true, optional = true }
rand = { workspace = true }
futures = { workspace = true }
governor = { workspace = true }
hex = { workspace = true, default-features = true }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"connection_info": {
"address": "85.190.254.217",
"port": 11625
"endpoints": [
{
"address": "85.190.254.217",
"port": 11625
}
]
},
"node_info": {
"ledger_version": 22,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"connection_info": {
"address": "154.12.251.105",
"port": 11625
"endpoints": [
{
"address": "154.12.251.105",
"port": 11625
}
]
},
"node_info": {
"ledger_version": 22,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"connection_info": {
"endpoints": [
{
"address": "85.190.254.217",
"port": 11625
},
{
"address": "154.12.251.105",
"port": 11625
},
{
"address": "194.233.85.232",
"port": 11625
}
]
},
"node_info": {
"ledger_version": 22,
"overlay_version": 35,
"overlay_min_version": 33,
"version_str": "stellar-core 22.0.0 (721fd0a654d5e82d38c748a91053e530a475193d)",
"is_pub_net": true
},
"stellar_history_archive_urls": [
"http://history.stellar.org/prd/core-live/core_live_001",
"http://history.stellar.org/prd/core-live/core_live_002",
"http://history.stellar.org/prd/core-live/core_live_003",
"https://stellar-history-de-fra.satoshipay.io",
"https://stellar-history-sg-sin.satoshipay.io",
"https://stellar-history-us-iowa.satoshipay.io"
]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"connection_info": {
"address": "194.233.85.232",
"port": 11625
"endpoints": [
{
"address": "194.233.85.232",
"port": 11625
}
]
},
"node_info": {
"ledger_version": 22,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"connection_info": {
"endpoints": [
{
"address": "54.166.220.249",
"port": 11625
},
{
"address": "54.159.138.198",
"port": 11625
},
{
"address": "44.223.45.116",
"port": 11625
}
]
},
"node_info": {
"ledger_version": 22,
"overlay_version": 35,
"overlay_min_version": 33,
"version_str": "stellar-core 22.0.0 (721fd0a654d5e82d38c748a91053e530a475193d)",
"is_pub_net": false
},
"stellar_history_archive_urls": [
"http://history.stellar.org/prd/core-testnet/core_testnet_001",
"http://history.stellar.org/prd/core-testnet/core_testnet_002",
"http://history.stellar.org/prd/core-testnet/core_testnet_003"
]
}
Loading
Loading