Skip to content

Commit 61e6114

Browse files
committed
debug: blocking issue.
1 parent 8bed653 commit 61e6114

2 files changed

Lines changed: 30 additions & 37 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
@@ -74,7 +74,7 @@ impl Config {
7474
let rng = rand::thread_rng();
7575

7676
let node_config = create_single_node_test_config(
77-
&None,
77+
&Some(db_dir.join("config.json")),
7878
&None,
7979
db_dir.as_path(),
8080
true,

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

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ pub mod rest_api;
55
use kestrel::process::{command::Command, ProcessOperations};
66
pub mod runtime;
77
use crate::config::{Config, NodeConfigWrapper};
8-
use anyhow::Context;
98
pub use rest_api::RestApi;
10-
use std::path::Path;
119

1210
use runtime::Runtime;
1311

@@ -70,20 +68,7 @@ where
7068
let runtime = R::try_new()?;
7169

7270
// create a .debug dir
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-
};
71+
let db_dir = node_config.storage.dir().clone();
8772

8873
let movement_aptos =
8974
MovementAptos::new(node_config, log_file, runtime, multiprocess, db_dir);
@@ -102,6 +87,7 @@ where
10287

10388
/// Runs the internal node logic
10489
pub(crate) async fn run_node_in_thread(&self) -> Result<(), MovementAptosError> {
90+
println!("Running node in thread");
10591
// Clone necessary data for the closure
10692
let node_config = self.node_config.clone();
10793
let log_file = self.log_file.clone();
@@ -135,36 +121,40 @@ where
135121
}
136122

137123
pub(crate) async fn run_node_in_process(&self) -> Result<(), MovementAptosError> {
124+
println!("Running node in process");
138125
// write the config to a file
139126
let config_path = self.workspace.join("config.json");
140127
let config = Config {
141128
node_config: NodeConfigWrapper(self.node_config.clone()),
142129
log_file: self.log_file.clone(),
143130
};
144-
std::fs::write(
145-
config_path.clone(),
146-
serde_json::to_string(&config).map_err(|e| MovementAptosError::Internal(e.into()))?,
147-
)
148-
.map_err(|e| MovementAptosError::Internal(e.into()))?;
131+
132+
let serialized_config =
133+
serde_json::to_string(&config).map_err(|e| MovementAptosError::Internal(e.into()))?;
134+
println!("Serialized config: {:?}", serialized_config);
149135

150136
// create node_config data dir
151-
let data_dir = self.node_config.storage.dir.clone();
152-
std::fs::create_dir_all(data_dir.clone())
137+
let data_dir = self.node_config.get_data_dir();
138+
tokio::fs::create_dir_all(data_dir)
139+
.await
140+
.map_err(|e| MovementAptosError::Internal(e.into()))?;
141+
142+
println!("Data dir: {:?}", data_dir);
143+
144+
// write the config to the file
145+
// seems to be blocking here
146+
// perhaps somehow being opened in read?
147+
tokio::fs::write(config_path.clone(), serialized_config)
148+
.await
153149
.map_err(|e| MovementAptosError::Internal(e.into()))?;
150+
println!("Config path: {:?}", config_path);
154151

155152
// spawn the node in a new process
153+
println!("Spawning node in process");
156154
let command = Command::line(
157155
"movement-aptos",
158-
vec![
159-
"run",
160-
"using",
161-
"--config-path",
162-
config_path
163-
.to_str()
164-
.context("Failed to convert config path to str")
165-
.map_err(|e| MovementAptosError::Internal(e.into()))?,
166-
],
167-
None,
156+
vec!["run", "using", "--config-path", "config.json"],
157+
Some(&self.workspace),
168158
false,
169159
vec![],
170160
vec![],
@@ -248,10 +238,10 @@ mod tests {
248238
));
249239

250240
// create parent dirs
251-
std::fs::create_dir_all(db_dir.clone())?;
241+
tokio::fs::create_dir_all(db_dir.clone()).await?;
252242

253243
let rng = thread_rng();
254-
let node_config = create_single_node_test_config(
244+
let mut node_config = create_single_node_test_config(
255245
&None,
256246
&None,
257247
db_dir.as_path(),
@@ -261,6 +251,7 @@ mod tests {
261251
&aptos_cached_packages::head_release_bundle().clone(),
262252
rng,
263253
)?;
254+
node_config.set_data_dir(db_dir.clone());
264255

265256
let movement_aptos = MovementAptos::<runtime::TokioTest>::try_new(node_config, None, true)?;
266257
let rest_api_state = movement_aptos.rest_api().read().clone();
@@ -270,7 +261,9 @@ mod tests {
270261
Ok::<_, MovementAptosError>(())
271262
});
272263

273-
rest_api_state.wait_for(tokio::time::Duration::from_secs(30)).await?;
264+
// You can comment and uncomment this to see that the rest api wait for is not causing the problem
265+
// tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
266+
rest_api_state.wait_for(tokio::time::Duration::from_secs(10)).await?;
274267

275268
println!("ENDING MOVEMENT APTOS");
276269

0 commit comments

Comments
 (0)