122 lines
3.4 KiB
Rust
Raw Normal View History

2026-02-02 07:19:22 +01:00
use std::{fmt, marker::PhantomData, path::PathBuf, sync::Arc};
2026-02-05 08:23:14 +02:00
use reqwest::Url;
2026-02-02 07:19:22 +01:00
use super::{Application, DynError};
2026-02-02 07:19:22 +01:00
/// Marker enabling node control support.
#[derive(Clone, Copy, Debug, Default)]
pub struct NodeControlCapability;
2026-02-02 07:19:22 +01:00
/// Observability settings attached to a scenario.
#[derive(Clone, Debug, Default)]
pub struct ObservabilityCapability {
2026-02-02 07:19:22 +01:00
/// Base URL used by the runner to query Prometheus metrics.
2025-12-17 17:04:41 +01:00
pub metrics_query_url: Option<Url>,
2026-02-02 07:19:22 +01:00
/// OTLP HTTP endpoint used by nodes to export metrics.
2025-12-17 17:04:41 +01:00
pub metrics_otlp_ingest_url: Option<Url>,
2026-02-02 07:19:22 +01:00
/// Optional Grafana URL for logs/output.
pub grafana_url: Option<Url>,
}
2026-01-19 08:34:17 +01:00
/// Peer selection strategy for dynamically started nodes.
#[derive(Clone, Debug)]
pub enum PeerSelection {
2026-02-02 07:19:22 +01:00
/// Use topology defaults.
2026-01-19 08:34:17 +01:00
DefaultLayout,
2026-02-02 07:19:22 +01:00
/// Start without initial peers.
2026-01-19 08:34:17 +01:00
None,
2026-02-02 07:19:22 +01:00
/// Connect to named peers.
2026-01-19 08:34:17 +01:00
Named(Vec<String>),
}
/// Options for dynamically starting a node.
2026-02-05 08:23:14 +02:00
#[derive(Clone)]
2026-02-02 07:19:22 +01:00
pub struct StartNodeOptions<E: Application> {
2026-01-19 08:34:17 +01:00
/// How to select initial peers on startup.
pub peers: PeerSelection,
2026-02-02 07:19:22 +01:00
/// Optional backend-specific initial config override.
pub config_override: Option<E::NodeConfig>,
/// Optional patch callback applied to generated node config before spawn.
pub config_patch:
Option<Arc<dyn Fn(E::NodeConfig) -> Result<E::NodeConfig, DynError> + Send + Sync>>,
/// Optional persistent working directory for this node process.
chore: merge dev into master (#29) * Add node config overrides (#14) * chore: merge master into dev and update configs after merge (#17) * Sdp config structs from logos blockchain (#15) * Update configs after main repo merge --------- Co-authored-by: gusto <bacv@users.noreply.github.com> * Local deployer allows to stop and restart nodes (#16) * Unify local node control and restart support * Add local stop-node support * Use node names for restart/stop control * merge --------- Co-authored-by: hansieodendaal <hansie.odendaal@gmail.com> * Add orphan manual cluster test utilities * Update node rev and align consensus/wallet config * Update node rev and align wallet/KMS configs * Update main repo ref (#23) * Fix genesis utxos and scale leader stake * Document leader stake constants * feat: add custom persistent dir option for working files (#26) * chore: config and naming updates (#27) * Update config and crate naming - Updated configs to the lates main repo configs. - Updated all main repo crate namings to be same as the main repo. - Added `create_dir_all` to `pub(crate) fn create_tempdir(custom_work_dir: Option<PathBuf>) -> std::io::Result<TempDir> {`. - Wired in optional `persist_dir` when using the local deployer. - Update `time` vulnerability **Note:** Unsure about the `service_params` mapping in `pub(crate) fn cryptarchia_deployment(config: &GeneralConfig) -> CryptarchiaDeploymentSettings {` * fix ntp server config --------- Co-authored-by: Andrus Salumets <andrus@status.im> Co-authored-by: gusto <bacv@users.noreply.github.com> Co-authored-by: andrussal <salumets.andrus@gmail.com>
2026-02-09 14:12:26 +02:00
pub persist_dir: Option<PathBuf>,
2026-02-02 07:19:22 +01:00
_phantom: PhantomData<E>,
2026-01-19 08:34:17 +01:00
}
2026-02-02 07:19:22 +01:00
impl<E: Application> fmt::Debug for StartNodeOptions<E> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("StartNodeOptions")
.field("peers", &self.peers)
.field("config_override", &self.config_override.is_some())
.field("config_patch", &self.config_patch.is_some())
.field("persist_dir", &self.persist_dir)
.finish()
}
}
impl<E: Application> Default for StartNodeOptions<E> {
2026-01-19 08:34:17 +01:00
fn default() -> Self {
Self {
peers: PeerSelection::DefaultLayout,
2026-02-02 07:19:22 +01:00
config_override: None,
2026-02-05 08:23:14 +02:00
config_patch: None,
chore: merge dev into master (#29) * Add node config overrides (#14) * chore: merge master into dev and update configs after merge (#17) * Sdp config structs from logos blockchain (#15) * Update configs after main repo merge --------- Co-authored-by: gusto <bacv@users.noreply.github.com> * Local deployer allows to stop and restart nodes (#16) * Unify local node control and restart support * Add local stop-node support * Use node names for restart/stop control * merge --------- Co-authored-by: hansieodendaal <hansie.odendaal@gmail.com> * Add orphan manual cluster test utilities * Update node rev and align consensus/wallet config * Update node rev and align wallet/KMS configs * Update main repo ref (#23) * Fix genesis utxos and scale leader stake * Document leader stake constants * feat: add custom persistent dir option for working files (#26) * chore: config and naming updates (#27) * Update config and crate naming - Updated configs to the lates main repo configs. - Updated all main repo crate namings to be same as the main repo. - Added `create_dir_all` to `pub(crate) fn create_tempdir(custom_work_dir: Option<PathBuf>) -> std::io::Result<TempDir> {`. - Wired in optional `persist_dir` when using the local deployer. - Update `time` vulnerability **Note:** Unsure about the `service_params` mapping in `pub(crate) fn cryptarchia_deployment(config: &GeneralConfig) -> CryptarchiaDeploymentSettings {` * fix ntp server config --------- Co-authored-by: Andrus Salumets <andrus@status.im> Co-authored-by: gusto <bacv@users.noreply.github.com> Co-authored-by: andrussal <salumets.andrus@gmail.com>
2026-02-09 14:12:26 +02:00
persist_dir: None,
2026-02-02 07:19:22 +01:00
_phantom: PhantomData,
2026-01-19 08:34:17 +01:00
}
}
}
2026-02-02 07:19:22 +01:00
impl<E: Application> StartNodeOptions<E> {
#[must_use]
pub fn with_peers(mut self, peers: PeerSelection) -> Self {
self.peers = peers;
self
}
#[must_use]
pub fn with_config_override(mut self, config_override: E::NodeConfig) -> Self {
self.config_override = Some(config_override);
self
}
#[must_use]
pub fn create_patch(
mut self,
config_patch: impl Fn(E::NodeConfig) -> Result<E::NodeConfig, DynError> + Send + Sync + 'static,
) -> Self {
self.config_patch = Some(Arc::new(config_patch));
self
}
#[must_use]
pub fn with_persist_dir(mut self, persist_dir: PathBuf) -> Self {
self.persist_dir = Some(persist_dir);
2026-02-05 08:23:14 +02:00
self
}
}
2026-02-02 07:19:22 +01:00
/// Indicates whether a capability requires node control.
pub trait RequiresNodeControl {
const REQUIRED: bool;
}
impl RequiresNodeControl for () {
const REQUIRED: bool = false;
}
impl RequiresNodeControl for NodeControlCapability {
const REQUIRED: bool = true;
}
impl RequiresNodeControl for ObservabilityCapability {
const REQUIRED: bool = false;
}
#[derive(Clone)]
2026-02-02 07:19:22 +01:00
pub struct StartedNode<E: Application> {
pub name: String,
2026-02-02 07:19:22 +01:00
pub client: E::NodeClient,
}