-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jstzd,jstz_node): implement jstz node
- Loading branch information
Showing
7 changed files
with
103 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
use octez::r#async::endpoint::Endpoint; | ||
|
||
#[derive(Clone)] | ||
pub struct JstzNodeConfig { | ||
/// The endpoint of the jstz node. | ||
pub endpoint: Endpoint, | ||
/// Rollup endpoint. | ||
pub rollup_endpoint: Endpoint, | ||
/// The path to the rollup kernel log file. | ||
pub kernel_log_file: PathBuf, | ||
} | ||
|
||
impl JstzNodeConfig { | ||
pub fn new( | ||
endpoint: &Endpoint, | ||
rollup_endpoint: &Endpoint, | ||
kernel_log_file: &Path, | ||
) -> Self { | ||
Self { | ||
endpoint: endpoint.clone(), | ||
rollup_endpoint: rollup_endpoint.clone(), | ||
kernel_log_file: kernel_log_file.to_path_buf(), | ||
} | ||
} | ||
} |
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,31 @@ | ||
use super::Task; | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use jstz_node::{config::JstzNodeConfig, run_with_config}; | ||
use tokio::task::JoinHandle; | ||
|
||
pub struct JstzNode { | ||
handle: JoinHandle<Result<()>>, | ||
config: JstzNodeConfig, | ||
} | ||
|
||
#[async_trait] | ||
impl Task for JstzNode { | ||
type Config = JstzNodeConfig; | ||
|
||
async fn spawn(config: Self::Config) -> Result<Self> { | ||
let cfg = config.clone(); | ||
let handle = tokio::spawn(async move { run_with_config(cfg).await }); | ||
Ok(JstzNode { handle, config }) | ||
} | ||
|
||
async fn kill(&mut self) -> Result<()> { | ||
self.handle.abort(); | ||
Ok(()) | ||
} | ||
|
||
async fn health_check(&self) -> Result<bool> { | ||
let res = reqwest::get(format!("{}/health", self.config.endpoint)).await; | ||
Ok(res.is_ok_and(|res| res.status().is_success())) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mod child_wrapper; | ||
mod file; | ||
pub mod jstz_node; | ||
pub mod jstzd; | ||
pub mod octez_baker; | ||
pub mod octez_node; | ||
|
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,22 @@ | ||
use jstz_node::config::JstzNodeConfig; | ||
use jstzd::task::{utils::retry, Task}; | ||
use octez::{r#async::endpoint::Endpoint, unused_port}; | ||
use tempfile::NamedTempFile; | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn jstz_node_test() { | ||
let endpoint = Endpoint::localhost(unused_port()); | ||
let mock_rollup_endpoint = Endpoint::localhost(unused_port()); | ||
let tempfile = NamedTempFile::new().unwrap(); | ||
let jstz_node_config = | ||
JstzNodeConfig::new(&endpoint, &mock_rollup_endpoint, tempfile.path()); | ||
let mut jstz_node = jstzd::task::jstz_node::JstzNode::spawn(jstz_node_config) | ||
.await | ||
.unwrap(); | ||
let jstz_node_ready = | ||
retry(10, 1000, || async { jstz_node.health_check().await }).await; | ||
assert!(jstz_node_ready); | ||
jstz_node.kill().await.unwrap(); | ||
let is_alive = jstz_node.health_check().await.unwrap(); | ||
assert!(!is_alive); | ||
} |