diff --git a/crates/jstzd/src/config.rs b/crates/jstzd/src/config.rs index f66a0a124..f06f1469a 100644 --- a/crates/jstzd/src/config.rs +++ b/crates/jstzd/src/config.rs @@ -1,6 +1,5 @@ use octez::unused_port; use rust_embed::Embed; -use std::path::Path; use crate::task::jstzd::JstzdConfig; use crate::{ @@ -15,6 +14,7 @@ use octez::r#async::protocol::{ use octez::r#async::{ baker::{BakerBinaryPath, OctezBakerConfig, OctezBakerConfigBuilder}, client::{OctezClientConfig, OctezClientConfigBuilder}, + file::FileWrapper, node_config::{OctezNodeConfig, OctezNodeConfigBuilder}, protocol::{BootstrapAccount, ProtocolParameterBuilder}, rollup::{OctezRollupConfigBuilder, RollupDataDir}, @@ -24,7 +24,6 @@ use tezos_crypto_rs::hash::SmartRollupHash; use tokio::io::AsyncReadExt; const DEFAULT_JSTZD_SERVER_PORT: u16 = 55555; -const KERNEL_DEBUG_FILE: &str = "kernel.log"; const ACTIVATOR_PK: &str = "edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2"; pub const BOOTSTRAP_CONTRACT_NAMES: [(&str, &str); 2] = [ ("exchanger", EXCHANGER_ADDRESS), @@ -93,8 +92,9 @@ pub(crate) async fn build_config( &protocol_params, )?; - let kernel_debug_file = Path::new(KERNEL_DEBUG_FILE); let octez_node_endpoint = octez_node_config.rpc_endpoint.clone(); + let kernel_debug_file = FileWrapper::default(); + let kernel_debug_file_path = kernel_debug_file.path(); let octez_rollup_config = OctezRollupConfigBuilder::new( octez_node_endpoint, octez_client_config.base_dir().into(), @@ -113,7 +113,7 @@ pub(crate) async fn build_config( let jstz_node_config = JstzNodeConfig::new( &jstz_node_rpc_endpoint, &octez_rollup_config.rpc_endpoint, - kernel_debug_file, + &kernel_debug_file_path, ); let server_port = config.server_port.unwrap_or(DEFAULT_JSTZD_SERVER_PORT); @@ -236,7 +236,7 @@ mod tests { use tezos_crypto_rs::hash::ContractKt1Hash; use tokio::io::AsyncReadExt; - use super::{jstz_rollup_path, ACTIVATOR_PK, JSTZ_ROLLUP_ADDRESS, KERNEL_DEBUG_FILE}; + use super::{jstz_rollup_path, ACTIVATOR_PK, JSTZ_ROLLUP_ADDRESS}; use super::Config; @@ -546,16 +546,6 @@ mod tests { config.octez_rollup_config().address.to_base58_check(), JSTZ_ROLLUP_ADDRESS ); - assert_eq!( - config - .octez_rollup_config() - .kernel_debug_file - .as_ref() - .unwrap() - .to_str() - .unwrap(), - KERNEL_DEBUG_FILE, - ); assert_eq!( config.octez_rollup_config().data_dir, RollupDataDir::TempWithPreImages { @@ -566,10 +556,6 @@ mod tests { config.octez_rollup_config().boot_sector_file, jstz_rollup_path::kernel_installer_path() ); - assert_eq!( - config.jstz_node_config().kernel_log_file.to_str().unwrap(), - KERNEL_DEBUG_FILE - ); assert_eq!( config.jstz_node_config().rollup_endpoint, diff --git a/crates/jstzd/src/task/octez_rollup.rs b/crates/jstzd/src/task/octez_rollup.rs index 89bdbf4f9..282225ef9 100644 --- a/crates/jstzd/src/task/octez_rollup.rs +++ b/crates/jstzd/src/task/octez_rollup.rs @@ -60,12 +60,18 @@ impl Task for OctezRollup { &config.rpc_endpoint, &config.log_file, ); - let inner = ChildWrapper::new_shared(rollup.run( - &config.address, - &config.operator, - Some(&config.boot_sector_file), - config.kernel_debug_file.as_deref(), - )?); + let inner = ChildWrapper::new_shared( + rollup.run( + &config.address, + &config.operator, + Some(&config.boot_sector_file), + config + .kernel_debug_file + .as_ref() + .map(|v| v.path()) + .as_deref(), + )?, + ); Ok(Self { inner, config, diff --git a/crates/jstzd/tests/jstzd_test.rs b/crates/jstzd/tests/jstzd_test.rs index 380b99e9f..e534c329c 100644 --- a/crates/jstzd/tests/jstzd_test.rs +++ b/crates/jstzd/tests/jstzd_test.rs @@ -14,6 +14,7 @@ use jstzd::{BOOTSTRAP_CONTRACT_NAMES, JSTZ_ROLLUP_ADDRESS}; use octez::r#async::baker::{BakerBinaryPath, OctezBakerConfigBuilder}; use octez::r#async::client::{OctezClient, OctezClientConfigBuilder}; use octez::r#async::endpoint::Endpoint; +use octez::r#async::file::FileWrapper; use octez::r#async::node_config::{OctezNodeConfigBuilder, OctezNodeRunOptionsBuilder}; use octez::r#async::protocol::{ BootstrapAccount, BootstrapContract, BootstrapSmartRollup, ProtocolParameterBuilder, @@ -43,7 +44,7 @@ async fn jstzd_test() { .unwrap(); let jstz_node_rpc_endpoint = Endpoint::localhost(unused_port()); let jstzd_port = unused_port(); - let (mut jstzd, config, kernel_debug_file) = create_jstzd_server( + let (mut jstzd, config) = create_jstzd_server( &octez_node_rpc_endpoint, &rollup_rpc_endpoint, &jstz_node_rpc_endpoint, @@ -54,7 +55,16 @@ async fn jstzd_test() { jstzd.run(false).await.unwrap(); ensure_jstzd_components_are_up(&jstzd, &octez_node_rpc_endpoint, jstzd_port).await; - ensure_rollup_is_logging_to(kernel_debug_file).await; + match config + .octez_rollup_config() + .kernel_debug_file + .as_ref() + .unwrap() + .as_ref() + { + FileWrapper::TempFile(v) => ensure_rollup_is_logging_to(v).await, + _ => panic!("kernel_debug_file should be a temp file"), + } let octez_client = OctezClient::new(config.octez_client_config().clone()); check_bootstrap_contracts(&octez_client).await; @@ -88,7 +98,7 @@ async fn create_jstzd_server( rollup_rpc_endpoint: &Endpoint, jstz_node_rpc_endpoint: &Endpoint, jstzd_port: u16, -) -> (JstzdServer, JstzdConfig, NamedTempFile) { +) -> (JstzdServer, JstzdConfig) { let run_options = OctezNodeRunOptionsBuilder::new() .set_synchronisation_threshold(0) .set_network("sandbox") @@ -140,7 +150,8 @@ async fn create_jstzd_server( .set_octez_node_endpoint(&octez_node_config.rpc_endpoint) .build() .expect("Failed to build baker config"); - let kernel_debug_file = NamedTempFile::new().unwrap(); + let kernel_debug_file = FileWrapper::default(); + let kernel_debug_file_path = kernel_debug_file.path(); let rollup_config = OctezRollupConfigBuilder::new( octez_node_rpc_endpoint.clone(), octez_client_config.base_dir().into(), @@ -152,13 +163,13 @@ async fn create_jstzd_server( preimages_dir: rollup_preimages_dir, }) .set_rpc_endpoint(rollup_rpc_endpoint) - .set_kernel_debug_file(kernel_debug_file.path()) + .set_kernel_debug_file(kernel_debug_file) .build() .expect("failed to build rollup config"); let jstz_node_config = JstzNodeConfig::new( jstz_node_rpc_endpoint, &rollup_config.rpc_endpoint, - kernel_debug_file.path(), + &kernel_debug_file_path, ); let config = JstzdConfig::new( octez_node_config, @@ -168,11 +179,7 @@ async fn create_jstzd_server( jstz_node_config, protocol_params, ); - ( - JstzdServer::new(config.clone(), jstzd_port), - config, - kernel_debug_file, - ) + (JstzdServer::new(config.clone(), jstzd_port), config) } async fn ensure_jstzd_components_are_up( @@ -344,7 +351,7 @@ async fn check_bootstrap_contracts(octez_client: &OctezClient) { ); } } -async fn ensure_rollup_is_logging_to(kernel_debug_file: NamedTempFile) { +async fn ensure_rollup_is_logging_to(kernel_debug_file: &NamedTempFile) { let mut file = kernel_debug_file.reopen().unwrap(); let mut contents = String::new(); file.read_to_string(&mut contents).unwrap(); diff --git a/crates/octez/src/async/rollup.rs b/crates/octez/src/async/rollup.rs index 0e8de688f..5aa76003b 100644 --- a/crates/octez/src/async/rollup.rs +++ b/crates/octez/src/async/rollup.rs @@ -56,7 +56,8 @@ pub struct OctezRollupConfigBuilder { /// if None, use localhost with random port pub rpc_endpoint: Option, /// The path to the kernel debug file - kernel_debug_file: Option, + #[serde(skip_deserializing)] + kernel_debug_file: Option, /// Path to the log file. log_file: Option, } @@ -99,8 +100,8 @@ impl OctezRollupConfigBuilder { self } - pub fn set_kernel_debug_file(mut self, kernel_debug_file: &Path) -> Self { - self.kernel_debug_file = Some(kernel_debug_file.to_path_buf()); + pub fn set_kernel_debug_file(mut self, kernel_debug_file: FileWrapper) -> Self { + self.kernel_debug_file.replace(kernel_debug_file); self } @@ -125,7 +126,7 @@ impl OctezRollupConfigBuilder { let uri = Uri::from_str(&format!("127.0.0.1:{}", unused_port())).unwrap(); Endpoint::try_from(uri).unwrap() }), - kernel_debug_file: self.kernel_debug_file, + kernel_debug_file: self.kernel_debug_file.map(Arc::new), log_file: Arc::new(match self.log_file { Some(v) => FileWrapper::try_from(v)?, None => FileWrapper::default(), @@ -147,7 +148,7 @@ pub struct OctezRollupConfig { pub boot_sector_file: PathBuf, pub rpc_endpoint: Endpoint, pub pvm_kind: SmartRollupPvmKind, - pub kernel_debug_file: Option, + pub kernel_debug_file: Option>, pub log_file: Arc, } @@ -237,9 +238,13 @@ impl OctezRollup { #[cfg(test)] mod test { + use tempfile::NamedTempFile; + use super::*; #[test] fn builds_rollup_config() { + let kernel_debug_file = NamedTempFile::new().unwrap(); + let kernel_debug_file_path = kernel_debug_file.path().to_path_buf(); let rollup_config = OctezRollupConfigBuilder::new( Endpoint::localhost(1234), PathBuf::from("/base_dir"), @@ -247,7 +252,7 @@ mod test { "operator".to_owned(), PathBuf::from("/tmp/boot_sector.hex"), ) - .set_kernel_debug_file(Path::new("/tmp/kernel_debug.log")) + .set_kernel_debug_file(FileWrapper::TempFile(kernel_debug_file)) .build() .unwrap(); assert_eq!(rollup_config.pvm_kind, SmartRollupPvmKind::Wasm); @@ -277,13 +282,15 @@ mod test { format!("http://127.0.0.1:{}", port) ); assert_eq!( - rollup_config.kernel_debug_file, - Some(PathBuf::from("/tmp/kernel_debug.log")) + rollup_config.kernel_debug_file.map(|v| v.path()), + Some(kernel_debug_file_path) ); } #[test] fn serialize_config() { + let kernel_debug_file = NamedTempFile::new().unwrap(); + let kernel_debug_file_path = kernel_debug_file.path().to_path_buf(); let log_file = tempfile::NamedTempFile::new().unwrap().into_temp_path(); let config = OctezRollupConfigBuilder::new( Endpoint::localhost(1234), @@ -292,7 +299,7 @@ mod test { "operator".to_owned(), PathBuf::from("/tmp/boot_sector.hex"), ) - .set_kernel_debug_file(Path::new("/tmp/kernel_debug.log")) + .set_kernel_debug_file(FileWrapper::TempFile(kernel_debug_file)) .set_data_dir(RollupDataDir::TempWithPreImages { preimages_dir: PathBuf::from("/tmp/pre_images"), }) @@ -312,7 +319,7 @@ 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": kernel_debug_file_path.to_string_lossy(), "log_file": log_file.to_string_lossy() }) );