mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:44:38 +00:00
init: Fix surprising behaviors of negated options #36880
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36880
Loading…
Reference in a new issue
No description provided.
Delete branch "2026-11-rpc-no-fix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
While looking into #36759 I discovered
-notorcontroldid 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-nofoodoes 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.
-nolimitclustercounthits an assertion inTxGraphon the first mempool transaction.-nolimitclustersizerejects every transaction.GetArg()returns"0"for a negated option. The-no*notifyoptions run the command0,-nosigneruses0as signer,-noi2psamfails startup and-norpcpasswordsets the password to0. Opt-in because options like-noonionand-noblockfilterindexdepend on reading"0".NEGATE_TO_EMPTYmakesGetArg()return"".-cjdnsreachable=0and-nocjdnsreachableturn CJDNS on.-nohelpprints the help.GetBoolArg()instead ofIsArgSet().-noblocksdirwrites block files relative to the working directory.-nowalletdirfails startup.DISALLOW_NEGATION. An empty value falls back to the default directory, like-datadirdoes.-notorcontrolconnects to0.0.0.0:9051, which reaches a local Tor.-listenonionis disabled.-nocheckblocks,-nomaxreceivebuffer,-nomaxsendbufferand-nomaxtipageread as 0, the opposite of what the user asked for.DISALLOW_NEGATION.-nomempoolexpiryhas 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.The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
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.
Earlier concerns neither republished nor resolved: 3 suggestions. See the Run archive linked from the Review report for their assessments.
🔵 Suggestion · CLI
-norpcuserassertion also accepts the old usernameThe new
bitcoin-cli -norpcuserassertion accepts the same authentication error for both""and"0", so removing the CLI’sNEGATE_TO_EMPTYflag would leave it passing.Location:
test/functional/interface_bitcoin_cli.py:247(head).🔵 Suggestion · GUI signer field still displays
0for a negated-signerWith
nosigner=1inbitcoin.conf, the node now clears the signer but the Options dialog still displays0, because its string conversion bypassesNEGATE_TO_EMPTY.Location:
src/init.cpp:640(head).🔵 Suggestion · The
NEGATE_TO_EMPTYtest misses literal"0"The
stringargtest would still pass ifNEGATE_TO_EMPTYalso erased a literal"0", despite that value needing to remain distinct from negation.Location:
src/test/getarg_tests.cpp:229(head).Review coverage was incomplete.
Reviewed:
9cf00ac7ae7f· Review report · Previous reportspermalink
Concept ACK, the surprising nature of the negations was documented a few times, e.g. in https://github.com/bitcoin/bitcoin/pull/36861#issuecomment-6862113841
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.
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.
Concept ACK
4b181fd471, and approach ACK with a few tweaks.My main feedback is that "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, https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4602824031),-notorcontrol(https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4602824369) and-nobantime(https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4602823756).In commit "args, wallet: Treat empty -blocksdir and -walletdir as unset" (
cd5bfc8230)Treating an empty
-blocksdir=as unset looks good, but I think-noblocksdirshould be an error instead of falling back to the default directory.-noblocksdirreads like an explicit instruction not to use a blocks directory, so writing blocks to the default location anyway would be misleading.-nodatadiris already rejected (#31212).The simplest way to do this would be the
DISALLOW_NEGATIONflag that-datadiruses. A better approach in the long run would map these tostd::optional<fs::path>, withstd::nulloptwhen 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.In commit "args: Make negation a no-op for options that are off by default" (
5d2ddcae41)The handling of
-nosigner,-noi2psam,-norpcpasswordand the other options here looks right to me. I'd suggest renamingNEGATE_TO_DEFAULTtoNEGATE_TO_EMPTYand havingGetArg()return""instead ofstd::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,-noi2psamand-norpcpasswordshould still mean no signer, no I2P connections and no RPC password, not whatever the new default is. It would also be consistent withGetPathArg(), 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.re: https://github.com/bitcoin/bitcoin/pull/36880#issuecomment-6943566644
In commit "init: Disallow negating options where it has no meaning" (
4b181fd471)I think this commit is worth keeping. These are limits where
-nofooreads as "no limit", but treating it as 0 means something very different:-nocheckblockschecks all blocks, and-nomaxsendbufferpauses sending whenever anything is queued. Ideally-nofoomight 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=0and-nofooget 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-nobantimeshould just be treated the same as-bantime=0, whether 0 ends up allowed or rejected (#36861 rejects it).In commit "init: Disable the automatic onion service with -notorcontrol" (
faf0a22033)I think it would be safer to make
-notorcontrolan error while-listenonionis enabled, asking the user to pass-nolistenonionif that's what they want, instead of soft-setting-listenonion=0. Since-listenonionis on by default, the error could say something like "-notorcontrol requires -nolistenonion" rather than mention-listenonion=1.-torcontrolis 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=0should behave the same way, like-proxy=0,-onion=0and-connect=0, which already treat 0 as disabled. Currently it still connects to0.0.0.0:9051, since it isn't a negated value.In commit "init: Read -cjdnsreachable and -help as booleans" (
08b4f85510)Note: The
-nocjdnsreachableand-nohelpfixes 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.In commit "mempool: Reject cluster limits below 1" (
512773d111)Note: This change looks right to me:
-nolimitclustercountis 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=unlimitedwould 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
unsignedand multiplying by 1000, so they also reject-limitclustercount=4294967297, which wraps to 1 here, and very large-limitclustersizevalues, which overflow here and crash a-ftrapvdebug build.In commit "args, wallet: Treat empty -blocksdir and -walletdir as unset" (
cd5bfc8230)I don't think
-nowalletdirshould 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-nowalletdirand-nodatadirmeaning what they say in the future, since they could be useful for other tools.bitcoin-cli -nodatadircould connect to a node without trying to read files from a datadir that may not be available, andbitcoin-wallet -nodatadir -nowalletdircould 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.Done, made
-notorcontrolan error.Done
Done, I removed
-bantimefrom the commit.Done with
DISALLOW_NEGATION.Done as suggested
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.
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.
Code review ACK
8731550b05. This fixes a set of options where-nofoodid the opposite of what it says, failed startup, or crashed the node, and makes negation behave predictably: negated options now mean empty or 0, and negating a limit where 0 would mean something very different is an error.Thanks for taking all the suggestions from my last review!
In commit "args, wallet: Fix empty and negated -blocksdir and -walletdir" (
e954bebe35)I think the commit message could be clearer about what changes, and the description of the old
-noblocksdirbehavior only applies to some platforms. When I ran a master build on Linux,-noblocksdirand-blocksdir=didn't write blocks to the working directory. Startup aborted with an uncaught exception ("filesystem error: cannot make absolute path"), becausefs::absolute("")throws with libstdc++ and only returns the working directory with libc++. Here's a suggestion listing the before and after behavior for each value that changes:The
-noblocksdirrow in the PR description table could be updated the same way.In commit "init: Require -nolistenonion with -notorcontrol" (
c0bc030a10)I think an error explaining how these are connected could be more helpful here:
-listenonionis on by default, so someone passing-notorcontrolmay not know how it's involved. And-nolistenonionon its own is enough to stop the node from connecting to the control port, since-listenonionis the only thing that uses it.In commit "init: Require -nolistenonion with -notorcontrol" (
c0bc030a10)Not blocking, but it might be worth adding a short release note, since some settings that used to be accepted now fail at startup:
-notorcontrolwhile onion listening is enabled,-noblocksdir,-nocheckblocks,-nomaxreceivebuffer,-nomaxsendbufferand-nomaxtipage. A note listing them, with-nolistenonionas the replacement for-notorcontrol, would help anyone who hits the new errors after upgrading. The Ralph review suggested this too.In commit "args: Add NEGATE_TO_EMPTY so -nofoo reads as an empty string" (
a040ec7116)This only checks that the node starts with
-noi2psam -norpcpassword, so most options changed in this commit have no test showing that-nofoonow does something sensible. I tried adding a check for each one to the existing functional test for that option. Each passes-foo=X -nofoo, the way someone would turn off a setting frombitcoin.conf:feature_startupnotify.py:-nostartupnotifydoesn't run the command.feature_notifications.py:-noblocknotifyand-nowalletnotifywrite no notification files and run no command.-noalertnotifyonly checks that no command runs, since the alert doesn't fire again after a restart.rpc_signer.py: with-nosigner,enumeratesignersreports that no signer is configured.p2p_i2p_ports.py: with-noi2psam, I2P is unreachable and has no proxy.rpc_users.py:-norpcpasswordfalls back to cookie authentication, and-norpcusersets an empty user name, not0.interface_bitcoin_cli.py:bitcoin-cli -norpcpassworduses the cookie file.-norpcusersends an empty user name, which this node can't distinguish from0since it uses cookie authentication.feature_torcontrol.py: with-notorpassword, the node uses NULL authentication.All of these pass on this branch and fail with the
NEGATE_TO_EMPTYcheck inGetArg()commented out. With the old behavior, the notify options print "0: command not found" to stderr, which the test framework checks when stopping the node. With these tests, the startup check here could probably be dropped. Feel free to use any of this:Diff
Added a release note in a new commit.
Taken, thanks.
Taken the suggested commit message, thanks!
Thanks, I added them to the
NEGATE_TO_EMPTYcommit with you as co-author and dropped the startup check.Addressed feedback from @ryanofsky , thanks a lot again! Also required a rebase due to the merge of #36637.
Code review
f65919e115. The changes from my last review all look good, but the new-nosignertest found a real bug in builds without the wallet (https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4699787496), so I'll re-ACK once that's fixed.Thanks for the quick update and for adding the tests!
re: https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4687251685
In commit "doc: Add release note for negated option changes" (
f65919e115)Thanks! It could also mention the settings that now work or mean something different, since those can change what a node does after upgrading too:
-blocksdir=and-walletdir=now use the default directory,-cjdnsreachable=0and-nocjdnsreachablenow disable CJDNS instead of enabling it, and negated options like-norpcpassword,-nosignerand-noblocknotifyare now treated as empty instead of0, so-norpcpassworduses cookie authentication. The Ralph review suggested this too.In commit "args: Add NEGATE_TO_EMPTY so -nofoo reads as an empty string" (
fb15cb374f)The new
rpc_signer.pycheck is failing in the "No wallet" CI job, and I think it found a real bug. In builds without the wallet,-signeris only registered byDummyWalletInitas a plain hidden option, so it doesn't getNEGATE_TO_EMPTY, but the node still reads it, for example in theenumeratesignersRPC, so-nosignerstill runs the command0there.Since the node reads
-signerwhether or not the wallet is enabled, I think it should be registered as a node option instead of a wallet option. Moving this registration intoSetupServerArgs()ininit.cpp, inside the same#ifdef ENABLE_EXTERNAL_SIGNER, and dropping-signerfrom theDummyWalletInitlist fixes the test for me in a no-wallet build. KeepingOptionsCategory::WALLETleaves the-helpoutput unchanged in wallet builds.(Not directly related to this PR, but it might be good for ArgsManager to handle placeholder options like the
DummyWalletInitones better. Currently they are registered as ordinary hidden options, the same way as real hidden options like-dbcrashratio, so setting them on the command line or in the config file is silently ignored, and nothing stops code from reading them. If they were marked as placeholders, ArgsManager could warn when they are set and raise an error when one is retrieved, which would have caught this bug even without a test.)In commit "args: Add NEGATE_TO_EMPTY so -nofoo reads as an empty string" (
fb15cb374f)The version of this test I posted in https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4683423642 had a comment here saying the large-work invalid chain warning isn't raised again after node0 restarts, so
-alertnotifycouldn't be tested. That was wrong, and thanks for correcting it in this push: the warning is raised again, so the alert command would run without-noalertnotify. That means the "only checked for not running a bogus command" part no longer applies, and the test could check the alert file the same way as the other two options:and after the
walletnotifycheck:With that, the test fails if
-noalertnotifyis removed.Added these to the release notes, thanks.
Cool, that works! Taken, thanks!
Right, I agree with your analysis. I moved the registration to
SetupServerArgs()into a new commit before theNEGATE_TO_EMPTYone and drop-signerfromDummyWalletInit.Makes sense, I am looking into this as a follow-up now.
Addressed feedback from @ryanofsky , thanks again for the review!
I like this targeted cleanup of surprising -no behavior while preserving options where 0 is meaningful. I left inline suggestions for -nodbcache, the signer field in Qt, and a few test gaps.
With
nosigner=1, the Options dialog should show an empty signer path instead of0.Example patch
Without a configured
blocksdir, this test passes even if the empty-blocksdir=override is ignored.Example patch
-nodbcachesilently selects the 4 MiB minimum rather than disabling the cache. It should be rejected alongside the buffer negations.Example patch
The alert-file check can pass without exercising
-noalertnotifyif the warning does not recur after restart.Example patch
This test also needs to cover
-notorcontrol -listen=0, which disables onion listening implicitly.Example patch
The authentication failure is the same for an empty username and
0, so this check does not prove-norpcuserworks.Example patch
Code review ACK
9cf00ac7ae. This fixes a set of options where-nofoodid the opposite of what it says, failed startup, or crashed the node, and makes negation behave predictably: negated options now mean empty or 0, and negating a limit where 0 would mean something very different is an error.Thanks for the quick updates and for following up on the placeholder options! l0rinc's suggestions look good to me too, especially making
-nodbcachean error (https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4740765473) and the two test improvements (https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4740764896, https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4740765205).In commit "doc: Add release note for negated option changes" (
9cf00ac7ae)It might help to mention what previous behavior was, since "now uses the default directory" raises question of what was happening before:
re: https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4712445114
In commit "args: Add NEGATE_TO_EMPTY so -nofoo reads as an empty string" (
c3b35225b5)Good catch. But I think it would be better to fix this in
SettingToString()than in the GUI. The underlying problem is thatSettingToString()converts negated values differently fromGetArg(), which appliesNEGATE_TO_EMPTYitself before calling it. IfSettingToString()took the option's flags as a required argument and appliedNEGATE_TO_EMPTYitself,GetArg()could passGetArgFlags()andOptionsModelcould pass the flags fromgArgs, where the GUI registers its options, so the two couldn't disagree. Making the argument required also lets the compiler find every caller.I tried this with your test, and it passes with the change and fails without it. The test needs to register the options first, because the Qt test harness clears them:
Diff
re: https://github.com/bitcoin/bitcoin/pull/36880#discussion_r4712452641
Agree, this is better than the check I suggested, which only showed the request failed. In
rpc_users.pythe node's user name is already checked to be empty by thecall_with_authlines before it, so thebitcoin-clicall there should only succeed if-norpcusersends an empty user name too. The Ralph review flagged the old check too.🐙 This pull request conflicts with the target branch and needs rebase.