init: Fix surprising behaviors of negated options

bitcoin/bitcoin: PR #36880

6 suggestions

Optional improvements

Link

[suggestion] · Configuration changes lack upgrade guidance

Previously accepted settings now fail at startup or change meaning, but the PR adds no release note explaining how operators should update their configurations.

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

Details and suggested fix

Add a doc/release-notes-<PR>.md fragment covering the newly rejected -nobantime, -nocheckblocks, -nomaxreceivebuffer, -nomaxsendbuffer, and -nomaxtipage forms, zero or negated cluster limits, and -notorcontrol combined with -listenonion=1. These changes also affect bitcoin.conf, because config-file entries use the same negation validation. List the errors and advise removing unwanted settings to restore defaults, or supplying an explicit numeric value where that remains supported.

Also describe the interpretation changes: -norpcpassword now selects the cookie-authentication path instead of password "0", false CJDNS settings disable reachability, and -notorcontrol disables the automatic onion service. Note the corrected alert, block, startup, and wallet notification negations, and signer negation in wallet-enabled builds. These are configuration-model changes covered by the existing release-note guidance.


Link

[suggestion] · -cjdnsreachable diagnostics still describe the old presence check

CJDNS diagnostics still describe presence checks after boolean parsing, and nonnumeric spellings change meaning; their use in deployed configurations is unconfirmed.

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

Details and suggested fix

With -onlynet=cjdns -cjdnsreachable=0, startup now says -cjdnsreachable is not provided even though it was supplied. Change the error and associated comment to say the option is not enabled, and change the help's If set wording to describe enablement and numeric boolean syntax. Update the test expectation accordingly. This distinction also matters for entries such as cjdnsreachable=true or yes: InterpretBool reads them as false, whereas the old presence check enabled CJDNS. Without -onlynet=cjdns, those entries now remove CJDNS from reachable networks without a warning. The documented bare -cjdnsreachable form still works.


Link

[suggestion] · Production negation registrations lack regression coverage

The new tests cover the conversion helper and two server registrations, but not bitcoin-cli or most affected production registrations.

Location: test/functional/feature_config_args.py:238 (head).

Details and suggested fix

Each option depends on its own NEGATE_TO_DEFAULT flag. Removing only bitcoin-cli's -rpcpassword flag would make CLI -norpcpassword send password "0" instead of reading the cookie, while the synthetic unit test and this server-startup case would remain unaffected. When bitcoin-cli is built, call it against the running cookie-authenticated node with -norpcpassword and -noipcconnect, and assert that a simple RPC succeeds. Also add a small table-driven retrieval test using the real SetupServerArgs registrations, with the appropriate system, wallet, and external-signer build guards. Check the affected notification, signer, RPC-user, and Tor-password negations return their defaults without spawning commands.


Link

[suggestion] · Flagged string tests do not distinguish literal values from negation

The stringarg test never retrieves literal values from flagged -bar, so it cannot distinguish negation from an explicitly supplied "0" or empty string.

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

Details and suggested fix

Every ordinary-value assertion retrieves unflagged -foo, even in the case that also parses -bar. A regression confined to flagged options could therefore map literal "0" or "" to the default without failing these assertions. Add -bar=0, -bar=, and -bar=eleven cases using a nonempty default, expecting "0", "", and "eleven" respectively. Also check that the optional-returning overload remains engaged for literal -bar=0, unlike -nobar.


Link

[suggestion] · The -torcontrol help omits its new disable behavior

The help for -torcontrol omits its new cross-option effect and the startup conflict with -listenonion=1.

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

Details and suggested fix

Negating the control endpoint now soft-sets -listenonion=0; it does not override an explicit true value, which instead causes initialization to fail. The help currently describes only the endpoint syntax and default. Add a sentence stating that -notorcontrol disables the automatic onion service and cannot be combined with -listenonion=1, so users can discover the intended behavior without encountering the conflict first.


Link

[suggestion] · The negated Tor-control test does not check that the controller stays off

The new Tor-control test verifies a parameter-interaction message, not the absence of the controller thread, so a later initialization regression could pass.

Location: test/functional/feature_torcontrol.py:302 (head).

Details and suggested fix

The successful-start case removes the fixture's listenonion=0 setting, but only asserts the soft-setting log message. A stale or incorrect listenonion value at the later TorController construction could leave that assertion passing while still starting the controller. Add unexpected_msgs=["Entering Tor control thread"] and keep the log context open through self.stop_node(0). The framework already enables debug logging, and shutdown joins any controller thread before process exit, so this also catches a thread that starts late.


Coverage details

Background

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

Documented decisions

Negation was deliberately extended beyond boolean switches so users could disable a facility whose ordinary argument is a value, without reserving a particular literal value to mean disabled.

Historical PR #12713 explicitly motivated distinguishing -nofoo from -foo=0 with the example of disabling a filename-valued debug log option. The pinned parser retains that distinction by representing negation as boolean false. This is the relevant precedent for interpreting negated command, credential, proxy, and path options as more than ordinary strings.

Source 1

Preserving existing argument semantics was an explicit constraint when introducing negation tracking, rather than globally redefining how every option interprets zero.

PR #12713 stated that existing callers would continue parsing options as before while gaining a way to inspect explicit negation. At the pinned base, string retrieval converts false to "0"; the head adds an opt-in default-returning flag instead of replacing that conversion universally. The historical compatibility constraint explains why explicit negation and literal zero can coexist as distinct concepts.

Source 1

Earlier argument-validation proposals sought both to reject invalid user settings at startup and to catch mismatches between how an option is declared and how callers retrieve it.

PR #16545 proposed startup errors for values inconsistent with registered flags and internal errors for inconsistent registration and retrieval. PR #17580 similarly proposed enforcing list versus scalar retrieval to prevent bugs. These are historical precedents for the affected distinction between presence checks, boolean reads, string reads, and numerical validation—not evidence that those broader proposals are implemented at the pinned head.

Source 1 · Source 2

Ralph's inferences

The central design tradeoff is between a convenient, uniform negation syntax and option-specific meanings of disabled, absent, empty, and zero.

The inspected parser stores negation separately, but retrieval determines its effect: boolean false, integer zero, string "0", or an empty path. The head's selected string defaults and empty-directory fallbacks therefore concern translating operator intent into each subsystem's existing configuration model. This interpretation follows the historical nonboolean-disable use case; it is not a documented rationale for every option changed here.

Source 1 · Source 2

A generic negation facility does not by itself establish that a numerical resource limit supports an unlimited mode.

In the pinned mempool argument code, cluster limits are numerical values: the base checks the count's upper bound, while the head requires a count from 1 through 64 and a positive size. The historical distinction between negation and literal values supports treating the spelling of a setting separately from its admissible domain. The inspected historical record does not establish the computational or adversarial rationale for these particular cluster bounds.

Source 1 · Source 2