create bitcoin.conf on first run with template #23931

pull ghost wants to merge 4 commits into bitcoin:master from changing 4 files +61 −2
  1. ghost commented at 2:21 PM on January 1, 2022: none

    Fixes #10746 and #19641

    What?

    Create bitcoin.conf on first run with a template added as comments. Can add/remove things based on feedback.

    Why?

    bitcoind can already create bitcoin.conf if a user runs below command on first startup:

    bitcoind -startupnotify="touch path/bitcoin.conf"
    

    bitcoin-qt can already create blank bitcoin.conf if a user can find this option after starting Bitcoin Core for the first time:

    image

    This pull request improves UX when using bitcoind.

    How?

    Used most of the code from https://github.com/bitcoin/bitcoin/pull/13761/ (will add Alexander Leishman as co-author if I could get the email address)

    Template is changed and I have used bitcoin.conf (privacy) template from https://github.com/jlopp/bitcoin-core-config-generator/

  2. DrahtBot added the label Build system on Jan 1, 2022
  3. DrahtBot added the label Utils/log/libs on Jan 1, 2022
  4. ghost commented at 5:00 PM on January 1, 2022: none

    I tried compiling and running this locally. Weird this had no errors when compiling on Fedora but there was no bitcoin.conf created on running bitcoind.

    I will try testing on other OS tomorrow.

  5. meshcollider commented at 7:49 PM on January 1, 2022: contributor

    will add Alexander Leishman as co-author if I could get the email address

    You can fetch his branch from the PR by running git fetch upstream pull/13761/head And then using git show to look at one of the commits and see the email address used.

  6. in src/conf_file.h:46 in 6ede4c1eea outdated
      41 | +# Options only for mainnet
      42 | +#[main]
      43 | +
      44 | +# Options only for testnet
      45 | +#[test]
      46 | +
    


    benthecarman commented at 10:01 AM on January 3, 2022:

    nit: should add a signet section


  7. in src/util/system.cpp:451 in 6ede4c1eea outdated
     447 | @@ -447,14 +448,24 @@ const fs::path& ArgsManager::GetDataDir(bool net_specific) const
     448 |          path /= fs::PathFromString(BaseParams().DataDir());
     449 |  
     450 |      if (fs::create_directories(path)) {
     451 | -        // This is the first run, create wallets subdirectory too
     452 | -        fs::create_directories(path / "wallets");
     453 | +        // This is the first run, create wallets subdirectory and bitcoin.conf
    


    benthecarman commented at 10:02 AM on January 3, 2022:

    this comment should probably go in the docs for SetupDatadir


    unknown commented at 9:26 AM on January 4, 2022:

    Not sure about this. This comment was already present. I just added and bitcoin.conf in it.


    luke-jr commented at 7:16 AM on January 12, 2022:

    But you moved the code the comment was "attached to" into that new function...


  8. ghost commented at 9:29 AM on January 4, 2022: none

    Thanks @meshcollider I was able to find the email address and added as co-author.

    Changes in last commit:

    1. Add Alexander Leishman as co-author

    2. Add signet section

    3. Change copyright year

    4. Change everything after #endif to comments based on errors in CI

    Tried testing and it works as expected. Config file was created on first run. It works when there is no data directory present in default location which was not the case when I tried earlier in #23931 (comment)

  9. unknown marked this as ready for review on Jan 7, 2022
  10. ghost commented at 1:56 AM on January 7, 2022: none

    I have marked the pull request ready for review. Will figure out a way to add test if it is required.

  11. Rspigler commented at 3:47 AM on January 7, 2022: contributor

    This approach doesn't seem as good to me as the other proposed changes. Why only show a subset of config options as comments? Doesn't really matter if it is a template provided by a third party.

  12. ghost commented at 3:52 AM on January 7, 2022: none

    Why only show a subset of config options as comments? Doesn't really matter if it is a template provided by a third party.

    We will have to decide and mention only some options in template. It's not possible to add all options. For other options users can do research. This file can also be left blank but one template will help users understand basic options.

    As mentioned in OP options can be added/removed based on feedback.

  13. DrahtBot commented at 9:00 PM on January 7, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #24266 (util: Avoid buggy std::filesystem:::create_directories() call by hebasto)

    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.

  14. Rspigler commented at 1:49 AM on January 11, 2022: contributor

    It's not possible to add all options

    I don't see why that's true. Look at this PR for example https://github.com/bitcoin/bitcoin/pull/22235

  15. ghost commented at 6:27 AM on January 11, 2022: none

    Sorry I don't agree with that approach to solve the problem. I would prefer a template in bitcoin.conf with basic things that a new user could understand and file created on first run.

  16. in src/conf_file.h:50 in 5dabe0a037 outdated
      45 | +#[test]
      46 | +
      47 | +# Options only for regtest
      48 | +#[regtest]
      49 | +
      50 | +# Options only for regtest
    


    luke-jr commented at 7:14 AM on January 12, 2022:

    Incorrect comment


    luke-jr commented at 7:15 AM on January 12, 2022:

    I don't think regtest/signet should be included here. They're not basic usage



  17. in src/conf_file.h:28 in 5dabe0a037 outdated
      23 | +# Accept incoming connections from peers.
      24 | +#listen=0
      25 | +# Use separate SOCKS5 proxy <ip:port> to reach peers via Tor hidden services.
      26 | +#onion=127.0.0.1:9050
      27 | +# Only connect to peers via Tor.
      28 | +#onlynet=onion
    


    luke-jr commented at 7:16 AM on January 12, 2022:

    This is a bad idea, so shouldn't be implicitly recommended


  18. luke-jr changes_requested
  19. in src/conf_file.h:16 in ccbd9a68c0 outdated
      11 | +
      12 | +# [network]
      13 | +# Add a node IP address to connect to and attempt to keep the connection open. This option can be set multiple times.
      14 | +#addnode=randomchars.onion
      15 | +# Bind to given address and always listen on it. (default: 0.0.0.0). Use [host]:port notation for IPv6. Append =onion to tag any incoming connections to that address and port as incoming Tor connections
      16 | +#bind=127.0.0.1:8333
    


    niVelion commented at 2:01 PM on January 12, 2022:

    Could you explain the binding suggested here?

    EDIT: I was referring to L16 #bind=127.0.0.1:8333, on re-reading perhaps it's my bad assumption that this was a suggestion.


    unknown commented at 5:06 PM on January 12, 2022:

    I was referring to L16 #bind=127.0.0.1:8333

    Its an example for using bind


    niVelion commented at 5:23 PM on January 12, 2022:

    You mention the default binding is 0.0.0.0; which I understand to mean the server will listen on all network interfaces.

    And we know listening on 127.0.0.1 would instruct the server not to listen on any interface; not to receive remote connections, but even a technical user might not realize this.

    Maybe swapping the default with the example would reduce user error?

    # Bind to given address and always listen on it. Use [host]:port notation for IPv6. Eg 192.249.249.1:10333.
    # Append =onion to tag any incoming connections to that address and port as incoming Tor connections 
    #bind=0.0.0.0
    
  20. DrahtBot added the label Needs rebase on Feb 3, 2022
  21. create bitcoin.conf on first run with template
    Co-authored-by: Alexander Leishman <leishman3@gmail.com>
    6fb326157f
  22. Remove regtest and signet 8362dfcf36
  23. Remove `onlynet=onion` 50fbbd1540
  24. Move comment in `SetupDataDir()` 4a8dfb63f5
  25. DrahtBot removed the label Needs rebase on Feb 4, 2022
  26. DrahtBot added the label Needs rebase on Feb 8, 2022
  27. DrahtBot commented at 3:37 PM on February 8, 2022: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->

    🐙 This pull request conflicts with the target branch and needs rebase.

    <sub>Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".</sub>

  28. bitcoin locked this on Nov 11, 2025

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: 2026-04-13 15:14 UTC

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