init: Fix surprising behaviors of negated options

bitcoin/bitcoin: PR #36880

4 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · Release note omits several operator-visible behavior changes

doc/release-notes-36880.md omits changes to empty directory values, CJDNS boolean handling and negated string options, including the switch from password "0" to the cookie-authentication path for -norpcpassword.

Location: doc/release-notes-36880.md:4 (head).

Details and suggested fix

-walletdir= previously failed validation but now selects the default wallet directory; -blocksdir= now selects the default blocks location instead of passing an empty path to fs::absolute. Neither value disables wallets or block storage. Also, -cjdnsreachable=0 and -nocjdnsreachable now disable CJDNS and fail with -onlynet=cjdns. The newly flagged notification, -signer, -i2psam and credential options now read as "" rather than "0" when negated. In particular, both bitcoind and bitcoin-cli take the cookie-authentication path for -norpcpassword. Add short upgrade bullets covering these changes so operators can account for changed directory selection, startup and authentication behavior.


Link

[suggestion] · CJDNS error reports a disabled option as missing

-onlynet=cjdns -cjdnsreachable=0 now fails with an error claiming that -cjdnsreachable was not provided, even though it was explicitly set.

Location: src/init.cpp:1650 (head).

Details and suggested fix

The switch from IsArgSet() to GetBoolArg() adds explicitly false values, including -nocjdnsreachable, to this error path but leaves its presence-based wording unchanged. Change the diagnostic to say that -cjdnsreachable is not enabled. Align the help's “If set” wording and the nearby “is given” comment with the boolean meaning as well.


Link

[suggestion] · Negated-notify regression tests depend on detached-thread timing

The negated-notification functional tests can miss a missing NEGATE_TO_EMPTY registration if the detached command's diagnostic arrives after their shutdown checks.

Location: test/functional/feature_startupnotify.py:45 (head).

Details and suggested fix

For -nostartupnotify, get_count() == 1 passes for both an empty command and command "0"; only stderr or runCommand error distinguishes them. StartupNotify() runs after RPC warmup and detaches its command thread, which shutdown does not join. The block, wallet and alert checks also rely on detached-command diagnostics. Shutdown usually gives these commands time to finish, but it does not guarantee completion before observation. Unit setup already calls SetupServerArgs(), so add synchronous assertions against the production registrations: parse -startupnotify=x -nostartupnotify, assert that GetArg() returns "", and repeat for the other notification options where registered. Keep the functional checks for integration coverage.


Link

[suggestion] · NEGATE_TO_EMPTY test misses explicit zero and unset values

The current implementation preserves explicit "0", but its new unit test never asserts that a NEGATE_TO_EMPTY option distinguishes -bar=0, -nobar and an unset value.

Location: src/test/getarg_tests.cpp:227 (head).

Details and suggested fix

stringarg reads the flagged -bar only under negation; its other assertions read the unflagged -foo. Converting based on the resulting string "0" instead of value.isFalse() would therefore pass these assertions while incorrectly clearing an explicit -rpcpassword=0, causing the RPC consumers to take the cookie-authentication path. Add -bar=0 assertions expecting "0" from both string GetArg() overloads, and an unset -bar assertion expecting a nonempty caller default such as "eleven".


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Explicit negation tracking was introduced to disable non-boolean facilities without changing existing argument semantics. The 2018 proposal says -nofoo and -foo=0 could not previously be distinguished, and uses disabling a named debug logfile as its motivating example.

Negation has both an inherited value-conversion meaning and a newer facility-disablement meaning. This history explains why changing every negated string globally would affect compatibility, while commands and credentials can have different expectations from options that deliberately interpret zero.

Source 1 · Source 2

The documented configuration contract permits command-line overrides of static configuration for scripting and debugging. Its general negation rule is zero for boolean/integer settings and empty for strings, paths, and lists, with explicit exceptions rather than a universal rule that negation restores defaults.

