Skip to content

Commit 11309a4

Browse files
committed
debug: reworking config dir.
1 parent 80eeefa commit 11309a4

2 files changed

Lines changed: 29 additions & 15 deletions

File tree

util/movement-aptos/movement-aptos-core-inner/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::movement_aptos::{runtime, MovementAptos};
1010
use aptos_node::create_single_node_test_config;
1111

1212
#[derive(Debug, Serialize, Deserialize, Clone)]
13-
pub struct NodeConfigWrapper(NodeConfig);
13+
pub struct NodeConfigWrapper(pub(crate) NodeConfig);
1414

1515
impl NodeConfigWrapper {
1616
pub fn new(node_config: NodeConfig) -> Self {

util/movement-aptos/movement-aptos-core-inner/src/movement_aptos.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use aptos_config::config::NodeConfig;
22
use kestrel::State;
33
use std::path::PathBuf;
44
pub mod rest_api;
5-
use anyhow::Context;
65
use kestrel::process::{command::Command, ProcessOperations};
76
pub mod runtime;
7+
use crate::config::{Config, NodeConfigWrapper};
8+
use anyhow::Context;
89
pub use rest_api::RestApi;
910
use std::path::Path;
1011

@@ -69,18 +70,23 @@ where
6970
let runtime = R::try_new()?;
7071

7172
// create a .debug dir
72-
let timestamp = chrono::Utc::now().timestamp_millis();
73-
let unique_id = uuid::Uuid::new_v4();
74-
let debug_dir = Path::new(".debug").join(format!(
75-
"movement-aptos-core-{}-{}",
76-
timestamp,
77-
unique_id.to_string().split('-').next().unwrap()
78-
));
79-
std::fs::create_dir_all(debug_dir.clone())
80-
.map_err(|e| MovementAptosError::Internal(e.into()))?;
73+
let db_dir = if multiprocess {
74+
let timestamp = chrono::Utc::now().timestamp_millis();
75+
let unique_id = uuid::Uuid::new_v4();
76+
let debug_dir = Path::new(".debug").join(format!(
77+
"movement-aptos-core-{}-{}",
78+
timestamp,
79+
unique_id.to_string().split('-').next().unwrap()
80+
));
81+
std::fs::create_dir_all(debug_dir.clone())
82+
.map_err(|e| MovementAptosError::Internal(e.into()))?;
83+
debug_dir
84+
} else {
85+
Path::new("").to_path_buf()
86+
};
8187

8288
let movement_aptos =
83-
MovementAptos::new(node_config, log_file, runtime, multiprocess, debug_dir);
89+
MovementAptos::new(node_config, log_file, runtime, multiprocess, db_dir);
8490
Ok(movement_aptos)
8591
}
8692

@@ -131,13 +137,21 @@ where
131137
pub(crate) async fn run_node_in_process(&self) -> Result<(), MovementAptosError> {
132138
// write the config to a file
133139
let config_path = self.workspace.join("config.json");
140+
let config = Config {
141+
node_config: NodeConfigWrapper(self.node_config.clone()),
142+
log_file: self.log_file.clone(),
143+
};
134144
std::fs::write(
135145
config_path.clone(),
136-
serde_json::to_string(&self.node_config)
137-
.map_err(|e| MovementAptosError::Internal(e.into()))?,
146+
serde_json::to_string(&config).map_err(|e| MovementAptosError::Internal(e.into()))?,
138147
)
139148
.map_err(|e| MovementAptosError::Internal(e.into()))?;
140149

150+
// create node_config data dir
151+
let data_dir = self.node_config.storage.dir.clone();
152+
std::fs::create_dir_all(data_dir.clone())
153+
.map_err(|e| MovementAptosError::Internal(e.into()))?;
154+
141155
// spawn the node in a new process
142156
let command = Command::line(
143157
"movement-aptos",
@@ -150,7 +164,7 @@ where
150164
.context("Failed to convert config path to str")
151165
.map_err(|e| MovementAptosError::Internal(e.into()))?,
152166
],
153-
Some(&self.workspace),
167+
None,
154168
false,
155169
vec![],
156170
vec![],

0 commit comments

Comments
 (0)