Skip to content

Conversation

leishman
Copy link
Contributor

@leishman leishman commented Jul 26, 2018

Fixes #10746. If no -conf flag is passed and no bitcoin.conf file exists in the datadir, then a bitcoin.conf template will be created in the datadir. This conf file will have no configurations set, only explanatory comments. The default bitcoin.conf template was copied from contrib/debian/examples/bitcoin.conf.

The lack of a default config file historically causes a lot of confusion for new users because bitcoind will print Using config file $DATADIR/bitcoin.conf on startup even if no file exists.

Curious if error handling is being done properly here or if file permissions need to be considered. I don't think a failure to create this file should terminate the process.

@leishman leishman force-pushed the write-default-config-file branch 4 times, most recently from 04be012 to a517c47 Compare July 26, 2018 03:12
@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 26, 2018

Note to reviewers: This pull request conflicts with the following ones:

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.

Copy link
Contributor

@ken2812221 ken2812221 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add the filenameto src/Makefile.am

BITCOIN_CORE_H = \

src/bitcoin.conf Outdated
@@ -0,0 +1,147 @@
R"(##
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's The R and ( for?

src/bitcoin.conf Outdated
#min=1

# Minimize to the system tray
#minimizetotray=1)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the ) for ?

src/bitcoind.cpp Outdated
// default bitcoin.conf file template
const char* g_default_conf_file =
#include <bitcoin.conf>
;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good way to do this. I'd prefer rename to bitcoin_conf.h and move const char ... into that file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The R() is for being able to #include the file. But I like your idea better. I will update. Thanks for the suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also sorry for not explaining further. R() is for multiline string literal: https://stackoverflow.com/a/20508617/2302781

Fixes bitcoin#10746. If no -conf flag is passed and no bitcoin.conf file exists in the
datadir, then a bitcoin.conf template will be created in the datadir. This conf
file will have no configurations set, only explanatory comments. The default
bitcoin.conf template was copied from contrib/debian/examples/bitcoin.conf.
@leishman leishman force-pushed the write-default-config-file branch from 35ae6b3 to 08def4b Compare July 26, 2018 05:46
@leishman
Copy link
Contributor Author

@ken2812221 updated!

@jonasschnelli
Copy link
Contributor

I'm conceptually unsure if the daemon binary should take care of the configuration management (if even supporting a template make sense). This seems to be better address on the package manager level.

@leishman
Copy link
Contributor Author

I can understand that point of view, however I think that many users are accustomed to config files being generated automatically for them from a binary. When people see that the datadir has been generated they are confused about why there is no config file in there. At the very least we should prevent the daemon output from saying that it is using a conf file that doesn't exist.

On a higher level, I'm hoping to start contributing more to Bitcoin Core and I'd like to start with some changes that improve usability for new users. It can be quite intimidating for people.

@sipa
Copy link
Member

sipa commented Jul 27, 2018

If bitcoind is able to create a datadir, at least I think there should be no problem with it creating a default config file in that directory at the same time.

@leishman
Copy link
Contributor Author

I've updated the PR to create the template config file immediately after creation of the datadir.

@laanwj
Copy link
Member

laanwj commented Jul 30, 2018

I'm conceptually unsure if the daemon binary should take care of the configuration management (if even supporting a template make sense). This seems to be better address on the package manager level.

I tend to agree. Daemons should not write their own configuration file.
We can package a default configuration file, but I don't think bitcoin.conf should be created.
(in many cases this is not even possible as the configuration is in a read-only location)
(so NACK from me, see also my argumentation in #10746)

@laanwj
Copy link
Member

laanwj commented Jul 30, 2018

If bitcoind is able to create a datadir, at least I think there should be no problem with it creating a default config file in that directory at the same time.

What about a compromise: always create a bitcoin.conf.example in the data directory. The user can decide to use it by copying it to bitcoin.conf (whatever its location) and editing it, or simply ignore it.

@leishman
Copy link
Contributor Author

What about a compromise: always create a bitcoin.conf.example in the data directory. The user can decide to use it by copying it to bitcoin.conf (whatever its location) and editing it, or simply ignore it.

I like this. I also think we should disable the startup logging message saying a conf file is being used, unless it is actually true. If there is no conf file, then we can print a message instructing the user how/where to create one. What do you think?

@leishman
Copy link
Contributor Author

leishman commented Aug 1, 2018

I've updated things so that a bitcoin.conf.example file is created and we only tell the user a conf file is being used if this file actually exists at the time of startup

src/conf_file.h Outdated
## Quick Primer on addnode vs connect ##
## Let's say for instance you use addnode=4.2.2.4 ##
## addnode will connect you to and tell you about the ##
## nodes connected to 4.2.2.4. In addition it will tell ##
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please left-indent this entire block and increase the total line length to say 78 chars. That will make it easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@practicalswift I copied this from contrib/debian/examples/bitcoin.conf. I'm happy to reformat the file and make these changes, but do you think they should be made in both places?

src/conf_file.h Outdated
## all of them to open lots of connections. Instead ##
## 'connect' them all to one node that is port forwarded ##
## and has lots of connections. ##
## Thanks goes to [Noodle] on Freenode. ##
Copy link
Contributor

@practicalswift practicalswift Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the greeting :-)