A command-line credential or notification-command override must be able to supersede a configured value. Returning an explicitly empty string is distinct from treating the setting as absent and retrieving a default. The historical documentation also explicitly recognizes forbidden negations and zero-valued string exceptions.

Source 1

Cookie RPC authentication was introduced to allow operation without manually configuring a password and without having the daemon write secrets into its configuration file. The cookie is random, regenerated at startup, deleted at exit, and access is controlled through filesystem read permissions.

Clearing an RPC password is therefore security-significant: the intended fallback is another authentication mechanism, not unauthenticated RPC. A literal password "0" and an absent configured password select materially different credential models.

Source 1

Tor listening interactions historically distinguish default adjustment from contradictory explicit instructions. -listen=0 soft-disables -listenonion, but explicitly requesting -listenonion=1 with -listen=0 is rejected because it otherwise advertises an onion address with no listener.

The existing rejection policy has a functional reason, not merely a preference for fewer configuration combinations. The base documentation identifies -listenonion as the switch controlling automatic onion-service creation and -torcontrol/-torpassword as its configuration; the head adds the negated-control-address check alongside that established contradiction check.

Source 1 · Source 2

I2P deliberately permits -listen=0 together with an explicit -i2pacceptincoming=1. Its incoming connections operate through the SAM proxy and do not require binding a local listening socket; only the default is flipped off when -listen=0 is supplied.

Tor and I2P disablement rules are not interchangeable. Disabling inbound I2P, removing its SAM proxy configuration, and disabling local socket listening are separate operations. Historical discussion explicitly justified retaining the working explicit I2P combination.

Source 1 · Source 2

-blocksdir was introduced to place bulky block files on different storage, such as an HDD, while keeping chainstate on an SSD. The proposal retained the block index in the datadir after discussion of filesystem ordering between the block index and UTXO database.

The selected directory represents an intentional storage-placement decision, not just a filename convenience. Default-directory fallback changes where bulk data resides, while the historical split between block files and the block index remains relevant. The inspected proposal does not establish a special purpose for an empty directory value.

Source 1 · Source 2 · Source 3

-walletdir was introduced to separate wallets from the main datadir. Its default-location transition was conditional: new installations gained a wallets subdirectory, and that directory was used when present. The original proposal explicitly noted that older versions would not discover wallets in the new location.

Default fallback carries wallet-discovery compatibility obligations. The pinned base still chooses <network datadir>/wallets when it exists, otherwise the network datadir, and separately preserves automatic loading of an existing unnamed wallet. Falling back to this search is not equivalent to disabling wallets.

Source 1

Ralph's inferences

String "0" is best understood as the compatibility residue of generic boolean negation, not a purposeful command or password value. Two inspected consumers nevertheless require the distinction: -onion="" inherits the configured proxy whereas -onion="0" forbids onion connections; -blockfilterindex="" enables all filter types whereas "0" enables none.

These are concrete reasons that a global false-to-empty conversion would change established disablement semantics. The head's opt-in conversion leaves the generic false-to-"0" representation available to those consumers.

Source 1

Privacy parameter interactions are conservative defaults rather than unconditional overrides. In the base, a proxy soft-disables listening, port mapping, and address discovery; explicit bind settings can request listening, and explicitly supplied settings survive soft-setting.

The existing design balances reducing accidental exposure against honoring deliberate operator configuration. It does not imply that every negated address option should silently disable related facilities, or that every explicit combination should be accepted.

Source 1

The old empty-versus-unset directory distinction follows presence-based path validation, rather than an identified special meaning for empty paths. Any supplied blocksdir entered absolute-path conversion and directory checking; any supplied walletdir entered canonicalization, existence, directory, and absolute-path checks. Only absence selected defaults.

The head's empty-walletdir fallback changes an explicit-invalid-path outcome into default wallet discovery, while retaining validation for nonempty paths. Historical compatibility constraints concern preserving existing wallet discovery and intentional storage placement; the inspected evidence does not establish empty paths as a supported no-directory mode or establish default fallback as previously guaranteed.