init: Fix surprising behaviors of negated options #36880

pull fjahr wants to merge 6 commits into bitcoin:master from fjahr:2026-11-rpc-no-fix changing 16 files +89 −31
  1. fjahr commented at 12:42 PM on November 15, 2026: contributor

    While looking into #36759 I discovered -notorcontrol did the opposite of what would be expected from it and I then checked for similar issues in other init options. There are several more where -nofoo does something surprising including one of them crashing the node.

    This PR attempts to fix all these surprising behaviors while also keeping things as simple as possible and just change behavior to something that makes sense harmless in the context of the option. Fixes that use a common approach for the fix are grouped together into a commit even if the options included themselves may have no relation at all.

    Commit Problematic options behavior Fix approach
    mempool: Reject cluster limits below 1 -nolimitclustercount hits an assertion in TxGraph on the first mempool transaction. -nolimitclustersize rejects every transaction. Reject values below 1 at startup.
    args: Add NEGATE_TO_EMPTY so -nofoo reads as an empty string GetArg() returns "0" for a negated option. The -no*notify options run the command 0, -nosigner uses 0 as signer, -noi2psam fails startup and -norpcpassword sets the password to 0. Opt-in because options like -noonion and -noblockfilterindex depend on reading "0". New opt-in flag NEGATE_TO_EMPTY makes GetArg() return "".
    init: Read -cjdnsreachable and -help as booleans -cjdnsreachable=0 and -nocjdnsreachable turn CJDNS on. -nohelp prints the help. Use GetBoolArg() instead of IsArgSet().
    args, wallet: Fix empty and negated -blocksdir and -walletdir -noblocksdir writes block files relative to the working directory. -nowalletdir fails startup. Fail at startup with DISALLOW_NEGATION. An empty value falls back to the default directory, like -datadir does.
    init: Require -nolistenonion with -notorcontrol -notorcontrol connects to 0.0.0.0:9051, which reaches a local Tor. Fail at startup unless -listenonion is disabled.
    init: Disallow negating options where it has no meaning -nocheckblocks, -nomaxreceivebuffer, -nomaxsendbuffer and -nomaxtipage read as 0, the opposite of what the user asked for. Fail at startup with DISALLOW_NEGATION.

    -nomempoolexpiry has a similar kind of problem. It evicts transactions as soon as the next one arrives. I left it out because #36540 already is open and addresses this.

  2. DrahtBot commented at 12:42 PM on November 15, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    Concept ACK l0rinc
    Approach ACK ryanofsky

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36861 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36861.svg"></sub> (Configuration argument handling improvements. by jlopp)
    • #36759 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36759.svg"></sub> (torcontrol: Improve connection logging by ViniciusCestarii)
    • #36434 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36434.svg"></sub> (http: support unix sockets by pinheadmz)
    • #36170 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36170.svg"></sub> (net: require a dedicated bind for automatic Tor by l0rinc)
    • #31260 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/31260.svg"></sub> (scripted-diff: Type-safe settings retrieval by ryanofsky)
    • #17783 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/17783.svg"></sub> (common: Disallow calling IsArgSet() on ALLOW_LIST options by ryanofsky)
    • #17581 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/17581.svg"></sub> (refactor: Remove settings merge reverse precedence code by ryanofsky)
    • #17580 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/17580.svg"></sub> (refactor: Add ALLOW_LIST flags and enforce usage in CheckArgFlags by ryanofsky)
    • #17493 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/17493.svg"></sub> (util: Forbid ambiguous multiple assignments in config file by ryanofsky)
    • #16545 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/16545.svg"></sub> (refactor: Implement missing error checking for ArgsManager flags by ryanofsky)

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  3. l0rinc commented at 6:47 PM on November 15, 2026: contributor

    Concept ACK, the surprising nature of the negations was documented a few times, e.g. in #36861 (comment)

  4. fjahr commented at 8:50 AM on November 17, 2026: contributor

    e.g. in #36861 (comment)

    Hm, that was opened after I did my initial research on related open PRs. Clearly there is a lot overlap, I will check if a separate PR still make sense.

  5. fjahr commented at 9:04 AM on November 17, 2026: contributor

    The first commit (cluster limit below 1) is covered in #36861 and the last commit (disallow negating) got some approach push back there already. Generally the "piecemeal" approach there got push back too. I think this here is a bit better but it also doesn't handle everything inside argsman. I tend to drop the first and the last commit and otherwise keep the PR open separately but I will comment about it on #36861 and see what the feedback is first.

  6. in src/node/mempool_args.cpp:110 in 4b181fd471 outdated
     104 | @@ -105,8 +105,11 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& argsman, const CChainP
     105 |  
     106 |      ApplyArgsManOptions(argsman, mempool_opts.limits);
     107 |  
     108 | -    if (mempool_opts.limits.cluster_count > MAX_CLUSTER_COUNT_LIMIT) {
     109 | -        return util::Error{Untranslated(strprintf("limitclustercount must be less than or equal to %d", MAX_CLUSTER_COUNT_LIMIT))};
     110 | +    if (mempool_opts.limits.cluster_count < 1 || mempool_opts.limits.cluster_count > MAX_CLUSTER_COUNT_LIMIT) {
     111 | +        return util::Error{Untranslated(strprintf("limitclustercount must be between 1 and %d", MAX_CLUSTER_COUNT_LIMIT))};
     112 | +    }
    


    ryanofsky commented at 4:49 PM on November 17, 2026:

    In commit "mempool: Reject cluster limits below 1" (512773d111daaa4330c873ed5889b9ef511f6e3a)

    Note: This change looks right to me: -nolimitclustercount is treated as 0, and 0 is rejected as out of bounds. If we ever need an unlimited or automatic setting, an explicit value like -limitclustercount=unlimited would be better than a special meaning for -nolimitclustercount.

    Also fine with me if this moves to #36861. Both reject negated and 0 values, but the checks there range-check before narrowing to unsigned and multiplying by 1000, so they also reject -limitclustercount=4294967297, which wraps to 1 here, and very large -limitclustersize values, which overflow here and crash a -ftrapv debug build.


    fjahr commented at 9:08 AM on November 19, 2026:

    I decided to keep it here for now so the crash fix doesn't depend on #36861. I'll drop it if #36861 is merged first of course since that is a more complete fix but with the pending questions about the approach there is a chance it may take a bit longer it seems.

  7. in src/common/args.h:116 in 4b181fd471
     112 | @@ -113,6 +113,7 @@ class ArgsManager
     113 |          // ALLOW_LIST = 0x10,     //!< unimplemented, draft implementation in #16545
     114 |          DISALLOW_NEGATION = 0x20, //!< disallow -nofoo syntax
     115 |          DISALLOW_ELISION = 0x40,  //!< disallow -foo syntax that doesn't assign any value
     116 | +        NEGATE_TO_DEFAULT = 0x80, //!< make GetArg() return the default for -nofoo instead of "0"
    


    ryanofsky commented at 4:49 PM on November 17, 2026:

    In commit "args: Make negation a no-op for options that are off by default" (5d2ddcae41522a0651e20476b7481ea2e50a6fcb)

    The handling of -nosigner, -noi2psam, -norpcpassword and the other options here looks right to me. I'd suggest renaming NEGATE_TO_DEFAULT to NEGATE_TO_EMPTY and having GetArg() return "" instead of std::nullopt.

    All of these options are read with GetArg(name, ""), so this doesn't change behavior now, but it matters if a default changes: if we someday enable a default signer, I2P connectivity, or RPC password, -nosigner, -noi2psam and -norpcpassword should still mean no signer, no I2P connections and no RPC password, not whatever the new default is. It would also be consistent with GetPathArg(), which already returns an empty path for negated options, and with the general rule in doc/bitcoin-conf.md.

    And it would be a step toward the more general fix in #16545, which parses nonlegacy negated string options as "" instead of "0", and keeps the old behavior for legacy options like -onion.


    fjahr commented at 9:08 AM on November 19, 2026:

    Done as suggested

  8. in src/init.cpp:1653 in 4b181fd471 outdated
    1649 | @@ -1641,7 +1650,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
    1650 |          }
    1651 |      }
    1652 |  
    1653 | -    if (!args.IsArgSet("-cjdnsreachable")) {
    1654 | +    if (!args.GetBoolArg("-cjdnsreachable", false)) {
    


    ryanofsky commented at 4:49 PM on November 17, 2026:

    In commit "init: Read -cjdnsreachable and -help as booleans" (08b4f855104b7ef25b82d66447b9e502c9bef5e9)

    Note: The -nocjdnsreachable and -nohelp fixes look right. IsArgSet() returns true for negated options, so many of its current uses have this kind of bug, which makes it a footgun and something that would be great to drop.

  9. in src/common/args.cpp:309 in 4b181fd471 outdated
     304 | @@ -305,8 +305,9 @@ fs::path ArgsManager::GetBlocksDirPath() const
     305 |      // this function
     306 |      if (!path.empty()) return path;
     307 |  
     308 | -    if (!GetSetting_("-blocksdir").isNull()) {
     309 | -        path = fs::absolute(GetPathArg_("-blocksdir"));
     310 | +    const fs::path blocksdir{GetPathArg_("-blocksdir")};
     311 | +    if (!blocksdir.empty()) {
    


    ryanofsky commented at 4:49 PM on November 17, 2026:

    In commit "args, wallet: Treat empty -blocksdir and -walletdir as unset" (cd5bfc823063f5d06e8a15180ba05e2afc7506fb)

    Treating an empty -blocksdir= as unset looks good, but I think -noblocksdir should be an error instead of falling back to the default directory. -noblocksdir reads like an explicit instruction not to use a blocks directory, so writing blocks to the default location anyway would be misleading. -nodatadir is already rejected (#31212).

    The simplest way to do this would be the DISALLOW_NEGATION flag that -datadir uses. A better approach in the long run would map these to std::optional<fs::path>, with std::nullopt when the option is not set and an empty path when it is negated, so code like this could return specific errors about required paths that are missing instead of generic errors about negated arguments.


    fjahr commented at 9:08 AM on November 19, 2026:

    Done with DISALLOW_NEGATION.

  10. in src/init.cpp:563 in 4b181fd471
     559 | @@ -560,7 +560,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
     560 |                      ""
     561 |                  #endif
     562 |                  ), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
     563 | -    argsman.AddArg("-bantime=<n>", strprintf("Default duration (in seconds) of manually configured bans (default: %u)", DEFAULT_MISBEHAVING_BANTIME), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
     564 | +    argsman.AddArg("-bantime=<n>", strprintf("Default duration (in seconds) of manually configured bans (default: %u)", DEFAULT_MISBEHAVING_BANTIME), ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::CONNECTION);
    


    ryanofsky commented at 4:49 PM on November 17, 2026:

    re: #36880 (comment)

    In commit "init: Disallow negating options where it has no meaning" (4b181fd471f2826659e000439f10345a483309f4)

    I tend to drop the first and the last commit

    I think this commit is worth keeping. These are limits where -nofoo reads as "no limit", but treating it as 0 means something very different: -nocheckblocks checks all blocks, and -nomaxsendbuffer pauses sending whenever anything is queued. Ideally -nofoo might mean unlimited for options like these, but since negation has always meant 0, an error is the safest choice.

    My #36861 review recommended against more DISALLOW_NEGATION, but that was overbroad and I will post a correction. I still think that when 0 is just an invalid value, it's better to check for 0 so -foo=0 and -nofoo get the same error, but most options here aren't like that.

    The exception is -bantime. "No ban time" can only mean a ban time of 0, or not banning, so I think -nobantime should just be treated the same as -bantime=0, whether 0 ends up allowed or rejected (#36861 rejects it).


    fjahr commented at 9:08 AM on November 19, 2026:

    Done, I removed -bantime from the commit.

  11. in src/wallet/walletutil.cpp:15 in 4b181fd471 outdated
      11 | @@ -12,10 +12,9 @@
      12 |  namespace wallet {
      13 |  fs::path GetWalletDir()
      14 |  {
      15 | -    fs::path path;
      16 | +    fs::path path{gArgs.GetPathArg("-walletdir")};
    


    ryanofsky commented at 4:49 PM on November 17, 2026:

    In commit "args, wallet: Treat empty -blocksdir and -walletdir as unset" (cd5bfc823063f5d06e8a15180ba05e2afc7506fb)

    I don't think -nowalletdir should fall back to the default wallet directory, for the same reason as -noblocksdir (https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4602823499). For bitcoind, an error seems simplest for now. But I wouldn't rule out -nowalletdir and -nodatadir meaning what they say in the future, since they could be useful for other tools. bitcoin-cli -nodatadir could connect to a node without trying to read files from a datadir that may not be available, and bitcoin-wallet -nodatadir -nowalletdir could operate on external wallet files without touching any default wallets. Treating them as an error now keeps that possible, while treating them as the default would not.


    fjahr commented at 9:08 AM on November 19, 2026:

    Done

  12. in src/init.cpp:846 in 4b181fd471
     838 | @@ -839,6 +839,12 @@ void InitParameterInteraction(ArgsManager& args)
     839 |          }
     840 |      }
     841 |  
     842 | +    if (args.IsArgNegated("-torcontrol")) {
     843 | +        if (args.SoftSetBoolArg("-listenonion", false)) {
     844 | +            LogInfo("parameter interaction: -notorcontrol -> setting -listenonion=0");
     845 | +        }
     846 | +    }
    


    ryanofsky commented at 4:49 PM on November 17, 2026:

    In commit "init: Disable the automatic onion service with -notorcontrol" (faf0a220338cbff2e045f0535635590f2d33fbe2)

    I think it would be safer to make -notorcontrol an error while -listenonion is enabled, asking the user to pass -nolistenonion if that's what they want, instead of soft-setting -listenonion=0. Since -listenonion is on by default, the error could say something like "-notorcontrol requires -nolistenonion" rather than mention -listenonion=1.

    -torcontrol is only used for the onion service now, but it could be used for other things later, so it's useful to know whether the user wants to disable onion listening or everything that uses the control port. An error also helps users who don't know what the control port is used for.

    That said, this is more borderline than the other cases, since "no" here really does mean none, so keeping the soft-set as a convenience seems ok too. But then -torcontrol=0 should behave the same way, like -proxy=0, -onion=0 and -connect=0, which already treat 0 as disabled. Currently it still connects to 0.0.0.0:9051, since it isn't a negated value.


    fjahr commented at 9:08 AM on November 19, 2026:

    Done, made -notorcontrol an error.

  13. ryanofsky commented at 5:11 PM on November 17, 2026: contributor

    Concept ACK 4b181fd471f2826659e000439f10345a483309f4, and approach ACK with a few tweaks.

    My main feedback is that I think "no" should mean none, false, or zero, or else be an error. We should avoid more clever interpretations like "default" or "unlimited", even where they could be sensible, because the precedent for mapping negated options to falsy values is well established, and other interpretations create unnecessary ambiguity.

    Inline comments suggest changes to NEGATE_TO_DEFAULT (https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4602822953), -noblocksdir/-nowalletdir (https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4602823499, #36880 (review)), -notorcontrol (https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4602824369) and -nobantime (https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4602823756).

  14. fjahr force-pushed on Nov 19, 2026
  15. mempool: Reject cluster limits below 1
    -limitclustercount=0 or -nolimitclustercount passed the upper bound check and triggered an assertion in TxGraph when mempool sanity checks are enabled, while -limitclustersize=0 or -nolimitclustersize made every transaction fail with a misleading error. Reject both at startup.
    97deecb652
  16. args: Add NEGATE_TO_EMPTY so -nofoo reads as an empty string
    GetArg() returns "0" for a negated option, so -noblocknotify, -nowalletnotify, -nostartupnotify and -noalertnotify ran the command "0", -nosigner used "0" as the signer command, -noi2psam failed at startup and -norpcpassword set the RPC password to "0" instead of using cookie authentication. Add a NEGATE_TO_EMPTY flag that makes GetArg() return "" instead, like GetPathArg() already does for negated paths and as doc/bitcoin-conf.md describes for negated strings, and use it for these options as well as -rpcuser and -torpassword. Returning "" rather than the default keeps -nofoo meaning none if one of these options gets a default later. The flag is opt-in because other options such as -noonion and -noblockfilterindex rely on reading "0".
    a040ec7116
  17. init: Read -cjdnsreachable and -help as booleans
    Both were checked with IsArgSet(), so -cjdnsreachable=0 and -nocjdnsreachable made CJDNS reachable, contradicting the -rpcallowip error that tells users to set -cjdnsreachable=0, and -nohelp printed the help text. Use GetBoolArg() instead.
    555d9d3a99
  18. args, wallet: Fix empty and negated -blocksdir and -walletdir
    Both were checked for being set rather than for an empty path, so -noblocksdir and -blocksdir= wrote block files relative to the working directory while the block index stayed in the datadir, and -nowalletdir and -walletdir= failed at startup. Treat an empty value as unset like -datadir already does. Reject the negated forms like -nodatadir, since -noblocksdir and -nowalletdir read as not using a directory at all and falling back to the default one would be misleading.
    e954bebe35
  19. init: Require -nolistenonion with -notorcontrol
    -notorcontrol made the node connect to the Tor control port at "0", i.e. 0.0.0.0:9051, which reaches a local Tor on most systems. Reject it while the automatic onion service is enabled, so the user has to turn that off explicitly with -nolistenonion rather than having -notorcontrol guess what else to disable. It still works when -listenonion is already off, for example through -listen=0.
    c0bc030a10
  20. init: Disallow negating options where it has no meaning
    -nocheckblocks, -nomaxreceivebuffer, -nomaxsendbuffer and -nomaxtipage read as 0, which is the opposite of what the negation suggests. All blocks are checked, buffers are minimal and the node never leaves initial block download. Reject them at startup instead.
    8731550b05
  21. fjahr force-pushed on Nov 19, 2026
  22. DrahtBot added the label CI failed on Nov 19, 2026
  23. fjahr commented at 9:11 AM on November 19, 2026: contributor

    Addressed review feedback from @ryanofsky, thanks a lot! Also rebased for good measure since the CI failed with an unrelated error. The table in the pull description is updated as well.

  24. DrahtBot removed the label CI failed on Nov 19, 2026

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-11-19 19:51 UTC

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