Convert ArgsManager::GetDataDir to a read-only function #27073

pull willcl-ark wants to merge 2 commits into bitcoin:master from willcl-ark:2022-02-cli-datadir changing 3 files +42 −12
  1. willcl-ark commented at 1:26 pm on February 10, 2023: contributor

    Fixes #20070

    Currently ArgsManager::GetDataDir() ensures it will always return a datadir by creating one if necessary. The function is shared between bitcoind bitcoin-qt and bitcoin-cli which results in the undesirable behaviour described in #20070.

    This PR splits out the part of the function which creates directories and adds it as a standalone function, only called as part of bitcoind and bitcoin-qt init, but not bitcoin-cli.

    ReadConfigFiles’ behavior is changed to use the absolute path of the config file in error and warning messages instead of a relative path.

    This was inadvertantly the form being tested here, whilst we were not testing that a relative path was returned by the message even though we passed a relative path in as argument.

  2. DrahtBot commented at 1:26 pm on February 10, 2023: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK hebasto, TheCharlatan, achow101, ryanofsky
    Concept ACK stickies-v, pinheadmz

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #26177 (refactor / kernel: Move non-gArgs chainparams functionality to kernel by TheCharlatan)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. in src/util/system.cpp:444 in dd123d37bb outdated
    446     return path;
    447 }
    448 
    449+void ArgsManager::CreateDataDirIfNotExists(bool net_specific)
    450+{
    451+    fs::path path = GetDataDir(net_specific);
    


    stickies-v commented at 2:55 pm on February 10, 2023:

    Would take this opportunity to mark the return value of fs::path& GetDataDir() as LIFETIMEBOUND

    0    auto& path{GetDataDir(net_specific)};
    

    edit: although one could argue that given the small size of the return value, we might instead just not have GetDataDir() return by reference entirely.

  4. in src/util/system.cpp:970 in dd123d37bb outdated
    966@@ -965,6 +967,19 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
    967     return true;
    968 }
    969 
    970+void ArgsManager::GetConfigFilePath(fs::path& conf_path, fs::path& conf_file)
    


    stickies-v commented at 2:59 pm on February 10, 2023:

    Parameter naming is a bit confusing, they’re both paths. conf_file is just guaranteed to be the absolute path, whereas conf_path may not be. abs_conf_path sounds more appropriate to me.

    But instead, I would simplify this by just returning the absolute path and changing the signature to fs::path GetConfigFilePath();. I don’t think we need the (current) conf_path for anything - (current) conf_file seems enough?


    willcl-ark commented at 11:40 am on February 13, 2023:
    agreed
  5. in src/util/system.cpp:976 in dd123d37bb outdated
    971+{
    972+    conf_path = GetPathArg("-conf", BITCOIN_CONF_FILENAME);
    973+    conf_file = GetConfigFile(conf_path);
    974+}
    975+
    976+void ArgsManager::GetOrCreateConfigFilePath()
    


    stickies-v commented at 3:23 pm on February 10, 2023:

    It seems like this function is only used to call ArgsManager::CreateDataDirIfNotExists(false). Unless I misunderstand, I think it makes more sense to just make ArgsManager::CreateDataDirIfNotExists public? It’s less code and a more clear intent, imo.

      0diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp
      1index 3d154961b..49a709628 100644
      2--- a/src/bitcoind.cpp
      3+++ b/src/bitcoind.cpp
      4@@ -153,7 +153,7 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
      5         if (!CheckDataDirOption()) {
      6             return InitError(Untranslated(strprintf("Specified data directory \"%s\" does not exist.\n", args.GetArg("-datadir", ""))));
      7         }
      8-        args.GetOrCreateConfigFilePath();
      9+        args.CreateDataDirIfNotExists(false);
     10         if (!args.ReadConfigFiles(error, true)) {
     11             return InitError(Untranslated(strprintf("Error reading configuration file: %s\n", error)));
     12         }
     13diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
     14index f69c4be2d..fa3d0ab92 100644
     15--- a/src/qt/bitcoin.cpp
     16+++ b/src/qt/bitcoin.cpp
     17@@ -596,7 +596,7 @@ int GuiMain(int argc, char* argv[])
     18     try {
     19         /// 6b. Parse bitcoin.conf
     20         /// - Do not call gArgs.GetDataDirNet() before this step finishes
     21-        gArgs.GetOrCreateConfigFilePath();
     22+        gArgs.CreateDataDirIfNotExists(false);
     23         if (!gArgs.ReadConfigFiles(error, true)) {
     24             InitError(strprintf(Untranslated("Error reading configuration file: %s\n"), error));
     25             QMessageBox::critical(nullptr, PACKAGE_NAME,
     26diff --git a/src/util/system.cpp b/src/util/system.cpp
     27index 11991f1ab..335630599 100644
     28--- a/src/util/system.cpp
     29+++ b/src/util/system.cpp
     30@@ -967,17 +967,9 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
     31     return true;
     32 }
     33 
     34-void ArgsManager::GetConfigFilePath(fs::path& conf_path, fs::path& conf_file)
     35+fs::path ArgsManager::GetConfigFilePath()
     36 {
     37-    conf_path = GetPathArg("-conf", BITCOIN_CONF_FILENAME);
     38-    conf_file = GetConfigFile(conf_path);
     39-}
     40-
     41-void ArgsManager::GetOrCreateConfigFilePath()
     42-{
     43-    fs::path conf_path, conf_file;
     44-    GetConfigFilePath(conf_path, conf_file);
     45-    CreateDataDirIfNotExists(false);
     46+    return GetConfigFile(GetPathArg("-conf", BITCOIN_CONF_FILENAME));
     47 }
     48 
     49 bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
     50@@ -988,9 +980,8 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
     51         m_config_sections.clear();
     52     }
     53 
     54-    fs::path conf_path, conf_file;
     55-    GetConfigFilePath(conf_path, conf_file);
     56-    std::ifstream stream{conf_file};
     57+    auto conf_path{GetConfigFilePath()};
     58+    std::ifstream stream{conf_path};
     59 
     60     // not ok to have a config file specified that cannot be opened
     61     if (IsArgSet("-conf") && !stream.good()) {
     62diff --git a/src/util/system.h b/src/util/system.h
     63index e3cb56d06..85b1f00d0 100644
     64--- a/src/util/system.h
     65+++ b/src/util/system.h
     66@@ -242,8 +242,7 @@ protected:
     67     void SelectConfigNetwork(const std::string& network);
     68 
     69     [[nodiscard]] bool ParseParameters(int argc, const char* const argv[], std::string& error);
     70-    void GetConfigFilePath(fs::path& conf_path, fs::path& conf_file);
     71-    void GetOrCreateConfigFilePath();
     72+    fs::path GetConfigFilePath();
     73     [[nodiscard]] bool ReadConfigFiles(std::string& error, bool ignore_invalid_keys = false);
     74 
     75     /**
     76@@ -477,6 +476,13 @@ protected:
     77      */
     78     void LogArgs() const;
     79 
     80+    /**
     81+     * Create data directory if it doesn't exist
     82+     *
     83+     * [@param](/bitcoin-bitcoin/contributor/param/) net_specific Create a network-identified data directory
     84+     */
     85+    void CreateDataDirIfNotExists(bool net_specific);
     86+
     87 private:
     88     /**
     89      * Get data directory path
     90@@ -486,13 +492,6 @@ private:
     91      */
     92     const fs::path& GetDataDir(bool net_specific) const;
     93 
     94-    /**
     95-     * Create data directory if it doesn't exist
     96-     *
     97-     * [@param](/bitcoin-bitcoin/contributor/param/) net_specific Create a network-identified data directory
     98-     */
     99-    void CreateDataDirIfNotExists(bool net_specific);
    100-
    101     // Helper function for LogArgs().
    102     void logArgsPrefix(
    103         const std::string& prefix,
    

    pinheadmz commented at 4:01 pm on February 10, 2023:
    I’d suggest renaming this function too, it returns void so it’s not really a “getter”

    willcl-ark commented at 11:40 am on February 13, 2023:
    Thanks, I adapted these changes with @pinheadmz name change suggested below

    willcl-ark commented at 11:41 am on February 13, 2023:
    Now returns a file path
  6. stickies-v commented at 3:24 pm on February 10, 2023: contributor
    Concept ACK - having the cli generate multiple datadirs is not great. Suggested some simplifications, I hope I’m not missing some nuance there?
  7. in src/util/system.cpp:442 in dd123d37bb outdated
    444     }
    445 
    446     return path;
    447 }
    448 
    449+void ArgsManager::CreateDataDirIfNotExists(bool net_specific)
    


    pinheadmz commented at 3:57 pm on February 10, 2023:
    suggestion, could call this EnsureDataDir or EnsureDirExists? Actually this is just for the wallet? maybe then EnsureWalletDir ?

    stickies-v commented at 5:20 pm on February 10, 2023:

    Actually this is just for the wallet?

    It’s not just for the wallet, it’s simply shorthand for creating both datadir/ as well as datadir/wallets/ - fs::create_directories creates all the non-existing dirs in path.

    But I agree: EnsureDataDir is probably a better name. Shorter and equally informative. I think Data needs to be in there - it’s opinionated about which exact directory.


    willcl-ark commented at 11:40 am on February 13, 2023:
    Agreed, and renamed.
  8. pinheadmz commented at 4:33 pm on February 10, 2023: member

    concept ACK

    I reproduced the steps from the issue and confirmed that the patch prevents creating new Bitcoin/wallets directory when running bitcoin-cli -getinfo from a new user on the same machine running bitcoind

  9. willcl-ark force-pushed on Feb 13, 2023
  10. willcl-ark commented at 11:42 am on February 13, 2023: contributor
    Thanks @stickies-v & @pinheadmz , I addressed your comments in the new push.
  11. in src/util/system.cpp:444 in 4c14a22876 outdated
    446     return path;
    447 }
    448 
    449+void ArgsManager::EnsureDataDir(bool net_specific)
    450+{
    451+    fs::path path = GetDataDir(net_specific);
    


    stickies-v commented at 11:49 am on February 13, 2023:

    nit

    0    const auto path{GetDataDir(net_specific)};
    

    willcl-ark commented at 2:03 pm on February 13, 2023:
    Now addressed in f0df9ee5d
  12. in src/util/system.cpp:983 in 4c14a22876 outdated
    979@@ -973,8 +980,8 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
    980         m_config_sections.clear();
    981     }
    982 
    983-    const fs::path conf_path = GetPathArg("-conf", BITCOIN_CONF_FILENAME);
    984-    std::ifstream stream{GetConfigFile(conf_path)};
    985+    auto conf_path{GetConfigFilePath()};
    


    stickies-v commented at 11:50 am on February 13, 2023:

    sorry, forgot to mark this as const in my diff

    0    const auto conf_path{GetConfigFilePath()};
    

    willcl-ark commented at 12:00 pm on February 13, 2023:
    sure, also agree
  13. in src/bitcoind.cpp:156 in 4c14a22876 outdated
    152@@ -153,6 +153,7 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
    153         if (!CheckDataDirOption()) {
    154             return InitError(Untranslated(strprintf("Specified data directory \"%s\" does not exist.\n", args.GetArg("-datadir", ""))));
    155         }
    156+        args.EnsureDataDir(false);
    


    stickies-v commented at 11:54 am on February 13, 2023:
    0        args.EnsureDataDir(/*net_specific=*/false);
    
  14. in src/qt/bitcoin.cpp:599 in 4c14a22876 outdated
    595@@ -596,6 +596,7 @@ int GuiMain(int argc, char* argv[])
    596     try {
    597         /// 6b. Parse bitcoin.conf
    598         /// - Do not call gArgs.GetDataDirNet() before this step finishes
    599+        gArgs.EnsureDataDir(false);
    


    stickies-v commented at 11:54 am on February 13, 2023:
    0        gArgs.EnsureDataDir(/*net_specific=*/false);
    
  15. hebasto commented at 11:56 am on February 13, 2023: member
    Concept ACK.
  16. willcl-ark force-pushed on Feb 13, 2023
  17. in src/util/system.cpp:458 in 08a523829a outdated
    448 
    449+void ArgsManager::EnsureDataDir(bool net_specific)
    450+{
    451+    fs::path path = GetDataDir(net_specific);
    452+    if (!fs::exists(path)) {
    453+        fs::create_directories(path / "wallets");
    


    hebasto commented at 12:10 pm on February 13, 2023:
    1. Should we care about possible exceptions here?
    2. What is the point to run this code when net_specific == false?

    willcl-ark commented at 2:01 pm on February 13, 2023:
    1. Yes, part of me wanted to add some exception handling here, however the original code this was factored out of did not have any, and so my thinking was that this would be OK to leave as-is, happy to be persuaded otherwise though…
    2. When run with net_specific = false, this will return the general DataDir, e.g. $HOME/.bitcoin and with true will return the network-specific DataDir e.g. $HOME/.bitcoin/regtest

    hebasto commented at 2:09 pm on February 13, 2023:

    2. What is the point to run this code when net_specific == false?

    2. When run with net_specific = false, this will return the general DataDir, e.g. $HOME/.bitcoin and with true will return the network-specific DataDir e.g. $HOME/.bitcoin/regtest

    Sorry, if my question was unclear. My point is whether we are interested in the wallet directory when net_specific = false?


    willcl-ark commented at 9:52 am on February 14, 2023:
    Now updated to EnsureDataDirNet which always creates the wallets/ path if it’s creating a new DataDir, but otherwise doesn’t.
  18. in src/util/system.cpp:442 in 08a523829a outdated
    444     }
    445 
    446     return path;
    447 }
    448 
    449+void ArgsManager::EnsureDataDir(bool net_specific)
    


    hebasto commented at 12:12 pm on February 13, 2023:

    Maybe introduce two functions: one for net_specific == true and the other for net_specific == true?

    It will make code cleaner on the caller sites.


    willcl-ark commented at 2:02 pm on February 13, 2023:
    Totally agree there could be two wrapper functions here if desired, EnsureDataDir and EnsureNetDataDir perhaps? It might just means more duplicated code in the end though?

    stickies-v commented at 2:52 pm on February 13, 2023:

    I did some digging, and I think (would be nice to get more confirmation on this) we can scrap the net_specific == false version entirely, we don’t seem to need it. EnsureDataDir is called 3 times: 2 times right before reading config files - but it looks like we don’t actually need to ensure a datadir there. If datadir doesn’t exist, by definition no config files can be read (and that’s handled gracefully). The only time we need it is where net_specific==true.

    Intuitively, this makes sense - it can never hurt to ensure that all the necessary datadirs (both base as well as the more specific net) exist. However, there actually is a pitfall, because GetDataDir() does some caching, we’re not allowed to call GetDatDir(true) before we’ve determined the network we’re on (which requires us to first read the basedir and check if there’s a config file there).

    For that reason, I think calling it EnsureDataDirNet is probably better - and aligns with GetDataDirNet naming.

     0diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp
     1index 3a36ff700..07002cc8a 100644
     2--- a/src/bitcoind.cpp
     3+++ b/src/bitcoind.cpp
     4@@ -153,7 +153,6 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
     5         if (!CheckDataDirOption()) {
     6             return InitError(Untranslated(strprintf("Specified data directory \"%s\" does not exist.\n", args.GetArg("-datadir", ""))));
     7         }
     8-        args.EnsureDataDir(/*net_specific=*/false);
     9         if (!args.ReadConfigFiles(error, true)) {
    10             return InitError(Untranslated(strprintf("Error reading configuration file: %s\n", error)));
    11         }
    12diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
    13index 80e607f77..59f433749 100644
    14--- a/src/qt/bitcoin.cpp
    15+++ b/src/qt/bitcoin.cpp
    16@@ -596,7 +596,6 @@ int GuiMain(int argc, char* argv[])
    17     try {
    18         /// 6b. Parse bitcoin.conf
    19         /// - Do not call gArgs.GetDataDirNet() before this step finishes
    20-        gArgs.EnsureDataDir(/*net_specific=*/false);
    21         if (!gArgs.ReadConfigFiles(error, true)) {
    22             InitError(strprintf(Untranslated("Error reading configuration file: %s\n"), error));
    23             QMessageBox::critical(nullptr, PACKAGE_NAME,
    24diff --git a/src/util/system.cpp b/src/util/system.cpp
    25index 329100008..75fd91516 100644
    26--- a/src/util/system.cpp
    27+++ b/src/util/system.cpp
    28@@ -439,9 +439,9 @@ const fs::path& ArgsManager::GetDataDir(bool net_specific) const
    29     return path;
    30 }
    31 
    32-void ArgsManager::EnsureDataDir(bool net_specific)
    33+void ArgsManager::EnsureDataDirNet()
    34 {
    35-    fs::path path = GetDataDir(net_specific);
    36+    fs::path path = GetDataDir(true);
    37     if (!fs::exists(path)) {
    38         fs::create_directories(path / "wallets");
    39     }
    40@@ -492,7 +492,7 @@ bool ArgsManager::IsArgSet(const std::string& strArg) const
    41 
    42 bool ArgsManager::InitSettings(std::string& error)
    43 {
    44-    EnsureDataDir(/*net_specific=*/true);
    45+    EnsureDataDirNet();
    46     if (!GetSettingsPath()) {
    47         return true; // Do nothing if settings file disabled.
    48     }
    49diff --git a/src/util/system.h b/src/util/system.h
    50index 3bcbd5c8e..23c15228e 100644
    51--- a/src/util/system.h
    52+++ b/src/util/system.h
    53@@ -478,10 +478,8 @@ protected:
    54 
    55     /**
    56      * Create data directory if it doesn't exist
    57-     *
    58-     * [@param](/bitcoin-bitcoin/contributor/param/) net_specific Create a network-identified data directory
    59      */
    60-    void EnsureDataDir(bool net_specific);
    61+    void EnsureDataDirNet();
    62 
    63 private:
    64     /**
    

    willcl-ark commented at 9:49 am on February 14, 2023:
    Thanks, I have updated to EnsureDataDirNet as suggested
  19. willcl-ark force-pushed on Feb 13, 2023
  20. fanquake commented at 2:54 pm on February 13, 2023: member
    Does/can this also close #16220?
  21. willcl-ark commented at 3:09 pm on February 13, 2023: contributor

    Does/can this also close #16220?

    I will check this out, specifically w.r.t this comment which I had not been considering:

    It would be, however the reason that wallets/ is not created when the .bitcoin directory already exists is backwards compatibility. If there is an existing datadir but no wallets directory it’s assumed to be an old data directory, and creating wallets would effectively hide the existing wallets in the top level dir, possibly leading to people to suspect loss of funds.

  22. willcl-ark commented at 9:47 am on February 14, 2023: contributor

    I will check this out, specifically w.r.t this comment which I had not been considering:

    I don’t believe this fully closes the loop on #16220, but I am also not sure that we ever will close that fully whilst also providing backwards-compatibility…

    There can exist currently two different working wallet configurations:

    1. Legacy: wallets in subfolders in top-level, e.g. ~/.bitcoin/test-wallet/wallet.dat or ~/.bitcoin/regtest/test-wallet/wallet.dat
    2. Current: wallets in wallets/ subfolder, e.g. ~/.bitcoin/wallets/test-wallet/wallet.dat or ~/.bitcoin/regtest/wallets/test-wallet/wallet.dat

    The current init logic (preserved by this PR) is that we will check for the presence of .bitcoin/ dir, and if it exists then use it as DataDir and take no further action. If it does not exist, then we will create it, along with a wallets/ subdirectory. This allows old installs to continue without “disappearing wallets”, as described by #16220.

    Without implementing some brittle filesystem-checking code as laanwj described, I don’t see this as really “fixable” (and probably that issue should be closed). One way of doing it could be to recursively check each subdir not called wallets/ in the datadir for the presence of *.dat files, but I don’t much like that idea.


    sidenote: I notice in testing this that loadwallet RPC says that it can take a path to a wallet.dat file, to load the wallet, which I found not to work at all, whether or not the wallet was in a wallets/ subdir or not (and IIRC from another recent issue it is not supposed to work like this, so could do with helptext being updated):

    https://github.com/bitcoin/bitcoin/blob/2c1fe27bf3c1e504864987cbe80f9c24897d3cb1/src/wallet/rpc/wallet.cpp#L203

     0will@ubuntu in ~/src/bitcoin on  2022-02-cli-datadir [$⇕] via 🐍 v3.7.16
     1✗ /home/will/src/bitcoin/src/bitcoin-cli loadwallet ~/.bitcoin/test/wallet.dat
     2error code: -4
     3error message:
     4Wallet file verification failed. Invalid -wallet path '/home/will/.bitcoin/test/wallet.dat'. -wallet path should point to a directory where wallet.dat and database/log.?????????? files can be stored, a location where such a directory could be created, or (for backwards compatibility) the name of an existing data file in -walletdir ("/home/will/.bitcoin")
     5
     6will@ubuntu in ~/src/bitcoin on  2022-02-cli-datadir [$⇕] via 🐍 v3.7.16
     7
     8####
     9# Moved wallet from ~/.bitcoin/test/wallet.dat to ~/.bitcoin/wallet.dat
    10####
    11
    12✗ /home/will/src/bitcoin/src/bitcoin-cli loadwallet ~/.bitcoin/wallet.dat
    13error code: -4
    14error message:
    15Wallet file verification failed. Invalid -wallet path '/home/will/.bitcoin/wallet.dat'. -wallet path should point to a directory where wallet.dat and database/log.?????????? files can be stored, a location where such a directory could be created, or (for backwards compatibility) the name of an existing data file in -walletdir ("/home/will/.bitcoin")
    
  23. willcl-ark force-pushed on Feb 14, 2023
  24. willcl-ark commented at 10:35 am on February 14, 2023: contributor

    I don’t particularly want to feature-creep too much, but another adjacent issue is #19990

    Which could potentially be addressed in this PR too if desired?

  25. ryanofsky commented at 4:00 pm on February 14, 2023: contributor

    I could be wrong, but the current version of this 41e9a810837b1c1eb497c2c22a6fa9873f379836 appears to change behavior by only creating the <datadir>/<netdir>/wallets directory, and no longer creating the <datadir>/wallets one level up if <datadir> did not exist.

    This seems like a potentially bad thing, because if testnet or signet or regtest bitcoin is started before mainnet bitcoin, mainnet wallets will go be created in <datadir> not <datadir>/wallets as intended. I think more ideally this PR would just refactor the code as desired without changing behavior.

  26. willcl-ark force-pushed on Feb 15, 2023
  27. willcl-ark commented at 10:42 am on February 15, 2023: contributor

    Thanks @ryanofsky that was unintentional and is now fixed. The only behaviour change is now in bitcoin-cli.

    This does still leave us with the (undesirable) behaviour described in #27073 (comment). It seems likely a likely flow that a user might download bitcoin core, create bitcoin.conf and then run the application, which results in not creating a wallets/ subdir on mainnet (and technically other networks, but it’s unlikely a new user would manually create those subdirectories). E.g. the following:

     0$ mkdir ~/.bitcoin
     1$ echo "all_my_settings" >> ~/.bitcoin/bitcoin.conf
     2$ bitcoind    # first run
     3$ find .bitcoin -type d
     4.bitcoin
     5.bitcoin/chainstate
     6.bitcoin/blocks
     7.bitcoin/blocks/index   # no wallets/ subdir created as datadir already existed
     8
     9$ bitcoind -regtest
    10$ find .bitcoin -type d
    11.bitcoin
    12.bitcoin/chainstate
    13.bitcoin/regtest
    14.bitcoin/regtest/wallets    # created as regtest subdir did not already exist, even though datadir did
    15.bitcoin/regtest/chainstate
    16.bitcoin/regtest/blocks
    17.bitcoin/regtest/blocks/index
    18.bitcoin/blocks
    19.bitcoin/blocks/index
    

    But I think this is something for a different PR to fix.

  28. in src/util/system.cpp:984 in 6207b73e50 outdated
    969@@ -965,6 +970,11 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
    970     return true;
    971 }
    972 
    973+fs::path ArgsManager::GetConfigFilePath()
    974+{
    975+    return GetConfigFile(GetPathArg("-conf", BITCOIN_CONF_FILENAME));
    


    hebasto commented at 12:03 pm on February 15, 2023:

    The behavior has been slightly changed:

    • on master:
    0$ ./src/qt/bitcoin-qt -regtest -conf=nothing
    1Error: Error reading configuration file: specified config file "nothing" could not be opened.
    
    • this PR (6207b73e508d6cfc7583483d00261c66b0c348c3):
    0$ ./src/qt/bitcoin-qt -regtest -conf=nothing
    1Error: Error reading configuration file: specified config file "/home/hebasto/.bitcoin/nothing" could not be opened.
    

    If it is intended, maybe document it?


    willcl-ark commented at 2:53 pm on February 15, 2023:

    Right that’s a good catch. We still behave the same as previously, either fetching conf from an absolute path or completing the path with default datadir, but now because I simplified reading the conf into a stream, we return the full path we were trying in the error.

    I agree that therefore there is a slight behaviour change, and personally I think this is more desirable than previously, where users were not told the absolute path the program was searching on for the config I would prefer to keep it this way, but not sure what documentation you would suggest adding in this case?


    hebasto commented at 3:11 pm on February 15, 2023:

    … not sure what documentation you would suggest adding in this case?

    The PR description? A commit message?


    hebasto commented at 3:13 pm on February 15, 2023:
    I’m curious now, why functional tests did not catch this change?

    willcl-ark commented at 8:57 pm on February 16, 2023:

    The reason is that we do not test relative -conf= arguments here, even though we pass a realtive conf argument in.

    This means that we are only testing the os.path.join sum of default DataDir and the relative arg.


    ryanofsky commented at 3:54 pm on February 18, 2023:

    re: #27073 (review)

    Agree new behavior is better than old behavior:

    • Having absolute path of the file that could not be loaded provides more information to users
    • Internally, new code avoids confusing side effect of GetConfigFile actually creating the datadir directory instead of just returning a path string

    willcl-ark commented at 8:29 am on February 23, 2023:
    Closing as I think this is resolved
  29. willcl-ark force-pushed on Feb 16, 2023
  30. in src/util/system.cpp:452 in 64b812e9a6 outdated
    445     return path;
    446 }
    447 
    448+void ArgsManager::EnsureDataDir()
    449+{
    450+    auto path{GetDataDir(false)};
    


    ryanofsky commented at 7:56 pm on February 17, 2023:

    In commit “util: add ArgsManager datadir helper functions” (f9ee6df4c08a8ef63900359b6c3564db1d4f5073)

    Maybe add comment about why this is creating wallet directories. Could say something like:

    “wallets” subdirectories are created in all new datadirs, because wallet code will create new wallets in the “wallets” subdirectory only if exists already, otherwise it will create them in the top-level datadir where they could interfere with other files. Wallet init code currently avoids creating “wallets” directories itself for backwards compatibility, but this be changed in the future (https://github.com/bitcoin/bitcoin/issues/16220) and wallet code here could away.


  31. ryanofsky approved
  32. ryanofsky commented at 4:30 pm on February 18, 2023: contributor
    Light code review ACK 64b812e9a6df8fb4ec96b978a08dc9bde2ada2f0. I want to look a little more closely at this and test a little more to be sure it works as expected, but this seems like a very nice change. Avoids confusing side effect of functions like GetDataDirNet, AbsPathForConfigVal, and GetConfigFile creating directories in the background.
  33. ryanofsky approved
  34. ryanofsky commented at 4:30 pm on February 18, 2023: contributor
    Light code review ACK 64b812e9a6df8fb4ec96b978a08dc9bde2ada2f0. I want to look a little more closely at this and test a little more to be sure it works as expected, but this seems like a very nice change. Avoids confusing side effect of functions like GetDataDirNet, AbsPathForConfigVal, and GetConfigFile creating directories in the background.
  35. TheCharlatan commented at 9:37 am on February 20, 2023: contributor

    Concept ACK

    You can mark both GetConfigFilePath and EnsureDataDir as const.

  36. willcl-ark force-pushed on Feb 20, 2023
  37. willcl-ark commented at 10:52 am on February 20, 2023: contributor

    Concept ACK

    You can mark both GetConfigFilePath and EnsureDataDir as const.

    Updated in 5626101

  38. TheCharlatan approved
  39. TheCharlatan commented at 12:19 pm on February 20, 2023: contributor
    Code review ACK 0af17e161d751b15f90615800411f36e11b3fcde
  40. DrahtBot requested review from ryanofsky on Feb 20, 2023
  41. hebasto approved
  42. hebasto commented at 1:34 pm on February 21, 2023: member

    ACK 0af17e161d751b15f90615800411f36e11b3fcde, tested on Ubuntu 22.04.

    Fixes #20070

    Confirming the bitcoin-cli does not create a data directory and its subdirectories.

    I’ve noticed another behavior change which looks good for me:

    • master:
    0$ ./src/bitcoind rubbish
    1Error: Command line contains unexpected token 'rubbish', see bitcoind -h for a list of options.
    2
    3$ tree ~/.bitcoin
    4/home/hebasto/.bitcoin
    5└── wallets
    6
    71 directory, 0 files
    
    • this PR (0af17e161d751b15f90615800411f36e11b3fcde):
    0$ ./src/bitcoind rubbish
    1Error: Command line contains unexpected token 'rubbish', see bitcoind -h for a list of options.
    2
    3$ ls ~/.bitcoin
    4ls: cannot access '/home/hebasto/.bitcoin': No such file or directory
    
  43. in src/util/system.h:479 in 5626101c8d outdated
    475@@ -475,6 +476,17 @@ class ArgsManager
    476      */
    477     void LogArgs() const;
    478 
    479+    /** If datadir does not exist, create it along with wallets/
    


    ryanofsky commented at 2:43 pm on February 22, 2023:

    In commit “util: make GetDataDir read-only & create datadir..” (0af17e161d751b15f90615800411f36e11b3fcde)

    Would be good to move this comment from the EnsureDataDir declaration to the EnsureDataDir implementation. The comment is trying to explain the confusing create_directories("wallets") calls there, so probably more helpful next to those calls.

    It would be good to have API documentation for the two new functions though. I would move the function descriptions you wrong in the commit message out of the commit message and into system.h comments.


    willcl-ark commented at 8:54 am on February 23, 2023:
    Updated in 56e370fbb9413260723c598048392219b1055ad0
  44. ryanofsky approved
  45. ryanofsky commented at 6:15 pm on February 22, 2023: contributor

    Code review ACK 0af17e161d751b15f90615800411f36e11b3fcde. Nice change that makes initialization more straightforward and gets rid of strange behavior. Only change since last review is adding a comment. I left some small suggestions, but they are not important.


    I think part of the PR description #27073#issue-1579684533 is inaccurate.

    As part of the refactoring it introduces a slight behaviour change to GetConfigFilePath, which now always returns the absolute path of the provided -conf argument, specifically when surfacing an error.

    The GetConfigFilePath() function is a new function so it’s behavior isn’t changing. I think it would be more accurate to say “ReadConfigFiles behavior is changed to use the absolute path of the config file in error and warning messages instead of a relative path.”

  46. util: add ArgsManager datadir helper functions
    * Add ArgsManager::EnsureDataDir()
      Creates data directory if it doesn't exist
    * Add ArgsManager::GetConfigFilePath()
      Return config file path (read-only)
    56e370fbb9
  47. util: make GetDataDir read-only & create datadir..
    .. only in bitcoind and bitcoin-qt
    
    This changes behaviour of GetConfigFilePath which now always returns the
    absolute path of the provided -conf argument.
    64c105442c
  48. willcl-ark force-pushed on Feb 23, 2023
  49. hebasto approved
  50. hebasto commented at 2:43 pm on February 23, 2023: member
    re-ACK 64c105442ce8c10900ea6fbecdbcfebe42f2d387, only comments have been adjusted as requsted since my previous review.
  51. DrahtBot requested review from ryanofsky on Feb 23, 2023
  52. DrahtBot requested review from TheCharlatan on Feb 23, 2023
  53. TheCharlatan approved
  54. TheCharlatan commented at 3:13 pm on February 23, 2023: contributor
    Re-ACK 64c105442ce8c10900ea6fbecdbcfebe42f2d387
  55. achow101 commented at 9:29 pm on February 23, 2023: member
    ACK 64c105442ce8c10900ea6fbecdbcfebe42f2d387
  56. ryanofsky approved
  57. ryanofsky commented at 9:31 pm on February 23, 2023: contributor
    Code review ACK 64c105442ce8c10900ea6fbecdbcfebe42f2d387. Only comment changes since last review
  58. achow101 merged this on Feb 23, 2023
  59. achow101 closed this on Feb 23, 2023

  60. sidhujag referenced this in commit 48dbcb8d6b on Feb 25, 2023
  61. ryanofsky referenced this in commit b20b34f5b3 on Feb 27, 2023
  62. stickies-v referenced this in commit fb0dbe9423 on Feb 28, 2023
  63. fanquake referenced this in commit c37fb251f5 on Feb 28, 2023
  64. achow101 referenced this in commit 8303f11e10 on Feb 28, 2023
  65. sidhujag referenced this in commit 51ca1bc72d on Mar 1, 2023
  66. achow101 referenced this in commit fc037c8c83 on Mar 7, 2023
  67. janus referenced this in commit 30f418df2a on Sep 3, 2023
  68. bitcoin locked this on Feb 23, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-22 09:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me