unexpected behavior when specify datadir in config file #15745

issue huahuayu openend this issue on April 4, 2019
  1. huahuayu commented at 9:18 am on April 4, 2019: none

    issue sumary

    I specificed datadir in conf file and run bitcoind with -conf option, but data is writing to default ~/.bitcoin dir , not the dir I want

    steps to reproduce

    bitcoind version 0.17.1

    0root@MNG-BC ➜  .bitcoin bitcoind --version
    1Bitcoin Core Daemon version v0.17.1.0-gef70f9b52b851c7997a9f1a0834714e3eebc1fd8
    

    step1: configrations

    bitcoind conf file path /root/.bitcoin/bitcoin.conf datadir for testnet : datadir=/mnt/data/bitcoin

     0# [core]
     1# Specify the location of the configuration file. To use non-default location, create a default location config file containing this setting.
     2conf=/root/.bitcoin/bitcoin.conf
     3
     4# [debug]
     5# Enable debug logging for all categories.
     6#debug=1
     7# Log IP Addresses in debug output.
     8#logips=1
     9# Run this node on the Bitcoin Test Network.
    10#testnet=1
    11
    12# [rpc]
    13# Accept command line and JSON-RPC commands.
    14server=1
    15# Accept public REST requests.
    16rest=1
    17# RPC user
    18rpcuser=rpcuser
    19# RPC password
    20rpcpassword=rpcpass
    21# RPC allow ip (allow all)
    22rpcallowip=0.0.0.0/0
    23# RPC bind
    24#rpcbind=127.0.0.1
    25# get all transaction
    26txindex=1
    27
    28
    29# [Sections]
    30# Most options automatically apply to mainnet, testnet, and regtest networks.
    31# If you want to confine an option to just one network, you should add it in the relevant section.
    32# EXCEPTIONS: The options addnode, connect, port, bind, rpcport, rpcbind and wallet
    33# only apply to mainnet unless they appear in the appropriate section below.
    34
    35# Options only for mainnet
    36[main]
    37# datadir
    38datadir=/mnt/data/bitcoin/mainnet
    39# Listen for incoming connections on non-default port.(default: 8333 or testnet: 18333)
    40port=8333
    41# RPC port(default:8332 or testnet:18332)
    42rpcport=8332
    43
    44# Options only for testnet
    45[test]
    46# datadir
    47datadir=/mnt/data/bitcoin
    48# Listen for incoming connections on non-default port.(default: 8333 or testnet: 18333)
    49port=18333
    50# RPC port(default:8332 or testnet:18332)
    51rpcport=18332
    52
    53# Options only for regtest
    54[regtest]
    

    step2 : run bitcoind

    run bitcoind with below command

    0bitcoind -conf=/root/.bitcoin/bitcoin.conf -testnet=1
    

    step3 : check the data

    expected all the data write to /mnt/data/bitcoin/testnet3
    but actually block data is been wroted to /root/.bitcoin/

    0drwx------  2 root root 4096 Apr  4 16:51 blocks
    1drwx------  3 root root 4096 Apr  4 16:51 testnet3
    

    more info about the contents in /root/.bitcoin

    0root@MNG-BC ➜  .bitcoin du --max-depth=1 -h
    11.1G    ./testnet3
    24.0K    ./blocks
    31.1G    .
    4root@MNG-BC ➜  .bitcoin cd testnet3
    5root@MNG-BC ➜  testnet3 ls
    6blocks
    7root@MNG-BC ➜  testnet3 cd blocks
    8root@MNG-BC ➜  blocks ls
    9blk00000.dat  blk00001.dat  blk00002.dat  blk00003.dat  blk00004.dat  blk00005.dat  blk00006.dat  blk00007.dat  index  rev00000.dat  rev00001.dat  rev00002.dat  rev00003.dat  rev00004.dat  rev00005.dat  rev00006.dat  rev00007.dat
    

    question

    Why datadir is not taken effect in conf? Is it a bug or my conf is wrong? Should I specific -datadir option in the command line?

  2. fanquake deleted a comment on Apr 4, 2019
  3. fanquake commented at 9:26 am on April 4, 2019: member
    @huahuayu Please don’t tag multiple people just to draw attention to your issue.
  4. laanwj commented at 11:05 am on April 4, 2019: member

    There is a circular relationship of sorts between the config file and the data dir. The configuration file can specify a data directory (using -datadir), while the default configuration file bitcoin.conf is in the data directory.

    This potential circularity is broken by ignoring -datadir in the default configuration file, so when -conf is driven by the data directory.

    However, when -conf is specified on the command line it should be possible to set a -datadir in that configuration file and have it be used. The purpose of this is to be able to have the configuration file in a read-only directory, e.g. /etc/bitcoin.conf, specifying where the read/write data is.

    I’ve tested this and with master this seems to work as expected:

    0$ mkdir /tmp/conf /tmp/datadir
    1$ echo "datadir=/tmp/datadir" > /tmp/conf/test1.conf
    2$ src/bitcoind --conf=/tmp/conf/test1.conf -printtoconsole
    32019-04-04T11:00:28Z Bitcoin Core version v0.18.99.0-79c345a0114c9a83fd40e01150519373c017b130 (release build)
    42019-04-04T11:00:28Z Default data directory /home/.../.bitcoin
    52019-04-04T11:00:28Z Using data directory /tmp/datadir
    62019-04-04T11:00:28Z Config file: /tmp/conf/test1.conf
    7...
    
  5. laanwj commented at 11:35 am on April 4, 2019: member

    Same for 0.17.1. Cannot reproduct this.

     0$ mkdir /tmp/conf /tmp/datadir
     1$ echo "datadir=/tmp/datadir" > /tmp/conf/test1.conf
     2$ src/bitcoind --conf=/tmp/conf/test1.conf -printtoconsole
     32019-04-04T11:34:53Z Bitcoin Core version v0.17.1.0-6cf81b01b48e871a35072dd08e7735c3ba42528c (release build)
     42019-04-04T11:34:53Z InitParameterInteraction: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1
     52019-04-04T11:34:53Z Assuming ancestors of block 0000000000000000002e63058c023a9a1de233554f28c7b21380b6c9003f36a8 have valid signatures.
     62019-04-04T11:34:53Z Setting nMinimumChainWork=0000000000000000000000000000000000000000028822fef1c230963535a90d
     72019-04-04T11:34:53Z Using the 'standard' SHA256 implementation
     82019-04-04T11:34:53Z Default data directory /home/.../.bitcoin
     92019-04-04T11:34:53Z Using data directory /tmp/datadir
    102019-04-04T11:34:53Z Using config file /tmp/conf/test1.conf
    
  6. huahuayu commented at 9:00 am on April 9, 2019: none

    hi @laanwj , sorry for the late reply, I tried again, if you followed my steps you will definitely reproduce the problem. Please not only to see the log but check the dirs actually created.

    Env info

    system info

    0$ uname -a
    1Linux MNG-BC 4.4.0-142-generic [#168](/bitcoin-bitcoin/168/)-Ubuntu SMP Wed Jan 16 21:00:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
    

    bitcoind version

    0$ bitcoind --version
    1Bitcoin Core Daemon version v0.17.1.0-gef70f9b52b851c7997a9f1a0834714e3eebc1fd8
    

    Steps to reproduce

    step1

    vi ~/.bitcoind/bitcoin.conf add below contents (change line 44/53 to your datadir)

     0# This config should be placed in following path:
     1# /root/.bitcoin/bitcoin.conf
     2
     3# [core]
     4# Specify the location of the configuration file. To use non-default location, create a default location config file containing this setting.
     5conf=/root/.bitcoin/bitcoin.conf
     6
     7# [debug]
     8# Enable debug logging for all categories.
     9#debug=1
    10# Log IP Addresses in debug output.
    11#logips=1
    12# Run this node on the Bitcoin Test Network.
    13#testnet=1
    14
    15# [rpc]
    16# Accept command line and JSON-RPC commands.
    17server=1
    18# Accept public REST requests.
    19rest=1
    20# RPC user
    21rpcuser=rpcuser
    22# RPC password
    23rpcpassword=rpcpass
    24# RPC allow ip (allow all)
    25rpcallowip=0.0.0.0/0
    26# RPC bind
    27#rpcbind=127.0.0.1
    28# get all transaction
    29txindex=1
    30
    31
    32# [Sections]
    33# Most options automatically apply to mainnet, testnet, and regtest networks.
    34# If you want to confine an option to just one network, you should add it in the relevant section.
    35# EXCEPTIONS: The options addnode, connect, port, bind, rpcport, rpcbind and wallet
    36# only apply to mainnet unless they appear in the appropriate section below.
    37
    38# Options only for mainnet
    39[main]
    40# datadir
    41datadir=/mnt/data/bitcoin/mainnet
    42# Listen for incoming connections on non-default port.(default: 8333 or testnet: 18333)
    43port=8333
    44# RPC port(default:8332 or testnet:18332)
    45rpcport=8332
    46
    47# Options only for testnet
    48[test]
    49# datadir
    50datadir=/mnt/data/bitcoin
    51# Listen for incoming connections on non-default port.(default: 8333 or testnet: 18333)
    52port=18333
    53# RPC port(default:8332 or testnet:18332)
    54rpcport=18332
    55
    56# Options only for regtest
    57[regtest]
    

    step2

    run bitcoind with below command

    0bitcoind -conf=/root/.bitcoin/bitcoin.conf -testnet=1 -daemon
    

    step3

    1. check the dir /root/.bitcoin/ it will have two dirs created: blocks and testnet3 which is not expected
    2. check the datadir you specified (for me it’s /mnt/data/bitcoin/) , it will have a dir created: testnet3, the files inside are as below
    0root@MNG-BC ➜  testnet3 ls
    1banlist.dat  chainstate  debug.log  fee_estimates.dat  indexes  mempool.dat  peers.dat  wallets
    

    Problem summary

    After bitcoind run, data write to two different dirs

    1. wallet and some other files write to the expected datadir which is good
    2. but block data write to /root/.bitcoin/ is not expected, it should in datadir too. It runs out of my disk space in system volume.
  7. huahuayu renamed this:
    unexpected behavior when specific datadir in config file
    unexpected behavior when specify datadir in config file
    on Apr 9, 2019
  8. hebasto commented at 8:15 am on April 22, 2019: member
    @huahuayu does #15864 fix this issue?
  9. promag commented at 10:10 am on April 22, 2019: member
    Should we just check the special case -conf is specified and avoid GetDefaultDataDir in that case?
  10. huahuayu commented at 2:11 am on April 23, 2019: none
    @hebasto let me check
  11. fanquake commented at 5:59 am on August 4, 2019: member
    @huahuayu Did #15864 fix your issue?
  12. MarcoFalke closed this on Aug 19, 2019

  13. sidhujag referenced this in commit 894dd2f309 on Aug 19, 2019
  14. deadalnix referenced this in commit 68cb14deaa on Apr 23, 2020
  15. ShengguangXiao referenced this in commit eee9fd8fa9 on Aug 28, 2020
  16. DrahtBot locked this on Dec 16, 2021

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-07-01 10:13 UTC

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