mirror of
https://github.com/logos-blockchain/logos-blockchain-testing.git
synced 2026-01-02 13:23:13 +00:00
config: return Result from api/network config builders
This commit is contained in:
parent
128e073ed8
commit
4a47024a11
@ -1,6 +1,7 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use nomos_utils::net::get_available_tcp_port;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GeneralApiConfig {
|
||||
@ -8,16 +9,23 @@ pub struct GeneralApiConfig {
|
||||
pub testing_http_address: SocketAddr,
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn create_api_configs(ids: &[[u8; 32]]) -> Vec<GeneralApiConfig> {
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ApiConfigError {
|
||||
#[error("failed to allocate a free TCP port for API config")]
|
||||
PortAllocationFailed,
|
||||
}
|
||||
|
||||
pub fn create_api_configs(ids: &[[u8; 32]]) -> Result<Vec<GeneralApiConfig>, ApiConfigError> {
|
||||
ids.iter()
|
||||
.map(|_| GeneralApiConfig {
|
||||
address: format!("127.0.0.1:{}", get_available_tcp_port().unwrap())
|
||||
.parse()
|
||||
.unwrap(),
|
||||
testing_http_address: format!("127.0.0.1:{}", get_available_tcp_port().unwrap())
|
||||
.parse()
|
||||
.unwrap(),
|
||||
.map(|_| {
|
||||
let address_port =
|
||||
get_available_tcp_port().ok_or(ApiConfigError::PortAllocationFailed)?;
|
||||
let testing_port =
|
||||
get_available_tcp_port().ok_or(ApiConfigError::PortAllocationFailed)?;
|
||||
Ok(GeneralApiConfig {
|
||||
address: format!("127.0.0.1:{address_port}").parse().unwrap(),
|
||||
testing_http_address: format!("127.0.0.1:{testing_port}").parse().unwrap(),
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@ -96,9 +96,11 @@ pub fn create_general_configs_with_blend_core_subset(
|
||||
consensus::create_consensus_configs(&ids, &consensus_params, &WalletConfig::default());
|
||||
let bootstrap_config =
|
||||
bootstrap::create_bootstrap_configs(&ids, SHORT_PROLONGED_BOOTSTRAP_PERIOD);
|
||||
let network_configs = network::create_network_configs(&ids, network_params);
|
||||
let da_configs = da::create_da_configs(&ids, &DaParams::default(), &da_ports);
|
||||
let api_configs = api::create_api_configs(&ids);
|
||||
let network_configs =
|
||||
network::create_network_configs(&ids, network_params).expect("network config generation");
|
||||
let da_configs =
|
||||
da::try_create_da_configs(&ids, &DaParams::default(), &da_ports).expect("DA configs");
|
||||
let api_configs = api::create_api_configs(&ids).expect("api config generation");
|
||||
let blend_configs = blend::create_blend_configs(&ids, &blend_ports);
|
||||
let tracing_configs = tracing::create_tracing_configs(&ids);
|
||||
let time_config = time::default_time_config();
|
||||
|
||||
@ -5,6 +5,7 @@ use nomos_libp2p::{
|
||||
};
|
||||
use nomos_node::config::network::serde::{BackendSettings, Config, SwarmConfig};
|
||||
use nomos_utils::net::get_available_udp_port;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::node_address_from_port;
|
||||
|
||||
@ -25,6 +26,12 @@ pub struct NetworkParams {
|
||||
|
||||
pub type GeneralNetworkConfig = Config;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum NetworkConfigError {
|
||||
#[error("failed to allocate a free UDP port for libp2p swarm")]
|
||||
PortAllocationFailed,
|
||||
}
|
||||
|
||||
fn default_swarm_config() -> SwarmConfig {
|
||||
SwarmConfig {
|
||||
host: std::net::Ipv4Addr::UNSPECIFIED,
|
||||
@ -55,7 +62,7 @@ fn nat_settings(port: u16) -> NatSettings {
|
||||
pub fn create_network_configs(
|
||||
ids: &[[u8; 32]],
|
||||
network_params: &NetworkParams,
|
||||
) -> Vec<GeneralNetworkConfig> {
|
||||
) -> Result<Vec<GeneralNetworkConfig>, NetworkConfigError> {
|
||||
let swarm_configs: Vec<SwarmConfig> = ids
|
||||
.iter()
|
||||
.map(|id| {
|
||||
@ -63,8 +70,8 @@ pub fn create_network_configs(
|
||||
let node_key = ed25519::SecretKey::try_from_bytes(&mut node_key_bytes)
|
||||
.expect("Failed to generate secret key from bytes");
|
||||
|
||||
let port = get_available_udp_port().unwrap();
|
||||
SwarmConfig {
|
||||
let port = get_available_udp_port().ok_or(NetworkConfigError::PortAllocationFailed)?;
|
||||
Ok(SwarmConfig {
|
||||
node_key,
|
||||
port,
|
||||
chain_sync_config: cryptarchia_sync::Config {
|
||||
@ -72,13 +79,13 @@ pub fn create_network_configs(
|
||||
},
|
||||
nat_config: nat_settings(port),
|
||||
..default_swarm_config()
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
.collect::<Result<_, _>>()?;
|
||||
|
||||
let all_initial_peers = initial_peers_by_network_layout(&swarm_configs, network_params);
|
||||
|
||||
swarm_configs
|
||||
Ok(swarm_configs
|
||||
.iter()
|
||||
.zip(all_initial_peers)
|
||||
.map(|(swarm_config, initial_peers)| GeneralNetworkConfig {
|
||||
@ -87,7 +94,7 @@ pub fn create_network_configs(
|
||||
swarm: swarm_config.to_owned(),
|
||||
},
|
||||
})
|
||||
.collect()
|
||||
.collect())
|
||||
}
|
||||
|
||||
fn initial_peers_by_network_layout(
|
||||
|
||||
@ -14,7 +14,7 @@ use testing_framework_config::topology::{
|
||||
ConsensusParams, ProviderInfo, create_consensus_configs,
|
||||
create_genesis_tx_with_declarations,
|
||||
},
|
||||
da::{DaParams, create_da_configs},
|
||||
da::{DaParams, try_create_da_configs},
|
||||
network::{Libp2pNetworkLayout, NetworkParams, create_network_configs},
|
||||
tracing::create_tracing_configs,
|
||||
wallet::WalletConfig,
|
||||
@ -267,10 +267,12 @@ impl TopologyBuilder {
|
||||
let mut consensus_configs =
|
||||
create_consensus_configs(&ids, &config.consensus_params, &config.wallet_config);
|
||||
let bootstrapping_config = create_bootstrap_configs(&ids, SHORT_PROLONGED_BOOTSTRAP_PERIOD);
|
||||
let da_configs = create_da_configs(&ids, &config.da_params, &da_ports);
|
||||
let network_configs = create_network_configs(&ids, &config.network_params);
|
||||
let da_configs = try_create_da_configs(&ids, &config.da_params, &da_ports)
|
||||
.expect("failed to create DA configs");
|
||||
let network_configs = create_network_configs(&ids, &config.network_params)
|
||||
.expect("failed to create network configs");
|
||||
let blend_configs = create_blend_configs(&ids, &blend_ports);
|
||||
let api_configs = create_api_configs(&ids);
|
||||
let api_configs = create_api_configs(&ids).expect("failed to create API configs");
|
||||
let tracing_configs = create_tracing_configs(&ids);
|
||||
let time_config = default_time_config();
|
||||
|
||||
|
||||
@ -66,6 +66,8 @@ pub enum NodeConfigBuildError {
|
||||
Providers(#[from] ProviderBuildError),
|
||||
#[error(transparent)]
|
||||
Da(#[from] da::DaConfigError),
|
||||
#[error(transparent)]
|
||||
Network(#[from] network::NetworkConfigError),
|
||||
#[error("failed to allocate an available UDP port")]
|
||||
PortAllocFailed,
|
||||
#[error("failed to parse multiaddr '{value}': {message}")]
|
||||
@ -271,7 +273,7 @@ fn build_base_configs(
|
||||
consensus_configs: create_consensus_configs(ids, consensus_params, wallet_config),
|
||||
bootstrap_configs: create_bootstrap_configs(ids, SHORT_PROLONGED_BOOTSTRAP_PERIOD),
|
||||
da_configs: try_create_da_configs(ids, da_params, da_ports)?,
|
||||
network_configs: create_network_configs(ids, &NetworkParams::default()),
|
||||
network_configs: create_network_configs(ids, &NetworkParams::default())?,
|
||||
blend_configs: create_blend_configs(ids, blend_ports),
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user