-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(watcher): start validator node process (#1116)
Description --- Spawns the the `tari_validator_node` through a tokio `Command` but has not been tested fully with actual config. (It doesn't persist the child or even outlives its scope.) Breaking Changes --- - [x] None - [ ] Requires data directory to be deleted - [ ] Other - Please specify
- Loading branch information
1 parent
7b914ce
commit 067bf14
Showing
8 changed files
with
231 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2024 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
use std::{ | ||
env, | ||
net::IpAddr, | ||
path::{Path, PathBuf}, | ||
process::Stdio, | ||
}; | ||
|
||
use tokio::process::{Child, Command}; | ||
|
||
use crate::{ | ||
config::{ExecutableConfig, InstanceType}, | ||
port::PortAllocator, | ||
}; | ||
|
||
#[allow(dead_code)] | ||
pub struct Forker { | ||
// Used for the validator to connect to the base (L1) node | ||
base_node_grpc_address: String, | ||
// The base directory of calling the application | ||
base_dir: PathBuf, | ||
// The Tari L2 validator instance | ||
validator: Option<Instance>, | ||
// The Minotari L1 wallet instance | ||
wallet: Option<Instance>, | ||
} | ||
|
||
impl Forker { | ||
pub fn new(base_node_grpc_address: String, base_dir: PathBuf) -> Self { | ||
Self { | ||
validator: None, | ||
wallet: None, | ||
base_node_grpc_address, | ||
base_dir, | ||
} | ||
} | ||
|
||
pub async fn start_validator(&mut self, config: ExecutableConfig) -> anyhow::Result<Child> { | ||
let instance = Instance::new(InstanceType::TariValidatorNode, config.clone()); | ||
self.validator = Some(instance.clone()); | ||
|
||
let mut cmd = Command::new( | ||
config | ||
.executable_path | ||
.unwrap_or_else(|| Path::new("tari_validator_node").to_path_buf()), | ||
); | ||
|
||
// TODO: stdout logs | ||
// let process_dir = self.base_dir.join("processes").join("TariValidatorNode"); | ||
// let stdout_log_path = process_dir.join("stdout.log"); | ||
// let stderr_log_path = process_dir.join("stderr.log"); | ||
cmd.envs(env::vars()) | ||
//.arg(format!("--config={validator_node_config_path}")) | ||
.kill_on_drop(true) | ||
.stdout(Stdio::piped()) | ||
.stderr(Stdio::piped()) | ||
.stdin(Stdio::null()); | ||
|
||
let child = cmd.spawn()?; | ||
|
||
Ok(child) | ||
} | ||
} | ||
|
||
#[allow(dead_code)] | ||
#[derive(Clone)] | ||
struct Instance { | ||
app: InstanceType, | ||
config: ExecutableConfig, | ||
listen_ip: Option<IpAddr>, | ||
port: PortAllocator, | ||
} | ||
|
||
impl Instance { | ||
pub fn new(app: InstanceType, config: ExecutableConfig) -> Self { | ||
Self { | ||
app, | ||
config, | ||
listen_ip: None, | ||
port: PortAllocator::new(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2024 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
use crate::{ | ||
config::{Config, ExecutableConfig}, | ||
forker::Forker, | ||
}; | ||
|
||
pub struct ProcessManager { | ||
pub validator_config: ExecutableConfig, | ||
pub wallet_config: ExecutableConfig, | ||
pub forker: Forker, | ||
} | ||
|
||
impl ProcessManager { | ||
pub fn new(config: Config) -> Self { | ||
Self { | ||
validator_config: config.executable_config[0].clone(), | ||
wallet_config: config.executable_config[1].clone(), | ||
forker: Forker::new(config.base_node_grpc_address, config.base_dir), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2024 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#[derive(Clone)] | ||
pub struct PortAllocator { | ||
pub wallet: MinotariPorts, | ||
} | ||
|
||
impl PortAllocator { | ||
pub fn new() -> Self { | ||
Self { | ||
wallet: MinotariPorts::new(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct MinotariPorts { | ||
pub p2p: Option<u16>, | ||
pub grpc: Option<u16>, | ||
} | ||
|
||
#[allow(dead_code)] | ||
impl MinotariPorts { | ||
fn new() -> Self { | ||
Self { p2p: None, grpc: None } | ||
} | ||
|
||
pub fn p2p_port_as_string(&self) -> Option<String> { | ||
self.p2p?; | ||
Some(format!("{}", self.p2p.unwrap())) | ||
} | ||
|
||
pub fn grpc_port_as_string(&self) -> Option<String> { | ||
self.grpc?; | ||
Some(format!("{}", self.grpc.unwrap())) | ||
} | ||
} |