Skip to content

Commit

Permalink
feat: support home dir via env and dry up references
Browse files Browse the repository at this point in the history
  • Loading branch information
snormore committed Jun 5, 2024
1 parent 650afb7 commit 29cd0b7
Show file tree
Hide file tree
Showing 34 changed files with 162 additions and 49 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3969,6 +3969,8 @@ dependencies = [
"derive_more",
"fn-sdk",
"hex",
"lazy_static",
"lightning-utils",
"ndarray",
"ort",
"safetensors",
Expand Down Expand Up @@ -5865,6 +5867,7 @@ dependencies = [
"lightning-interfaces",
"lightning-notifier",
"lightning-test-utils",
"lightning-utils",
"resolved-pathbuf",
"rocksdb",
"serde",
Expand All @@ -5884,6 +5887,7 @@ dependencies = [
"bytes",
"derive_more",
"lightning-interfaces",
"lightning-utils",
"parking_lot",
"rand 0.8.5",
"resolved-pathbuf",
Expand Down Expand Up @@ -6142,6 +6146,7 @@ dependencies = [
"anyhow",
"bytes",
"lightning-ebpf-common",
"lightning-utils",
"log",
"notify",
"once_cell",
Expand Down Expand Up @@ -6647,6 +6652,7 @@ dependencies = [
"lightning-signer",
"lightning-test-utils",
"lightning-topology",
"lightning-utils",
"resolved-pathbuf",
"rocksdb",
"serde",
Expand Down Expand Up @@ -6739,6 +6745,7 @@ dependencies = [
"lightning-notifier",
"lightning-signer",
"lightning-test-utils",
"lightning-utils",
"panic-report",
"resolved-pathbuf",
"serde",
Expand Down Expand Up @@ -6806,7 +6813,9 @@ dependencies = [
"fleek-crypto",
"futures",
"hp-fixed",
"lazy_static",
"lightning-interfaces",
"lightning-utils",
"plotters",
"rand 0.8.5",
"rand_chacha",
Expand Down Expand Up @@ -6872,6 +6881,7 @@ dependencies = [
"json5",
"lazy_static",
"lightning-ebpf-service",
"lightning-utils",
"log",
"ratatui",
"resolved-pathbuf",
Expand Down Expand Up @@ -6919,6 +6929,7 @@ dependencies = [
"autometrics",
"ethers",
"fleek-crypto",
"lazy_static",
"lightning-interfaces",
"reqwest",
"resolved-pathbuf",
Expand Down
4 changes: 3 additions & 1 deletion core/application/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use lightning_utils::config::LIGHTNING_HOME_DIR;
use resolved_pathbuf::ResolvedPathBuf;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -42,7 +43,8 @@ impl Default for Config {
testnet: true,
storage: StorageConfig::RocksDb,
db_path: Some(
"~/.lightning/data/app_db"
LIGHTNING_HOME_DIR
.join("data/app_db")
.try_into()
.expect("Failed to resolve path"),
),
Expand Down
1 change: 1 addition & 0 deletions core/archive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"

[dependencies]
lightning-interfaces = { path = "../interfaces" }
lightning-utils = { path = "../utils" }
affair.workspace = true
anyhow.workspace = true
resolved-pathbuf.workspace = true
Expand Down
4 changes: 3 additions & 1 deletion core/archive/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use lightning_utils::config::LIGHTNING_HOME_DIR;
use resolved_pathbuf::ResolvedPathBuf;
use serde::{Deserialize, Serialize};

Expand All @@ -13,7 +14,8 @@ impl Default for Config {
fn default() -> Self {
Self {
is_archive: false,
store_path: "~/.lightning/data/archiver"
store_path: LIGHTNING_HOME_DIR
.join("data/archiver")
.try_into()
.expect("Failed to resolve path"),
}
Expand Down
1 change: 1 addition & 0 deletions core/blockstore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
lightning-interfaces = { path = "../interfaces" }
lightning-utils = { path = "../utils" }
bincode.workspace = true
resolved-pathbuf.workspace = true
blake3-tree = { path = "../../lib/blake3-tree" }
Expand Down
7 changes: 5 additions & 2 deletions core/blockstore/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use lightning_utils::config::LIGHTNING_HOME_DIR;
use resolved_pathbuf::ResolvedPathBuf;
use serde::{Deserialize, Serialize};

pub const ROOT_DIR_DEFAULT: &str = "~/.lightning/blockstore";
pub const INTERNAL_DIR: &str = "internal";
pub const BLOCK_DIR: &str = "block";
pub const TMP_DIR: &str = "tmp";
Expand All @@ -14,7 +14,10 @@ pub struct Config {
impl Default for Config {
fn default() -> Self {
Self {
root: ResolvedPathBuf::try_from(ROOT_DIR_DEFAULT).unwrap(),
root: LIGHTNING_HOME_DIR
.join("blockstore")
.try_into()
.expect("Failed to resolve path"),
}
}
}
3 changes: 2 additions & 1 deletion core/cli/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use std::path::PathBuf;

use clap::{arg, ArgAction, Parser, Subcommand};
use lightning_utils::config::LIGHTNING_HOME_DIR;

use crate::commands::admin::AdminSubCmd;

#[derive(Parser)]
#[command(about, version = crate::VERSION)]
pub struct Args {
/// Path to the toml configuration file
#[arg(short, long, global = true, default_value_t = String::from("~/.lightning/config.toml") )]
#[arg(short, long, global = true, default_value_t = String::from(LIGHTNING_HOME_DIR.join("config.toml").to_string_lossy().as_ref()) )]
pub config: String,
/// Determines that we should be using the mock consensus backend.
#[arg(long, global = true, default_value_t = false)]
Expand Down
5 changes: 4 additions & 1 deletion core/cli/src/commands/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anyhow::{Error, Result};
use clap::{Args, Subcommand};
use lightning_ebpf_service::{ConfigSource, PathConfig};
use lightning_tui::app::App;
use lightning_utils::config::LIGHTNING_HOME_DIR;
use once_cell::sync::OnceCell;
use resolved_pathbuf::ResolvedPathBuf;
use tracing::debug;
Expand Down Expand Up @@ -79,7 +80,9 @@ pub async fn exec(cmd: AdminSubCmd) -> Result<()> {
PATH_CONFIG.set(config).expect("Not to be initialized yet");
BIND_PATH
.set(
ResolvedPathBuf::try_from("~/.lightning/ebpf/ctrl")
LIGHTNING_HOME_DIR
.join("ebpf/ctrl")
.try_into()
.expect("Path resolution not to fail"),
)
.expect("Not to be initialized yet");
Expand Down
4 changes: 3 additions & 1 deletion core/consensus/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use lightning_utils::config::LIGHTNING_HOME_DIR;
use resolved_pathbuf::ResolvedPathBuf;
use serde::{Deserialize, Serialize};

Expand All @@ -10,7 +11,8 @@ pub struct Config {
impl Default for Config {
fn default() -> Self {
Self {
store_path: "~/.lightning/data/narwhal_store"
store_path: LIGHTNING_HOME_DIR
.join("data/narwhal_store")
.try_into()
.expect("Failed to resolve path"),
}
Expand Down
4 changes: 3 additions & 1 deletion core/dack-aggregator/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::time::Duration;

use lightning_utils::config::LIGHTNING_HOME_DIR;
use resolved_pathbuf::ResolvedPathBuf;
use serde::{Deserialize, Serialize};

Expand All @@ -15,7 +16,8 @@ impl Default for Config {
fn default() -> Self {
Self {
submit_interval: Duration::from_secs(10),
db_path: "~/.lightning/data/dack_aggregator"
db_path: LIGHTNING_HOME_DIR
.join("data/dack_aggregator")
.try_into()
.expect("Failed to resolve path"),
}
Expand Down
3 changes: 2 additions & 1 deletion core/e2e/src/bin/spawn_swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use lightning_application::app::Application;
use lightning_e2e::swarm::Swarm;
use lightning_e2e::utils::shutdown;
use lightning_interfaces::prelude::*;
use lightning_test_utils::config::LIGHTNING_TEST_HOME_DIR;
use lightning_test_utils::logging;
use lightning_topology::Topology;
use resolved_pathbuf::ResolvedPathBuf;
Expand Down Expand Up @@ -52,7 +53,7 @@ async fn main() -> Result<()> {
.unwrap()
.as_millis() as u64;

let path = ResolvedPathBuf::try_from("~/.lightning-test/e2e/spawn-swarm").unwrap();
let path = ResolvedPathBuf::try_from(LIGHTNING_TEST_HOME_DIR.join("e2e/spawn-swarm")).unwrap();
if path.exists() {
fs::remove_dir_all(&path).expect("Failed to clean up swarm directory before test.");
}
Expand Down
3 changes: 2 additions & 1 deletion core/e2e/tests/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anyhow::Result;
use lightning_e2e::swarm::Swarm;
use lightning_e2e::utils::rpc;
use lightning_interfaces::types::Epoch;
use lightning_test_utils::config::LIGHTNING_TEST_HOME_DIR;
use lightning_test_utils::logging;
use resolved_pathbuf::ResolvedPathBuf;
use serde_json::json;
Expand All @@ -21,7 +22,7 @@ async fn e2e_checkpoint() -> Result<()> {
.unwrap()
.as_millis() as u64;

let path = ResolvedPathBuf::try_from("~/.lightning-test/e2e/checkpoint").unwrap();
let path = ResolvedPathBuf::try_from(LIGHTNING_TEST_HOME_DIR.join("e2e/checkpoint")).unwrap();
if path.exists() {
fs::remove_dir_all(&path).expect("Failed to clean up swarm directory before test.");
}
Expand Down
15 changes: 11 additions & 4 deletions core/e2e/tests/epoch_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use hp_fixed::unsigned::HpUfixed;
use lightning_e2e::swarm::{Swarm, SwarmNode};
use lightning_e2e::utils::rpc;
use lightning_interfaces::types::Staking;
use lightning_test_utils::config::LIGHTNING_TEST_HOME_DIR;
use lightning_test_utils::logging;
use resolved_pathbuf::ResolvedPathBuf;
use serde_json::json;
Expand All @@ -24,7 +25,9 @@ async fn e2e_epoch_change_all_nodes_on_committee() -> Result<()> {
.unwrap()
.as_millis() as u64;

let path = ResolvedPathBuf::try_from("~/.lightning-test/e2e/epoch-change-committee").unwrap();
let path =
ResolvedPathBuf::try_from(LIGHTNING_TEST_HOME_DIR.join("e2e/epoch-change-committee"))
.unwrap();
if path.exists() {
fs::remove_dir_all(&path).expect("Failed to clean up swarm directory before test.");
}
Expand Down Expand Up @@ -93,7 +96,9 @@ async fn e2e_epoch_change_with_edge_node() -> Result<()> {
.unwrap()
.as_millis() as u64;

let path = ResolvedPathBuf::try_from("~/.lightning-test/e2e/epoch-change-edge-node").unwrap();
let path =
ResolvedPathBuf::try_from(LIGHTNING_TEST_HOME_DIR.join("e2e/epoch-change-edge-node"))
.unwrap();
if path.exists() {
fs::remove_dir_all(&path).expect("Failed to clean up swarm directory before test.");
}
Expand Down Expand Up @@ -163,7 +168,8 @@ async fn e2e_committee_change() -> Result<()> {
.unwrap()
.as_millis() as u64;

let path = ResolvedPathBuf::try_from("~/.lightning-test/e2e/committee-change").unwrap();
let path =
ResolvedPathBuf::try_from(LIGHTNING_TEST_HOME_DIR.join("e2e/committee-change")).unwrap();
if path.exists() {
fs::remove_dir_all(&path).expect("Failed to clean up swarm directory before test.");
}
Expand Down Expand Up @@ -206,7 +212,8 @@ async fn e2e_test_staking_auction() -> Result<()> {
.unwrap()
.as_millis() as u64;

let path = ResolvedPathBuf::try_from("~/.lightning-test/e2e/staking-auction").unwrap();
let path =
ResolvedPathBuf::try_from(LIGHTNING_TEST_HOME_DIR.join("e2e/staking-auction")).unwrap();
if path.exists() {
fs::remove_dir_all(&path).expect("Failed to clean up swarm directory before test.");
}
Expand Down
3 changes: 2 additions & 1 deletion core/e2e/tests/pinger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anyhow::Result;
use lightning_e2e::swarm::Swarm;
use lightning_e2e::utils::rpc;
use lightning_interfaces::types::{NodeInfo, Participation};
use lightning_test_utils::config::LIGHTNING_TEST_HOME_DIR;
use lightning_test_utils::logging;
use resolved_pathbuf::ResolvedPathBuf;
use serde_json::json;
Expand All @@ -21,7 +22,7 @@ async fn e2e_detect_offline_node() -> Result<()> {
.unwrap()
.as_millis() as u64;

let path = ResolvedPathBuf::try_from("~/.lightning-test/e2e/pinger").unwrap();
let path = ResolvedPathBuf::try_from(LIGHTNING_TEST_HOME_DIR.join("e2e/pinger")).unwrap();
if path.exists() {
fs::remove_dir_all(&path).expect("Failed to clean up swarm directory before test.");
}
Expand Down
4 changes: 3 additions & 1 deletion core/e2e/tests/syncronizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use fleek_blake3 as blake3;
use lightning_e2e::swarm::Swarm;
use lightning_e2e::utils::rpc;
use lightning_interfaces::prelude::*;
use lightning_test_utils::config::LIGHTNING_TEST_HOME_DIR;
use lightning_test_utils::logging;
use resolved_pathbuf::ResolvedPathBuf;
use serde_json::json;
Expand All @@ -22,7 +23,8 @@ async fn e2e_syncronize_state() -> Result<()> {
.unwrap()
.as_millis() as u64;

let path = ResolvedPathBuf::try_from("~/.lightning-test/e2e/syncronize-state").unwrap();
let path =
ResolvedPathBuf::try_from(LIGHTNING_TEST_HOME_DIR.join("e2e/syncronize-state")).unwrap();
if path.exists() {
fs::remove_dir_all(&path).expect("Failed to clean up swarm directory before test.");
}
Expand Down
7 changes: 5 additions & 2 deletions core/keystore/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use fleek_crypto::{ConsensusSecretKey, NodeSecretKey, SecretKey};
use lightning_utils::config::LIGHTNING_HOME_DIR;
use resolved_pathbuf::ResolvedPathBuf;
use serde::{Deserialize, Serialize};

Expand All @@ -12,10 +13,12 @@ pub struct KeystoreConfig {
impl Default for KeystoreConfig {
fn default() -> Self {
Self {
node_key_path: "~/.lightning/keystore/node.pem"
node_key_path: LIGHTNING_HOME_DIR
.join("keystore/node.pem")
.try_into()
.expect("Failed to resolve path."),
consensus_key_path: "~/.lightning/keystore/consensus.pem"
consensus_key_path: LIGHTNING_HOME_DIR
.join("keystore/consensus.pem")
.try_into()
.expect("Failed to resolve path."),
}
Expand Down
1 change: 1 addition & 0 deletions core/resolver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
lightning-interfaces = { path = "../interfaces" }
lightning-utils = { path = "../utils" }
anyhow.workspace = true
async-trait.workspace = true
bincode.workspace = true
Expand Down
4 changes: 3 additions & 1 deletion core/resolver/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use lightning_utils::config::LIGHTNING_HOME_DIR;
use resolved_pathbuf::ResolvedPathBuf;
use serde::{Deserialize, Serialize};

Expand All @@ -10,7 +11,8 @@ pub struct Config {
impl Default for Config {
fn default() -> Self {
Self {
store_path: "~/.lightning/data/resolver_store"
store_path: LIGHTNING_HOME_DIR
.join("data/resolver_store")
.try_into()
.expect("Failed to resolve path"),
}
Expand Down
2 changes: 2 additions & 0 deletions core/service-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ edition.workspace = true

[dependencies]
lightning-interfaces = { path = "../interfaces" }
lightning-utils = { path = "../utils" }
lightning-test-utils = { path = "../test-utils" }
fn-sdk = { path = "../../lib/sdk" }
fleek-crypto.workspace = true
tokio.workspace = true
Expand Down
Loading

0 comments on commit 29cd0b7

Please sign in to comment.