mirror of
https://github.com/logos-blockchain/logos-blockchain-testing.git
synced 2026-01-03 22:03:12 +00:00
Add cfgsync input validation module and thiserror dep
This commit is contained in:
parent
5564942152
commit
b7d9386c26
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1008,6 +1008,7 @@ dependencies = [
|
|||||||
"subnetworks-assignations",
|
"subnetworks-assignations",
|
||||||
"testing-framework-config",
|
"testing-framework-config",
|
||||||
"testing-framework-core",
|
"testing-framework-core",
|
||||||
|
"thiserror 2.0.17",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -35,5 +35,6 @@ serde_yaml = "0.9"
|
|||||||
subnetworks-assignations = { workspace = true }
|
subnetworks-assignations = { workspace = true }
|
||||||
testing-framework-config = { workspace = true }
|
testing-framework-config = { workspace = true }
|
||||||
testing-framework-core = { path = "../../core" }
|
testing-framework-core = { path = "../../core" }
|
||||||
|
thiserror = { workspace = true }
|
||||||
tokio = { default-features = false, features = ["macros", "net", "rt-multi-thread"], version = "1" }
|
tokio = { default-features = false, features = ["macros", "net", "rt-multi-thread"], version = "1" }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
|
|||||||
@ -26,9 +26,12 @@ use testing_framework_config::topology::configs::{
|
|||||||
|
|
||||||
pub use crate::host::{Host, HostKind, PortOverrides};
|
pub use crate::host::{Host, HostKind, PortOverrides};
|
||||||
use crate::{
|
use crate::{
|
||||||
config::providers::create_providers, host::sort_hosts, network::rewrite_initial_peers,
|
config::{providers::create_providers, validation::validate_inputs},
|
||||||
|
host::sort_hosts,
|
||||||
|
network::rewrite_initial_peers,
|
||||||
};
|
};
|
||||||
mod providers;
|
mod providers;
|
||||||
|
mod validation;
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn create_node_configs(
|
pub fn create_node_configs(
|
||||||
@ -43,11 +46,14 @@ pub fn create_node_configs(
|
|||||||
) -> HashMap<Host, GeneralConfig> {
|
) -> HashMap<Host, GeneralConfig> {
|
||||||
let hosts = sort_hosts(hosts);
|
let hosts = sort_hosts(hosts);
|
||||||
|
|
||||||
assert_eq!(
|
validate_inputs(
|
||||||
hosts.len(),
|
&hosts,
|
||||||
consensus_params.n_participants,
|
consensus_params,
|
||||||
"host count must match consensus participants"
|
ids.as_ref(),
|
||||||
);
|
da_ports.as_ref(),
|
||||||
|
blend_ports.as_ref(),
|
||||||
|
)
|
||||||
|
.expect("invalid cfgsync inputs");
|
||||||
|
|
||||||
let ids = ids.unwrap_or_else(|| {
|
let ids = ids.unwrap_or_else(|| {
|
||||||
let mut generated = vec![[0; 32]; consensus_params.n_participants];
|
let mut generated = vec![[0; 32]; consensus_params.n_participants];
|
||||||
@ -56,29 +62,14 @@ pub fn create_node_configs(
|
|||||||
}
|
}
|
||||||
generated
|
generated
|
||||||
});
|
});
|
||||||
assert_eq!(
|
|
||||||
ids.len(),
|
|
||||||
consensus_params.n_participants,
|
|
||||||
"pre-generated ids must match participant count"
|
|
||||||
);
|
|
||||||
|
|
||||||
let ports = da_ports.unwrap_or_else(|| {
|
let ports = da_ports.unwrap_or_else(|| {
|
||||||
(0..consensus_params.n_participants)
|
(0..consensus_params.n_participants)
|
||||||
.map(|_| get_available_udp_port().unwrap())
|
.map(|_| get_available_udp_port().unwrap())
|
||||||
.collect()
|
.collect()
|
||||||
});
|
});
|
||||||
assert_eq!(
|
|
||||||
ports.len(),
|
|
||||||
consensus_params.n_participants,
|
|
||||||
"da port list must match participant count"
|
|
||||||
);
|
|
||||||
|
|
||||||
let blend_ports = blend_ports.unwrap_or_else(|| hosts.iter().map(|h| h.blend_port).collect());
|
let blend_ports = blend_ports.unwrap_or_else(|| hosts.iter().map(|h| h.blend_port).collect());
|
||||||
assert_eq!(
|
|
||||||
blend_ports.len(),
|
|
||||||
consensus_params.n_participants,
|
|
||||||
"blend port list must match participant count"
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut consensus_configs = create_consensus_configs(&ids, consensus_params, wallet_config);
|
let mut consensus_configs = create_consensus_configs(&ids, consensus_params, wallet_config);
|
||||||
let bootstrap_configs = create_bootstrap_configs(&ids, SHORT_PROLONGED_BOOTSTRAP_PERIOD);
|
let bootstrap_configs = create_bootstrap_configs(&ids, SHORT_PROLONGED_BOOTSTRAP_PERIOD);
|
||||||
|
|||||||
62
testing-framework/tools/cfgsync/src/config/validation.rs
Normal file
62
testing-framework/tools/cfgsync/src/config/validation.rs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
use testing_framework_config::topology::configs::consensus::ConsensusParams;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
use crate::host::Host;
|
||||||
|
|
||||||
|
#[derive(Debug, Error, PartialEq, Eq)]
|
||||||
|
pub enum ValidationError {
|
||||||
|
#[error("host count {actual} does not match participants {expected}")]
|
||||||
|
HostCountMismatch { actual: usize, expected: usize },
|
||||||
|
#[error("id count {actual} does not match participants {expected}")]
|
||||||
|
IdCountMismatch { actual: usize, expected: usize },
|
||||||
|
#[error("da port count {actual} does not match participants {expected}")]
|
||||||
|
DaPortCountMismatch { actual: usize, expected: usize },
|
||||||
|
#[error("blend port count {actual} does not match participants {expected}")]
|
||||||
|
BlendPortCountMismatch { actual: usize, expected: usize },
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn validate_inputs(
|
||||||
|
hosts: &[Host],
|
||||||
|
consensus_params: &ConsensusParams,
|
||||||
|
ids: Option<&Vec<[u8; 32]>>,
|
||||||
|
da_ports: Option<&Vec<u16>>,
|
||||||
|
blend_ports: Option<&Vec<u16>>,
|
||||||
|
) -> Result<(), ValidationError> {
|
||||||
|
let expected = consensus_params.n_participants;
|
||||||
|
|
||||||
|
if hosts.len() != expected {
|
||||||
|
return Err(ValidationError::HostCountMismatch {
|
||||||
|
actual: hosts.len(),
|
||||||
|
expected,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(ids) = ids {
|
||||||
|
if ids.len() != expected {
|
||||||
|
return Err(ValidationError::IdCountMismatch {
|
||||||
|
actual: ids.len(),
|
||||||
|
expected,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(ports) = da_ports {
|
||||||
|
if ports.len() != expected {
|
||||||
|
return Err(ValidationError::DaPortCountMismatch {
|
||||||
|
actual: ports.len(),
|
||||||
|
expected,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(ports) = blend_ports {
|
||||||
|
if ports.len() != expected {
|
||||||
|
return Err(ValidationError::BlendPortCountMismatch {
|
||||||
|
actual: ports.len(),
|
||||||
|
expected,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user