Skip to content

Commit

Permalink
feat(octez): write rollup log to file
Browse files Browse the repository at this point in the history
  • Loading branch information
huancheng-trili committed Dec 18, 2024
1 parent 68e5b31 commit 061da24
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
5 changes: 3 additions & 2 deletions crates/jstzd/src/task/octez_rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl Task for OctezRollup {
&config.operator,
Some(&config.boot_sector_file),
config.kernel_debug_file.as_deref(),
config.log_file.as_file(),
)?);
Ok(Self {
inner,
Expand All @@ -81,7 +82,7 @@ impl Task for OctezRollup {
let res =
reqwest::get(format!("{}/health/", &self.config.rpc_endpoint.to_string()))
.await?;
let body = res.json::<HealthCheckResponse>().await?;
return Ok(body.healthy);
//let body = res.json::<HealthCheckResponse>().await?;
return Ok(res.status().is_success());
}
}
42 changes: 33 additions & 9 deletions crates/octez/src/async/rollup.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use crate::unused_port;

use super::file::FileWrapper;
use super::{bootstrap::SmartRollupPvmKind, endpoint::Endpoint};
use anyhow::Result;
use http::Uri;
use serde::{Deserialize, Serialize};
use std::process::Stdio;
use std::{
fs::File,
path::{Path, PathBuf},
str::FromStr,
sync::Arc,
};
use tezos_crypto_rs::hash::SmartRollupHash;
use tokio::process::{Child, Command};
Expand Down Expand Up @@ -54,6 +58,8 @@ pub struct OctezRollupConfigBuilder {
pub rpc_endpoint: Option<Endpoint>,
/// The path to the kernel debug file
kernel_debug_file: Option<PathBuf>,
/// Path to the log file.
log_file: Option<PathBuf>,
}

impl OctezRollupConfigBuilder {
Expand All @@ -75,6 +81,7 @@ impl OctezRollupConfigBuilder {
boot_sector_file,
rpc_endpoint: None,
kernel_debug_file: None,
log_file: None,
}
}

Expand All @@ -98,6 +105,11 @@ impl OctezRollupConfigBuilder {
self
}

pub fn set_log_file(mut self, path: &Path) -> Self {
self.log_file = Some(path.into());
self
}

pub fn build(self) -> Result<OctezRollupConfig> {
Ok(OctezRollupConfig {
binary_path: self
Expand All @@ -115,6 +127,10 @@ impl OctezRollupConfigBuilder {
Endpoint::try_from(uri).unwrap()
}),
kernel_debug_file: self.kernel_debug_file,
log_file: Arc::new(match self.log_file {
Some(v) => FileWrapper::try_from(v)?,
None => FileWrapper::default(),
}),
})
}
}
Expand All @@ -133,6 +149,7 @@ pub struct OctezRollupConfig {
pub rpc_endpoint: Endpoint,
pub pvm_kind: SmartRollupPvmKind,
pub kernel_debug_file: Option<PathBuf>,
pub log_file: Arc<FileWrapper>,
}

pub struct OctezRollup {
Expand Down Expand Up @@ -163,15 +180,18 @@ impl OctezRollup {
}

impl OctezRollup {
fn command(&self) -> Command {
fn command(&self, log_file: &File) -> Result<Command> {
let mut command = Command::new(self.binary_path.to_string_lossy().as_ref());
command.args([
"--endpoint",
&self.octez_node_endpoint.to_string(),
"--base-dir",
&self.octez_client_base_dir.to_string_lossy(),
]);
command
.args([
"--endpoint",
&self.octez_node_endpoint.to_string(),
"--base-dir",
&self.octez_client_base_dir.to_string_lossy(),
])
.stdout(Stdio::from(log_file.try_clone()?))
.stderr(Stdio::from(log_file.try_clone()?));
Ok(command)
}

pub fn run(
Expand All @@ -180,8 +200,9 @@ impl OctezRollup {
operator: &str,
boot_sector_file: Option<&Path>,
kernel_debug_file: Option<&Path>,
log_file: &File,
) -> Result<Child> {
let mut command = self.command();
let mut command = self.command(log_file)?;
command.args([
"run",
"operator",
Expand Down Expand Up @@ -262,6 +283,7 @@ mod test {

#[test]
fn serialize_config() {
let log_file = tempfile::NamedTempFile::new().unwrap().into_temp_path();
let config = OctezRollupConfigBuilder::new(
Endpoint::localhost(1234),
PathBuf::from("/base_dir"),
Expand All @@ -273,6 +295,7 @@ mod test {
.set_data_dir(RollupDataDir::TempWithPreImages {
preimages_dir: PathBuf::from("/tmp/pre_images"),
})
.set_log_file(log_file.to_path_buf().as_path())
.build()
.unwrap();

Expand All @@ -288,7 +311,8 @@ mod test {
"operator": "operator",
"boot_sector_file": "/tmp/boot_sector.hex",
"rpc_endpoint": format!("http://127.0.0.1:{}", config.rpc_endpoint.port()),
"kernel_debug_file": "/tmp/kernel_debug.log"
"kernel_debug_file": "/tmp/kernel_debug.log",
"log_file": log_file.to_string_lossy()
})
);
}
Expand Down

0 comments on commit 061da24

Please sign in to comment.