src/conf_file.h Outdated
# If not, you must set rpcuser and rpcpassword to secure the JSON-RPC api. The first
# method(DEPRECATED) is to set this pair for the server and client:
#rpcuser=Ulysseys
#rpcpassword=YourSuperGreatPasswordNumber_DO_NOT_USE_THIS_OR_YOU_WILL_GET_ROBBED_385593
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the 385593 part could be longer and randomized?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

part could be longer and randomized?

What do you mean by this? This is an example password that we'd never want anyone to use, and actually comes from the sample bitcoin.conf on the wiki.

Copy link
Contributor

@practicalswift practicalswift Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fanquake Yes I know but randomizing would make it slighly less painful for newcomers to make the mistake of uncommenting as-is. Perhaps that is overkill though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's overkill. If anything we should remove the term 'Number' from the example pw so people don't think it must be limited to a numeric value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, makes sense!

@Sjors
Copy link
Member

Sjors commented Aug 9, 2018

Afaik you can't download that binary separately from the "official" source, and the release signatures don't cover individual files either: https://bitcoincore.org/en/download/

@leishman
Copy link
Contributor Author

leishman commented Aug 9, 2018

They are hosted here: https://bitcoincore.org/bin/bitcoin-core-0.16.2/

And when installing the bitcoind package on ubuntu: sudo apt-get install bitcoind this does not setup the ~/.bitcoin directory for you. This directory is created upon execution of the bitcoind binary. So it's unclear to me where a static file, like the default conf, could possibly be included. What am I missing?

@sipa
Copy link
Member

sipa commented Aug 9, 2018

It's also not possible. When you do a system wide installation of bitcoind it doesn't know which user(s) are going to run it.

@Sjors
Copy link
Member

Sjors commented Aug 9, 2018

@leishman these are packages with multiple files, which you can add files to by tweaking the deploy scripts. Similarly, it should be possible for the ubuntu install script to put this template file somewhere, since it also manages put the icon in /usr/share.

@leishman
Copy link
Contributor Author

leishman commented Aug 9, 2018

@sipa so do you think the approach I have taken in this PR is reasonable?

@Sjors
Copy link
Member

Sjors commented Aug 10, 2018

To clarify my position: I prefer a more elegant solution, but I'm OK with doing that later.

I do however recommend adding a functional test to check if this file is indeed created.

@leishman
Copy link
Contributor Author

@Sjors ok I'll add in that test

@leishman
Copy link
Contributor Author

@Sjors After digging into the testing framework it looks like testing for this behavior is actually quite tricky. The current functionality only creates a bitcoin.conf.example file if the default datadir is used and doesn't already exist. In the testing framework, a custom test-specific datadir is always used in order to not pollute the global filesystem of the testing machine.

@Sjors
Copy link
Member

Sjors commented Aug 20, 2018

@jnewbery is there already a test which checks that the datadir is created when necessary? If so, perhaps that test can be modified to also check the presence of bitcoin.conf.example?

@jnewbery
Copy link
Contributor

is there already a test which checks that the datadir is created when necessary?

I don't think so. See initialize_datadir() in util.py and the places it's called. There are various places where the files in the datadir or the datadir itself is removed. See here for example:

initialize_datadir(self.options.tmpdir, 0)

@leishman
Copy link
Contributor Author

Yeah, currently the test framework always puts the datadirs in a custom path deep in the system /tmp directory. This prevents polluting the $HOME path of the machine running the tests. But because of this, my change is basically untestable, unless we change the way the test framework works or hack something ugly.

Testing default datadir creation could be a testing feature we add in a later PR.

@leishman
Copy link
Contributor Author

Pulling out logging update into a separate PR: #14057

@jnewbery
Copy link
Contributor

The current functionality only creates a bitcoin.conf.example file if the default datadir is used and doesn't already exist.

... my change is basically untestable

What do you think about changing the conditional here: https://github.com/bitcoin/bitcoin/pull/13761/files#diff-b7702a084eb00fb47f9800fd68271951R791 to check whether the directory is empty instead of whether the directory exists (ie create the wallets subdirectory and example conf file when a non-existent or empty datadir is used).

That makes more sense to me, and would be testable in the existing test framework.

@DrahtBot
Copy link
Contributor

Needs rebase

@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase, so I am closing this for now. Please let me know when you want to continue working on this, so the pull request can be re-opened.

@DrahtBot DrahtBot closed this Dec 12, 2018
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 27, 2021
…tcoin.conf" message on startup if conf file exists

946107a Only log "Using PATH_TO_bitcoin.conf" message on startup if conf file exists. (Alexander Leishman)

Pull request description:

  Currently we log a message indicating that a bitcoin.conf file is being used even if one does not exist. This PR changes the logic to:

  **If config file does not exist and no -conf flag passed, log:**
  `Config file: FILE_PATH (not found, skipping)`. Where `FILE_PATH` is the default or the path passed in with the `-conf` flag.

  **If config file does not exist and -conf flag passed with incorrect path, log warning:**
  `Warning: The specified config file FILE_PATH does not exist`

  **If config file exists, log**:
  `Config file: FILE_PATH`

  Note: This is a (modified) subset of changes introduced in bitcoin#13761 which creates a default example config file. I think it makes sense to extract this small bit out into a separate PR.

