Skip to content

Commit 59c719d

Browse files
Merge pull request lightningdevkit#3 from lndk-org/fix-dir-structure
Fix up directory structure
2 parents 0166347 + c50f65d commit 59c719d

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

src/config.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,39 @@
11
use bitcoin::network::constants::Network;
22
use chrono::Utc;
33
use lightning::ln::msgs::NetAddress;
4-
use std::{env, fs};
4+
use std::fs;
5+
use std::path::PathBuf;
56
use tempfile::{Builder, TempDir};
67

78
pub struct LdkUserInfo {
89
pub bitcoind_rpc_username: String,
910
pub bitcoind_rpc_password: String,
1011
pub bitcoind_rpc_port: u16,
1112
pub bitcoind_rpc_host: String,
13+
pub ldk_data_dir: PathBuf,
1214
pub ldk_peer_listening_port: u16,
1315
pub ldk_announced_listen_addr: Vec<NetAddress>,
1416
pub ldk_announced_node_name: [u8; 32],
1517
pub network: Network,
1618
}
1719

18-
1920
// Here we initialize three layers of directories needed for our tests. We won't persist ldk data, but we'll persist
2021
// the logs to help with debugging.
21-
pub(crate) fn setup_data_and_log_dirs(test_name: &str) -> (String, TempDir, String) {
22-
// If necessary, we initialize the lndk-tests dir, which holds all of the lndk related test data.
23-
let lndk_tests_folder = "lndk-tests";
24-
let lndk_test_dir = env::temp_dir().join(lndk_tests_folder);
25-
fs::create_dir_all(lndk_test_dir.clone()).unwrap();
26-
27-
let ldk_dir_binding = Builder::new()
22+
pub(crate) fn setup_data_and_log_dirs(ldk_dir: PathBuf, test_name: &str) -> (String, TempDir, String) {
23+
let ldk_data_dir_binding = Builder::new()
2824
.prefix("ldk-data-dir")
29-
.tempdir_in(lndk_test_dir.clone())
25+
.tempdir_in(ldk_dir.clone())
3026
.unwrap();
31-
let ldk_data_dir = String::from(ldk_dir_binding.path().to_str().unwrap());
27+
let ldk_data_dir = String::from(ldk_data_dir_binding.path().to_str().unwrap());
3228

3329
// Create the ldk-logs dir, which we'll persist after the tests are over for debugging.
3430
let now_timestamp = Utc::now();
3531
let timestamp = now_timestamp.format("%d-%m-%Y-%H%M");
36-
let ldk_log_dir_binding = lndk_test_dir.join(format!("ldk-logs-{test_name}-{timestamp}"));
32+
let ldk_log_dir_binding = ldk_dir.join(format!("ldk-logs-{test_name}-{timestamp}"));
3733
let ldk_log_dir = String::from(ldk_log_dir_binding.as_path().to_str().unwrap());
3834

3935
// Initialize the LDK data directory if necessary.
40-
fs::create_dir_all(ldk_data_dir.clone()).unwrap();
4136
fs::create_dir_all(ldk_log_dir.clone()).unwrap();
4237

43-
(ldk_data_dir, ldk_dir_binding, ldk_log_dir)
38+
(ldk_data_dir, ldk_data_dir_binding, ldk_log_dir)
4439
}

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ async fn handle_ldk_events(
471471
}
472472

473473
pub async fn start_ldk(args: config::LdkUserInfo, test_name: &str) -> node_api::Node {
474-
let (ldk_data_dir, _ldk_dir_binding, ldk_log_dir) = config::setup_data_and_log_dirs(test_name);
474+
let (ldk_data_dir, ldk_data_dir_binding, ldk_log_dir) = config::setup_data_and_log_dirs(args.ldk_data_dir, test_name);
475475
let ldk_addr = args.ldk_announced_listen_addr.clone();
476476
let ldk_announced_node_name = args.ldk_announced_node_name.clone();
477477

@@ -956,5 +956,6 @@ pub async fn start_ldk(args: config::LdkUserInfo, test_name: &str) -> node_api::
956956
background_processor,
957957
stop_listen_connect,
958958
listening_port: args.ldk_peer_listening_port.clone(),
959+
ldk_data_dir: ldk_data_dir_binding,
959960
};
960961
}

src/node_api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
1616
use std::sync::{Arc, Mutex};
1717
use std::sync::atomic::{AtomicBool, Ordering};
1818
use std::time::Duration;
19+
use tempfile::TempDir;
1920
use tokio::sync::watch::Sender;
2021

2122
pub(crate) type Router = DefaultRouter<
@@ -69,6 +70,7 @@ pub struct Node {
6970

7071
// Config values
7172
pub(crate) listening_port: u16,
73+
pub(crate) ldk_data_dir: TempDir,
7274
}
7375

7476
impl Node {

0 commit comments

Comments
 (0)