From bcee99650bf8f9d8d5520a127afe3655420ea722 Mon Sep 17 00:00:00 2001 From: Gianmarco Fraccaroli <> Date: Thu, 9 Feb 2023 12:15:24 +0100 Subject: [PATCH 1/5] ledger: default folder in home directory --- Cargo.lock | 1 + apps/Cargo.toml | 1 + apps/src/lib/cli.rs | 2 +- apps/src/lib/config/mod.rs | 9 +++++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 8aba5b5646..c56d516a36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3700,6 +3700,7 @@ dependencies = [ "config", "data-encoding", "derivative", + "directories", "ed25519-consensus", "eyre", "ferveo", diff --git a/apps/Cargo.toml b/apps/Cargo.toml index f1bf95a05d..88081bfb3b 100644 --- a/apps/Cargo.toml +++ b/apps/Cargo.toml @@ -151,6 +151,7 @@ masp_proofs = { git = "https://github.com/anoma/masp", rev = "bee40fc465f6afbd10 bimap = {version = "0.6.2", features = ["serde"]} rust_decimal = "1.26.1" rust_decimal_macros = "1.26.1" +directories = "4.0.1" [dev-dependencies] namada = {path = "../shared", default-features = false, features = ["testing", "wasm-runtime"]} diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index 9c23cadb46..722d32c151 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -1598,7 +1598,7 @@ pub mod args { "base-dir", DefaultFn(|| match env::var("NAMADA_BASE_DIR") { Ok(dir) => dir.into(), - Err(_) => config::DEFAULT_BASE_DIR.into(), + Err(_) => config::get_default_namada_folder(), }), ); // const BLOCK_HEIGHT_OPT: ArgOpt = arg_opt("height"); diff --git a/apps/src/lib/config/mod.rs b/apps/src/lib/config/mod.rs index 811289c790..254913b317 100644 --- a/apps/src/lib/config/mod.rs +++ b/apps/src/lib/config/mod.rs @@ -10,6 +10,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::path::{Path, PathBuf}; use std::str::FromStr; +use directories::BaseDirs; use namada::types::chain::ChainId; use namada::types::time::Rfc3339String; use serde::{Deserialize, Serialize}; @@ -348,6 +349,14 @@ impl Config { } } +pub fn get_default_namada_folder() -> PathBuf { + if let Some(base_dirs) = BaseDirs::new() { + base_dirs.home_dir().join(DEFAULT_BASE_DIR) + } else { + DEFAULT_BASE_DIR.into() + } +} + pub const VALUE_AFTER_TABLE_ERROR_MSG: &str = r#" Error while serializing to toml. It means that some nested structure is followed by simple fields. From 713852bbec237ac1508d80df70f406c3012993ca Mon Sep 17 00:00:00 2001 From: Gianmarco Fraccaroli <> Date: Thu, 9 Feb 2023 14:06:01 +0100 Subject: [PATCH 2/5] fix: use data_dir --- apps/src/lib/config/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/src/lib/config/mod.rs b/apps/src/lib/config/mod.rs index 254913b317..c6d62cf9c9 100644 --- a/apps/src/lib/config/mod.rs +++ b/apps/src/lib/config/mod.rs @@ -10,7 +10,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::path::{Path, PathBuf}; use std::str::FromStr; -use directories::BaseDirs; +use directories::ProjectDirs; use namada::types::chain::ChainId; use namada::types::time::Rfc3339String; use serde::{Deserialize, Serialize}; @@ -350,8 +350,8 @@ impl Config { } pub fn get_default_namada_folder() -> PathBuf { - if let Some(base_dirs) = BaseDirs::new() { - base_dirs.home_dir().join(DEFAULT_BASE_DIR) + if let Some(project_dir) = ProjectDirs::from("com", "anoma", "namada") { + project_dir.data_dir().to_path_buf() } else { DEFAULT_BASE_DIR.into() } From 05a62794c1496ff6d1a6d974e3ef8552d12dd1a7 Mon Sep 17 00:00:00 2001 From: Gianmarco Fraccaroli <> Date: Fri, 10 Feb 2023 11:09:15 +0100 Subject: [PATCH 3/5] fix: doc strings --- apps/src/lib/cli.rs | 2 +- documentation/docs/src/user-guide/ledger.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index 722d32c151..38ae59aa6a 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -1731,7 +1731,7 @@ pub mod args { configuration and state is stored. This value can also \ be set via `NAMADA_BASE_DIR` environment variable, but \ the argument takes precedence, if specified. Defaults to \ - `.namada`.", + `$XDG_DATA_HOME/com/anoma.namada`.", )) .arg(WASM_DIR.def().about( "Directory with built WASM validity predicates, \ diff --git a/documentation/docs/src/user-guide/ledger.md b/documentation/docs/src/user-guide/ledger.md index bd02ff6e77..34719640a0 100644 --- a/documentation/docs/src/user-guide/ledger.md +++ b/documentation/docs/src/user-guide/ledger.md @@ -10,7 +10,7 @@ namada ledger The node will attempt to connect to the persistent validator nodes and other peers in the network, and synchronize to the latest block. -By default, the ledger will store its configuration and state in the `.namada` directory relative to the current working directory. You can use the `--base-dir` CLI global argument or `NAMADA_BASE_DIR` environment variable to change it. +By default, the ledger will store its configuration and state in the `.namada` directory in `$XDG_DATA_HOME/com/anoma`. You can use the `--base-dir` CLI global argument or `NAMADA_BASE_DIR` environment variable to change it. The ledger also needs access to the built WASM files that are used in the genesis block. These files are included in release and shouldn't be modified, otherwise your node will fail with a consensus error on the genesis block. By default, these are expected to be in the `wasm` directory, relative to the current working directory. This can also be set with the `--wasm-dir` CLI global argument, `NAMADA_WASM_DIR` environment variable or the configuration file. From bdd32da31cca9e01db184cb0630455310b9be815 Mon Sep 17 00:00:00 2001 From: Gianmarco Fraccaroli <> Date: Wed, 22 Feb 2023 14:25:22 +0100 Subject: [PATCH 4/5] fix: review comments --- apps/src/lib/cli.rs | 7 ++++--- apps/src/lib/config/mod.rs | 2 +- documentation/docs/src/user-guide/ledger.md | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index 38ae59aa6a..8b41019efb 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -1582,8 +1582,7 @@ pub mod args { use super::utils::*; use super::{ArgGroup, ArgMatches}; use crate::client::types::{ParsedTxArgs, ParsedTxTransferArgs}; - use crate::config; - use crate::config::TendermintMode; + use crate::config::{self, TendermintMode}; use crate::facade::tendermint::Timeout; use crate::facade::tendermint_config::net::Address as TendermintAddress; @@ -1731,7 +1730,9 @@ pub mod args { configuration and state is stored. This value can also \ be set via `NAMADA_BASE_DIR` environment variable, but \ the argument takes precedence, if specified. Defaults to \ - `$XDG_DATA_HOME/com/anoma.namada`.", + `$XDG_DATA_HOME/com.heliax.namada` or \ + `$HOME/.local/share/com.heliax.namada` depending on the \ + operating system (former is linux, latter is osx).", )) .arg(WASM_DIR.def().about( "Directory with built WASM validity predicates, \ diff --git a/apps/src/lib/config/mod.rs b/apps/src/lib/config/mod.rs index c6d62cf9c9..60609c8262 100644 --- a/apps/src/lib/config/mod.rs +++ b/apps/src/lib/config/mod.rs @@ -350,7 +350,7 @@ impl Config { } pub fn get_default_namada_folder() -> PathBuf { - if let Some(project_dir) = ProjectDirs::from("com", "anoma", "namada") { + if let Some(project_dir) = ProjectDirs::from("com", "heliax", "namada") { project_dir.data_dir().to_path_buf() } else { DEFAULT_BASE_DIR.into() diff --git a/documentation/docs/src/user-guide/ledger.md b/documentation/docs/src/user-guide/ledger.md index 34719640a0..2e4c9c6dc7 100644 --- a/documentation/docs/src/user-guide/ledger.md +++ b/documentation/docs/src/user-guide/ledger.md @@ -10,9 +10,9 @@ namada ledger The node will attempt to connect to the persistent validator nodes and other peers in the network, and synchronize to the latest block. -By default, the ledger will store its configuration and state in the `.namada` directory in `$XDG_DATA_HOME/com/anoma`. You can use the `--base-dir` CLI global argument or `NAMADA_BASE_DIR` environment variable to change it. +By default, the ledger will store its configuration and state in the `.namada` directory in either `$XDG_DATA_HOME/` or `$HOME/.local/share/`, where `` is `com.heliax.namada`. You can use the `--base-dir` CLI global argument or `NAMADA_BASE_DIR` environment variable to change it. -The ledger also needs access to the built WASM files that are used in the genesis block. These files are included in release and shouldn't be modified, otherwise your node will fail with a consensus error on the genesis block. By default, these are expected to be in the `wasm` directory, relative to the current working directory. This can also be set with the `--wasm-dir` CLI global argument, `NAMADA_WASM_DIR` environment variable or the configuration file. +The ledger also needs access to the built WASM files that are used in the genesis block. These files are included in release and shouldn't be modified, otherwise your node will fail with a consensus error on the genesis block. By default, these are expected to be in the `wasm` directory inside the chain directory that's in the base directory. This can also be set with the `--wasm-dir` CLI global argument, `NAMADA_WASM_DIR` environment variable or the configuration file. The ledger configuration is stored in `.namada/{chain_id}/config.toml` (with default `--base-dir`). It is created when you join the network. You can modify From ac0eb2901ba5ba0a9b02e5f2ed6bd8f0d0ef8016 Mon Sep 17 00:00:00 2001 From: Gianmarco Fraccaroli <> Date: Wed, 26 Apr 2023 10:51:10 +0200 Subject: [PATCH 5/5] added changelog --- .changelog/unreleased/improvements/1138-base-directory.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/1138-base-directory.md diff --git a/.changelog/unreleased/improvements/1138-base-directory.md b/.changelog/unreleased/improvements/1138-base-directory.md new file mode 100644 index 0000000000..0c395a35b1 --- /dev/null +++ b/.changelog/unreleased/improvements/1138-base-directory.md @@ -0,0 +1,2 @@ +- Changed the default base directory. On linux, the default path will be `$XDG_DATA_HOME/com.heliax.namada`, on OSX it will be `$HOME/.local/share/com.heliax.namada`. + ([#1138](https://github.com/anoma/namada/pull/1138)) \ No newline at end of file