Tree-SHA512: be0f0ae6a0c9041e2d6acb54d2563bbcc79786fb2f8bf9a963fe01bc54cd4e388b89079fde1eb79f7f17099776428e5e984bf7107590a3d1ecfc0562dbc6e3f5
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 28, 2021
…tcoin.conf" message on startup if conf file exists

946107a Only log "Using PATH_TO_bitcoin.conf" message on startup if conf file exists. (Alexander Leishman)

Pull request description:

  Currently we log a message indicating that a bitcoin.conf file is being used even if one does not exist. This PR changes the logic to:

  **If config file does not exist and no -conf flag passed, log:**
  `Config file: FILE_PATH (not found, skipping)`. Where `FILE_PATH` is the default or the path passed in with the `-conf` flag.

  **If config file does not exist and -conf flag passed with incorrect path, log warning:**
  `Warning: The specified config file FILE_PATH does not exist`

  **If config file exists, log**:
  `Config file: FILE_PATH`

  Note: This is a (modified) subset of changes introduced in bitcoin#13761 which creates a default example config file. I think it makes sense to extract this small bit out into a separate PR.

Tree-SHA512: be0f0ae6a0c9041e2d6acb54d2563bbcc79786fb2f8bf9a963fe01bc54cd4e388b89079fde1eb79f7f17099776428e5e984bf7107590a3d1ecfc0562dbc6e3f5
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 29, 2021
…tcoin.conf" message on startup if conf file exists

946107a Only log "Using PATH_TO_bitcoin.conf" message on startup if conf file exists. (Alexander Leishman)

Pull request description:

  Currently we log a message indicating that a bitcoin.conf file is being used even if one does not exist. This PR changes the logic to:

  **If config file does not exist and no -conf flag passed, log:**
  `Config file: FILE_PATH (not found, skipping)`. Where `FILE_PATH` is the default or the path passed in with the `-conf` flag.

  **If config file does not exist and -conf flag passed with incorrect path, log warning:**
  `Warning: The specified config file FILE_PATH does not exist`

  **If config file exists, log**:
  `Config file: FILE_PATH`

  Note: This is a (modified) subset of changes introduced in bitcoin#13761 which creates a default example config file. I think it makes sense to extract this small bit out into a separate PR.

Tree-SHA512: be0f0ae6a0c9041e2d6acb54d2563bbcc79786fb2f8bf9a963fe01bc54cd4e388b89079fde1eb79f7f17099776428e5e984bf7107590a3d1ecfc0562dbc6e3f5
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 1, 2021
…tcoin.conf" message on startup if conf file exists

946107a Only log "Using PATH_TO_bitcoin.conf" message on startup if conf file exists. (Alexander Leishman)

Pull request description:

  Currently we log a message indicating that a bitcoin.conf file is being used even if one does not exist. This PR changes the logic to:

  **If config file does not exist and no -conf flag passed, log:**
  `Config file: FILE_PATH (not found, skipping)`. Where `FILE_PATH` is the default or the path passed in with the `-conf` flag.

  **If config file does not exist and -conf flag passed with incorrect path, log warning:**
  `Warning: The specified config file FILE_PATH does not exist`

  **If config file exists, log**:
  `Config file: FILE_PATH`

  Note: This is a (modified) subset of changes introduced in bitcoin#13761 which creates a default example config file. I think it makes sense to extract this small bit out into a separate PR.

Tree-SHA512: be0f0ae6a0c9041e2d6acb54d2563bbcc79786fb2f8bf9a963fe01bc54cd4e388b89079fde1eb79f7f17099776428e5e984bf7107590a3d1ecfc0562dbc6e3f5
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Jul 1, 2021
…tcoin.conf" message on startup if conf file exists

946107a Only log "Using PATH_TO_bitcoin.conf" message on startup if conf file exists. (Alexander Leishman)

Pull request description:

  Currently we log a message indicating that a bitcoin.conf file is being used even if one does not exist. This PR changes the logic to:

  **If config file does not exist and no -conf flag passed, log:**
  `Config file: FILE_PATH (not found, skipping)`. Where `FILE_PATH` is the default or the path passed in with the `-conf` flag.

  **If config file does not exist and -conf flag passed with incorrect path, log warning:**
  `Warning: The specified config file FILE_PATH does not exist`

  **If config file exists, log**:
  `Config file: FILE_PATH`

  Note: This is a (modified) subset of changes introduced in bitcoin#13761 which creates a default example config file. I think it makes sense to extract this small bit out into a separate PR.

Tree-SHA512: be0f0ae6a0c9041e2d6acb54d2563bbcc79786fb2f8bf9a963fe01bc54cd4e388b89079fde1eb79f7f17099776428e5e984bf7107590a3d1ecfc0562dbc6e3f5
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a default bitcoin.conf in the correct location.
10 participants