Configuration argument handling improvements. #36861

Open
jlopp wants to merge 1 commit from configValidation into master AGit
jlopp commented 2026-11-13 17:54:19 +00:00 (Migrated from github.com)

Several numeric options were read with GetArg() and then stored into unsigned or wider members without a range check. A negative value wrapped to a huge value and disabled the limit it was meant to configure, and a value wider than the destination could silently become a different number.

Parse the options whose destination is unsigned with ToIntegral() on the raw string rather than with GetArg(): the typed getter saturates values it cannot represent (so a leading '-' for an unsigned T becomes 0), while ToIntegral rejects '-', trailing garbage and overflow instead of saturating. Reject the remaining out-of-range values where they are read:

  • -maxtipage: uint32_t seconds, range [0, UINT32_MAX]. A negative age placed the IBD cutoff in the future, so the node never treated its tip as recent.
  • -dbbatchsize: uint64_t bytes. A negative value wrapped to a huge batch size and disabled flushing, so a reindex could hold an unbounded batch.
  • -dbcrashratio: uint32_t, range [0, UINT32_MAX]. CoinsViewOptions::simulate_crash_ratio is changed from int to uint32_t to match.
  • -limitclustercount: [1, MAX_CLUSTER_COUNT_LIMIT]. The separate upper-bound check in ApplyArgsManOptions is folded into this one, so an invalid value is reported once with one message.
  • -limitclustersize: [1, INT64_MAX / 1000] kB. Zero made every transaction exceed the cluster size and blocked all mempool admission.
  • -limitancestorcount, -limitdescendantcount: non-negative.
  • -mempoolexpiry: [0, std::chrono::seconds::max() / 3600] hours, and the value is stored as seconds directly. The bound is taken from seconds rather than hours because std::chrono::hours is not guaranteed to be 64-bit.
  • -datacarriersize: [0, UINT_MAX]; still unchecked when -datacarrier=0 turns the limit off.
  • -bytespersigop: [0, UINT_MAX]. A negative value wrapped and inflated the sigop-adjusted size of every transaction until all were non-standard.
  • -maxsendbuffer, -maxreceivebuffer: [0, UINT_MAX / 1000], since both are multiplied by 1000 into unsigned int members.
  • -bantime: greater than 0. Zero or negative made setban without an explicit duration create an already expired ban.
  • -timeout: positive and at most INT_MAX milliseconds. A non-positive value now fails instead of silently falling back to the default (as -peertimeout already did), and a value above INT_MAX used to narrow before it could be checked (e.g. 2^32 + 1 became 1).
  • -txconfirmtarget: [1, UINT_MAX] in parameter interaction, and additionally bounded by the fee estimator's maximum when a wallet is loaded. A target beyond the estimator's range made every transaction fall back to -fallbackfee. The help text now states the minimum.

Zero remains valid wherever it already meant "disabled": -dbbatchsize, -datacarriersize, -mempoolexpiry, -maxtipage, -bytespersigop, -maxsendbuffer, -maxreceivebuffer, -limitancestorcount and -limitdescendantcount.

Since -nofoo is parsed as 0, add DISALLOW_NEGATION to the options where 0 is valid but very different from "no limit": -dbbatchsize, -mempoolexpiry, -maxreceivebuffer, -maxsendbuffer, -maxtipage, -limitancestorcount, -limitdescendantcount and -datacarriersize. Options that already reject (-bantime, -timeout, -peertimeout, -limitclustercount, -limitclustersize, -txconfirmtarget) need no separate check: negation reports the value error once. -bytespersigop still allows negation, because 0 turns the sigop adjustment off, which is exactly what -nobytespersigop says.

ReadCoinsViewArgs now returns util::Result (marked nodiscard) so its errors abort startup instead of being discarded.

Finally, -help gains the = placeholder for the options that take a value (-dbbatchsize, -bytespersigop, -datacarriersize, -stopatheight, -checkblockindex) and states the bounds for -bantime, -limitclustercount, -limitclustersize and -txconfirmtarget.

Add unit tests for the option parsers and functional tests for the accepted, rejected and negated forms.

Several numeric options were read with GetArg<int>() and then stored into unsigned or wider members without a range check. A negative value wrapped to a huge value and disabled the limit it was meant to configure, and a value wider than the destination could silently become a different number. Parse the options whose destination is unsigned with ToIntegral<T>() on the raw string rather than with GetArg<T>(): the typed getter saturates values it cannot represent (so a leading '-' for an unsigned T becomes 0), while ToIntegral rejects '-', trailing garbage and overflow instead of saturating. Reject the remaining out-of-range values where they are read: - -maxtipage: uint32_t seconds, range [0, UINT32_MAX]. A negative age placed the IBD cutoff in the future, so the node never treated its tip as recent. - -dbbatchsize: uint64_t bytes. A negative value wrapped to a huge batch size and disabled flushing, so a reindex could hold an unbounded batch. - -dbcrashratio: uint32_t, range [0, UINT32_MAX]. CoinsViewOptions::simulate_crash_ratio is changed from int to uint32_t to match. - -limitclustercount: [1, MAX_CLUSTER_COUNT_LIMIT]. The separate upper-bound check in ApplyArgsManOptions is folded into this one, so an invalid value is reported once with one message. - -limitclustersize: [1, INT64_MAX / 1000] kB. Zero made every transaction exceed the cluster size and blocked all mempool admission. - -limitancestorcount, -limitdescendantcount: non-negative. - -mempoolexpiry: [0, std::chrono::seconds::max() / 3600] hours, and the value is stored as seconds directly. The bound is taken from seconds rather than hours because std::chrono::hours is not guaranteed to be 64-bit. - -datacarriersize: [0, UINT_MAX]; still unchecked when -datacarrier=0 turns the limit off. - -bytespersigop: [0, UINT_MAX]. A negative value wrapped and inflated the sigop-adjusted size of every transaction until all were non-standard. - -maxsendbuffer, -maxreceivebuffer: [0, UINT_MAX / 1000], since both are multiplied by 1000 into unsigned int members. - -bantime: greater than 0. Zero or negative made setban without an explicit duration create an already expired ban. - -timeout: positive and at most INT_MAX milliseconds. A non-positive value now fails instead of silently falling back to the default (as -peertimeout already did), and a value above INT_MAX used to narrow before it could be checked (e.g. 2^32 + 1 became 1). - -txconfirmtarget: [1, UINT_MAX] in parameter interaction, and additionally bounded by the fee estimator's maximum when a wallet is loaded. A target beyond the estimator's range made every transaction fall back to -fallbackfee. The help text now states the minimum. Zero remains valid wherever it already meant "disabled": -dbbatchsize, -datacarriersize, -mempoolexpiry, -maxtipage, -bytespersigop, -maxsendbuffer, -maxreceivebuffer, -limitancestorcount and -limitdescendantcount. Since -nofoo is parsed as 0, add DISALLOW_NEGATION to the options where 0 is valid but very different from "no limit": -dbbatchsize, -mempoolexpiry, -maxreceivebuffer, -maxsendbuffer, -maxtipage, -limitancestorcount, -limitdescendantcount and -datacarriersize. Options that already reject (-bantime, -timeout, -peertimeout, -limitclustercount, -limitclustersize, -txconfirmtarget) need no separate check: negation reports the value error once. -bytespersigop still allows negation, because 0 turns the sigop adjustment off, which is exactly what -nobytespersigop says. ReadCoinsViewArgs now returns util::Result<void> (marked [[nodiscard]]) so its errors abort startup instead of being discarded. Finally, -help gains the =<n> placeholder for the options that take a value (-dbbatchsize, -bytespersigop, -datacarriersize, -stopatheight, -checkblockindex) and states the bounds for -bantime, -limitclustercount, -limitclustersize and -txconfirmtarget. Add unit tests for the option parsers and functional tests for the accepted, rejected and negated forms.
DrahtBot commented 2026-11-13 17:54:28 +00:00 (Migrated from github.com)

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.

Type Reviewers
ACK ryanofsky
Concept ACK l0rinc, fjahr
Approach NACK sedited

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:

  • #36540 (mempool: remove time-based transaction expiry by ismaelsadeeq)
  • #36170 (net: stop sharing P2P listeners with automatic Tor services by l0rinc)
  • #36000 (validation: prefetch blocks while connecting by l0rinc)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36861 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36861.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36861#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [ryanofsky](https://github.com/bitcoin/bitcoin/pull/36861#pullrequestreview-6114531725) | | Concept ACK | [l0rinc](https://github.com/bitcoin/bitcoin/pull/36861#issuecomment-6862113841), [fjahr](https://github.com/bitcoin/bitcoin/pull/36861#issuecomment-6943920970) | | Approach NACK | [sedited](https://github.com/bitcoin/bitcoin/pull/36861#issuecomment-6863371683) | 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: * [#36540](https://github.com/bitcoin/bitcoin/pull/36540) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36540.svg"></sub> (mempool: remove time-based transaction expiry by ismaelsadeeq) * [#36170](https://github.com/bitcoin/bitcoin/pull/36170) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36170.svg"></sub> (net: stop sharing P2P listeners with automatic Tor services by l0rinc) * [#36000](https://github.com/bitcoin/bitcoin/pull/36000) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36000.svg"></sub> (validation: prefetch blocks while connecting by l0rinc) 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-->
First-time contributor

Earlier concerns neither republished nor resolved: 1 minor finding · 3 suggestions. See the Run archive linked from the Review report for their assessments.

🟠 Minor · Release notes misdescribe restrictive zero values as unlimited

The new release note can lead operators to set -mempoolexpiry=0 expecting no expiry, although zero instead expires older transactions at the next limiting pass.

Location: doc/release-notes-36861.md:29 (head).

🔵 Suggestion · -maxtipage strict parsing also removes a previously tested range

Strict parsing rejects previously regression-tested -maxtipage values through INT64_MAX even though the seconds-based consumer handles them; no operational reliance on the wider DEBUG_ONLY range is known.

Location: src/node/chainstatemanager_args.cpp:63 (head).

🔵 Suggestion · mempool_args_validation discards the parsed values

mempool_args_validation checks only success or failure, so incorrect stored values and a regression in wide-hour expiry handling would pass its new assertions.

Location: src/test/mempool_tests.cpp:557 (head).

🔵 Suggestion · Strict-parser tests miss numeric prefixes with trailing garbage

The new database-option assertions do not distinguish strict whole-string parsing from prefix parsing with the same range checks.

Location: src/test/validation_chainstatemanager_tests.cpp:1026 (head).

🔵 Suggestion · -txconfirmtarget estimator policy is coupled to storage-range checks

A separate wallet commit would make the new load-time estimator ceiling, including its -blocksonly exemption, independently reviewable and revertible without undoing unrelated numeric hardening.

Location: src/wallet/wallet.cpp:2854 (commit).

Review coverage was incomplete.


Reviewed: 830af36b820d · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:806938d40e279b6d701b2e78128bb1a09b55193a0b697245a1dce6241d3081c1:3607c760b63c01fb7f1f349adfc3fd0614b148a7df02e42f2f0edc2d448925a1 --> <!-- ralph-base:0e8f70a86314bc73539b110d947c41d40c4886fc --> <!-- ralph-head:830af36b820d3e4f331d34023aef44e3f687d927 --> <!-- ralph-case:067cbfbbbdf6f3dc26278d888a545935eee8c237c1b5512ca3c68bbb44286608 --> Earlier concerns neither republished nor resolved: 1 minor finding · 3 suggestions. See the Run archive linked from the Review report for their assessments. **🟠 Minor · Release notes misdescribe restrictive zero values as unlimited** The new release note can lead operators to set `-mempoolexpiry=0` expecting no expiry, although zero instead expires older transactions at the next limiting pass. Location: [`doc/release-notes-36861.md:29`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/830af36b820d3e4f331d34023aef44e3f687d927/doc/release-notes-36861.md#L29>) (head). **🔵 Suggestion · `-maxtipage` strict parsing also removes a previously tested range** Strict parsing rejects previously regression-tested `-maxtipage` values through `INT64_MAX` even though the seconds-based consumer handles them; no operational reliance on the wider `DEBUG_ONLY` range is known. Location: [`src/node/chainstatemanager_args.cpp:63`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/830af36b820d3e4f331d34023aef44e3f687d927/src/node/chainstatemanager_args.cpp#L63>) (head). **🔵 Suggestion · `mempool_args_validation` discards the parsed values** `mempool_args_validation` checks only success or failure, so incorrect stored values and a regression in wide-hour expiry handling would pass its new assertions. Location: [`src/test/mempool_tests.cpp:557`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/830af36b820d3e4f331d34023aef44e3f687d927/src/test/mempool_tests.cpp#L557>) (head). **🔵 Suggestion · Strict-parser tests miss numeric prefixes with trailing garbage** The new database-option assertions do not distinguish strict whole-string parsing from prefix parsing with the same range checks. Location: [`src/test/validation_chainstatemanager_tests.cpp:1026`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/830af36b820d3e4f331d34023aef44e3f687d927/src/test/validation_chainstatemanager_tests.cpp#L1026>) (head). **🔵 Suggestion · `-txconfirmtarget` estimator policy is coupled to storage-range checks** A separate wallet commit would make the new load-time estimator ceiling, including its `-blocksonly` exemption, independently reviewable and revertible without undoing unrelated numeric hardening. Location: src/wallet/wallet.cpp:2854 (commit). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`830af36b820d`](<https://git.fish.foo/bitcoin/bitcoin/commit/830af36b820d3e4f331d34023aef44e3f687d927>) · [Review report](<https://review.fish.foo/report/36861-830af36b820d3e4f331d34023aef44e3f687d927-3195-11.html>) · [Previous reports](<https://review.fish.foo/traces/36861/>) [permalink](<https://review.fish.foo/report/36861-830af36b820d3e4f331d34023aef44e3f687d927-3195-11.html>)
l0rinc commented 2026-11-13 18:55:26 +00:00 (Migrated from github.com)

Concept ACK

There are lots of AI findings about these potential misconfigurations, so it would be good to close off as many of them as possible in one go.

A few closely related cases seem worth covering as well:

  • -timeout values above INT_MAX are narrowed before the new positivity check (similar ones were already attempted here and closed).
  • Very large -mempoolexpiry values can overflow when converted from hours to seconds.
  • A negative -txconfirmtarget wraps into the wallet's unsigned target and can make fee estimation fall back to -fallbackfee.
  • Negating an integer option is documented as setting it to 0, so -nolimitclustersize and -nobantime are equivalent to the zero values this PR explicitly accepts. -limitclustersize=0 makes every transaction oversized and prevents normal mempool admission, while -bantime=0 makes setban without an explicit duration create an immediately expired ban.

CI seems to fail because the new test loop binds a std::string reference to temporary strings.

Concept ACK There are lots of AI findings about these potential misconfigurations, so it would be good to close off as many of them as possible in one go. A few closely related cases seem worth covering as well: - `-timeout` values above `INT_MAX` are narrowed before the new positivity check (similar ones were already attempted here and closed). - Very large `-mempoolexpiry` values can overflow when converted from hours to seconds. - A negative `-txconfirmtarget` wraps into the wallet's unsigned target and can make fee estimation fall back to `-fallbackfee`. - Negating an integer option is documented as setting it to `0`, so `-nolimitclustersize` and `-nobantime` are equivalent to the zero values this PR explicitly accepts. `-limitclustersize=0` makes every transaction oversized and prevents normal mempool admission, while `-bantime=0` makes `setban` without an explicit duration create an immediately expired ban. CI seems to fail because the new test loop binds a `std::string` reference to temporary strings.
DrahtBot commented 2026-11-13 18:58:18 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task i686: https://github.com/bitcoin/bitcoin/actions/runs/43477395661/job/132064683071
LLM reason (✨ experimental): The build failed because mempool_tests.cpp triggers a range-loop warning treated as an error: const std::string& binds to temporary strings.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `i686`: https://github.com/bitcoin/bitcoin/actions/runs/43477395661/job/132064683071</sub> <sub>LLM reason (✨ experimental): The build failed because `mempool_tests.cpp` triggers a range-loop warning treated as an error: `const std::string&` binds to temporary strings.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
sedited commented 2026-11-13 19:56:00 +00:00 (Migrated from github.com)

See https://github.com/bitcoin/bitcoin/issues/36763

But I think I'm Approach NACK at yet another piecemeal approach to a solution for this. This should be solved by the args handler itself, not with many different bug prone special cases.

See https://github.com/bitcoin/bitcoin/issues/36763 But I think I'm Approach NACK at yet another piecemeal approach to a solution for this. This should be solved by the args handler itself, not with many different bug prone special cases.
ryanofsky (Migrated from github.com) reviewed 2026-11-13 22:56:43 +00:00
ryanofsky (Migrated from github.com) left a comment

Concept ACK 1ab3f14858 for parsing improvements here, but I'd recommend against increased use of the DISALLOW_NEGATION flag:

  • If your option can't accept zero values, DISALLOW_NEGATION is only a partial fix and may allow zeroes to slip through because you are only guarding against them being set ib a single path. Better to check for valid values one place instead of multiple.
  • It creates inconsistent UX where -option=0 and -nooption have different behaviors without a clear reason, when normal behavior is for them to behave the same.

DISALLOW_NEGATION was intended to used rarely and eventually removed (https://github.com/bitcoin/bitcoin/pull/22766#issuecomment-944924866) and this PR seems to increase usage by a lot. The other changes here look very good though.

Concept ACK 1ab3f148582c21054dfc9323623edcf9768949f6 for parsing improvements here, but I'd recommend against increased use of the DISALLOW_NEGATION flag: - If your option can't accept zero values, DISALLOW_NEGATION is only a partial fix and may allow zeroes to slip through because you are only guarding against them being set ib a single path. Better to check for valid values one place instead of multiple. - It creates inconsistent UX where -option=0 and -nooption have different behaviors without a clear reason, when normal behavior is for them to behave the same. DISALLOW_NEGATION was intended to used rarely and eventually removed (https://github.com/bitcoin/bitcoin/pull/22766#issuecomment-944924866) and this PR seems to increase usage by a lot. The other changes here look very good though.
maflcko (Migrated from github.com) reviewed 2026-11-16 11:16:47 +00:00
maflcko (Migrated from github.com) left a comment

left some nits

left some nits
maflcko (Migrated from github.com) commented 2026-11-16 11:10:51 +00:00

this fix seems wrong. The correct fix would be to just parse as u32. Note that chrono itself can't deal with i64 here: std::chrono::seconds std::chrono::duration</* int35 */>

this fix seems wrong. The correct fix would be to just parse as u32. Note that chrono itself can't deal with i64 here: `std::chrono::seconds std::chrono::duration</* int35 */>`
maflcko (Migrated from github.com) commented 2026-11-16 11:12:07 +00:00

u64?

u64?
maflcko (Migrated from github.com) commented 2026-11-16 11:13:32 +00:00

maybe simulate_crash_ratio should be u32?

maybe `simulate_crash_ratio` should be u32?
maflcko (Migrated from github.com) commented 2026-11-16 11:15:31 +00:00

parsing should be done as u32?

parsing should be done as u32?
fjahr commented 2026-11-17 09:20:28 +00:00 (Migrated from github.com)

Concept ACK

There is a bit of overlap between this and https://github.com/bitcoin/bitcoin/pull/36880 and I didn't catch the overlap because I looked for related PRs before this PR here was opened. This particularly focusses on the "-no..." flags behavior. It may be a little bit better in some parts but others may still be considered too "piecemeal".

I could drop parts of my PR to remove the overlap but I would first like to see if the approach should be completely different. I am particularly interested in fixing the -no... options that either do the complete opposite of what's expected or even prevent startup or can crash the node. I think that is worth fixing even with a more priecemeal approach but I am also fine if these can drive a faster implementation of fixes within argsman.

Concept ACK There is a bit of overlap between this and https://github.com/bitcoin/bitcoin/pull/36880 and I didn't catch the overlap because I looked for related PRs before this PR here was opened. This particularly focusses on the "-no..." flags behavior. It may be a little bit better in some parts but others may still be considered too "piecemeal". I could drop parts of my PR to remove the overlap but I would first like to see if the approach should be completely different. I am particularly interested in fixing the `-no...` options that either do the complete opposite of what's expected or even prevent startup or can crash the node. I think that is worth fixing even with a more priecemeal approach but I am also fine if these can drive a faster implementation of fixes within argsman.
ryanofsky (Migrated from github.com) reviewed 2026-11-17 17:44:41 +00:00
ryanofsky (Migrated from github.com) left a comment

re: https://github.com/bitcoin/bitcoin/pull/36861#pullrequestreview-5899222221

Correction to my earlier review: I overstated the case against DISALLOW_NEGATION, sorry about that. It makes sense for options that are a maximum, limit, or timeout, where -nofoo reads as "no limit" but 0 means something very different. Ideally -nofoo might mean unlimited for these, but since negation has always meant 0, an error is the safest choice.

I still think negation should generally behave like setting 0 or empty values, and if these values are invalid, better to check for them once than have multiple checks producing different errors. By that standard, about half of the uses here look right to me, and the rest aren't needed:

  • Make sense: -dbbatchsize, -mempoolexpiry, -maxreceivebuffer, -maxsendbuffer, -maxtipage, -limitancestorcount, -limitdescendantcount, -datacarriersize.
  • Not needed because the PR already rejects 0, so -nofoo would get that error: -bantime, -timeout, -peertimeout, -limitclustercount, -limitclustersize, -txconfirmtarget.
  • Not needed because 0 means what -nofoo says: -bytespersigop, where 0 turns off the sigop adjustment.
re: https://github.com/bitcoin/bitcoin/pull/36861#pullrequestreview-5899222221 Correction to my earlier review: I overstated the case against `DISALLOW_NEGATION`, sorry about that. It makes sense for options that are a maximum, limit, or timeout, where `-nofoo` reads as "no limit" but 0 means something very different. Ideally `-nofoo` might mean unlimited for these, but since negation has always meant 0, an error is the safest choice. I still think negation should generally behave like setting 0 or empty values, and if these values are invalid, better to check for them once than have multiple checks producing different errors. By that standard, about half of the uses here look right to me, and the rest aren't needed: - Make sense: `-dbbatchsize`, `-mempoolexpiry`, `-maxreceivebuffer`, `-maxsendbuffer`, `-maxtipage`, `-limitancestorcount`, `-limitdescendantcount`, `-datacarriersize`. - Not needed because the PR already rejects 0, so `-nofoo` would get that error: `-bantime`, `-timeout`, `-peertimeout`, `-limitclustercount`, `-limitclustersize`, `-txconfirmtarget`. - Not needed because 0 means what `-nofoo` says: `-bytespersigop`, where 0 turns off the sigop adjustment.
jlopp commented 2026-11-18 13:08:37 +00:00 (Migrated from github.com)

Updated negation support:

-bantime → Error: -bantime must be greater than 0 (got 0).
-timeout → Error: timeout must be a positive integer.
-peertimeout → Error: peertimeout must be a positive integer.
-limitclustercount → Error: limitclustercount must be between 1 and 64 (got 0)
-limitclustersize → Error: limitclustersize must be between 1 and 9223372036854775 kilobytes (got 0)
-txconfirmtarget → Error: -txconfirmtarget must be between 1 and 4294967295 (got 0).
-bytespersigop → accepts negation silently, since 0 means "no sigop adjustment"

Each is now validated in exactly one place, and -nofoo produces the identical message to -foo=0

Updated negation support: -bantime → Error: -bantime must be greater than 0 (got 0). -timeout → Error: timeout must be a positive integer. -peertimeout → Error: peertimeout must be a positive integer. -limitclustercount → Error: limitclustercount must be between 1 and 64 (got 0) -limitclustersize → Error: limitclustersize must be between 1 and 9223372036854775 kilobytes (got 0) -txconfirmtarget → Error: -txconfirmtarget must be between 1 and 4294967295 (got 0). -bytespersigop → accepts negation silently, since 0 means "no sigop adjustment" Each is now validated in exactly one place, and -nofoo produces the identical message to -foo=0
maflcko (Migrated from github.com) reviewed 2026-11-18 13:26:21 +00:00
maflcko (Migrated from github.com) commented 2026-11-18 13:26:21 +00:00

I know that parsing saturates, but I am not sure if it is the right fix to do manual parsing one-by-one at each call site.

This is adding tens of lines of code for what is basically a debug-only option. Also, it takes away the saturation "feature" here.

I think we'll have to decide:

  • Either we keep the saturation feature, and just use dumb parsing, or
  • we do proper validation, but then inside the argparser, to avoid re-inventing the wheel for every call site.

Maybe this can be done with a new Getter that takes an options object with the upper and lower bound and then it returns either nothing (if nothing was set), or the value (if it fits the range), or the error (if it doesn't fit the range, or so)?

I know that parsing saturates, but I am not sure if it is the right fix to do manual parsing one-by-one at each call site. This is adding tens of lines of code for what is basically a debug-only option. Also, it takes away the saturation "feature" here. I think we'll have to decide: * Either we keep the saturation feature, and just use dumb parsing, or * we do proper validation, but then inside the argparser, to avoid re-inventing the wheel for every call site. Maybe this can be done with a new Getter that takes an options object with the upper and lower bound and then it returns either nothing (if nothing was set), or the value (if it fits the range), or the error (if it doesn't fit the range, or so)?
ryanofsky (Migrated from github.com) approved these changes 2026-11-24 17:47:16 +00:00
ryanofsky (Migrated from github.com) left a comment

Code review ACK 9611ea5584. This makes numeric options that master silently accepts with nonsensical values (negative buffer sizes, ban times and confirmation targets, -timeout=0), or that crash the node (-limitclustercount=0), fail at startup with clear errors instead. I tried each changed option on regtest with valid, out-of-range and negated values, and they all behaved as described.

I still think these checks would be better in ArgsManager (https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4682944029), but the changes are an end-user improvement either way and I didn't see other significant problems.

Code review ACK 9611ea5584050b6decbeec528d5dfafabee6adbd. This makes numeric options that master silently accepts with nonsensical values (negative buffer sizes, ban times and confirmation targets, `-timeout=0`), or that crash the node (`-limitclustercount=0`), fail at startup with clear errors instead. I tried each changed option on regtest with valid, out-of-range and negated values, and they all behaved as described. I still think these checks would be better in ArgsManager (https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4682944029), but the changes are an end-user improvement either way and I didn't see other significant problems.
ryanofsky (Migrated from github.com) commented 2026-11-24 16:11:50 +00:00

re: https://github.com/bitcoin/bitcoin/pull/36861#issuecomment-6979485030

In commit "Configuration argument handling improvements." (9611ea5584)

Each is now validated in exactly one place, and -nofoo produces the identical message to -foo=0

Thanks, this looks right to me now. DISALLOW_NEGATION is used only for the limits where "no limit" and 0 mean different things, and the other options give the same error for -nofoo and -foo=0.

re: https://github.com/bitcoin/bitcoin/pull/36861#issuecomment-6979485030 In commit "Configuration argument handling improvements." (9611ea5584050b6decbeec528d5dfafabee6adbd) > Each is now validated in exactly one place, and -nofoo produces the identical message to -foo=0 Thanks, this looks right to me now. `DISALLOW_NEGATION` is used only for the limits where "no limit" and 0 mean different things, and the other options give the same error for `-nofoo` and `-foo=0`.
Lines 1177-1180
ryanofsky (Migrated from github.com) commented 2026-11-24 17:43:41 +00:00

In commit "Configuration argument handling improvements." (9611ea5584)

Could this add a release note? Some configurations that start on master will fail to start after this change, for example -timeout=0 (which currently falls back to the default), -bantime=0, -limitclustersize=0, and -txconfirmtarget=0 or above 1008 when a wallet is loaded. A short note listing the options that now reject out-of-range values would help anyone who hits one of the new errors after upgrading. The Ralph review suggested this too.

In commit "Configuration argument handling improvements." (9611ea5584050b6decbeec528d5dfafabee6adbd) Could this add a release note? Some configurations that start on master will fail to start after this change, for example `-timeout=0` (which currently falls back to the default), `-bantime=0`, `-limitclustersize=0`, and `-txconfirmtarget=0` or above 1008 when a wallet is loaded. A short note listing the options that now reject out-of-range values would help anyone who hits one of the new errors after upgrading. The [Ralph review](https://review.fish.foo/report/36861-aa8bfe2a137cceda68737c2874c5367f655dc5db-2656-1.html#finding-finding%3A5) suggested this too.
ryanofsky (Migrated from github.com) commented 2026-11-24 16:11:48 +00:00

re: https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4614637883

In commit "Configuration argument handling improvements." (9611ea5584)

we do proper validation, but then inside the argparser, to avoid re-inventing the wheel for every call site.

+1 for doing the validation in ArgsManager. Besides the extra code, doing it at each call site means options in this PR now parse numbers differently. For example, -limitclustercount=2.5 is an error, but -limitclustersize=2.5 is silently treated as 2, because GetIntArg ignores anything after the leading digits, while the ToIntegral call used for -limitclustercount rejects it. The error messages also vary ("-bantime must be...", "limitclustersize must be...", "timeout must be a positive integer.").

A getter like you describe could be something like:

//! Return nullopt if the option is not set, the value if it is an integer in
//! [min, max], or an error if it is not an integer or is out of range.
template <std::integral Int>
util::Result<std::optional<Int>> GetArg(const std::string& name, Int min, Int max) const;

That would make each call site one line and give every option the same parsing and error format. It would also fit #31260, which turns GetArg default arguments into compile-time setting declarations and could handle min and max arguments the same way.

re: https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4614637883 In commit "Configuration argument handling improvements." (9611ea5584050b6decbeec528d5dfafabee6adbd) > we do proper validation, but then inside the argparser, to avoid re-inventing the wheel for every call site. +1 for doing the validation in ArgsManager. Besides the extra code, doing it at each call site means options in this PR now parse numbers differently. For example, `-limitclustercount=2.5` is an error, but `-limitclustersize=2.5` is silently treated as 2, because `GetIntArg` [ignores](https://github.com/bitcoin/bitcoin/blob/9611ea5584050b6decbeec528d5dfafabee6adbd/src/util/strencodings.h#L130) anything after the leading digits, while the [`ToIntegral`](https://github.com/bitcoin/bitcoin/blob/9611ea5584050b6decbeec528d5dfafabee6adbd/src/util/strencodings.h#L184-L186) call used for `-limitclustercount` rejects it. The error messages also vary ("-bantime must be...", "limitclustersize must be...", "timeout must be a positive integer."). A getter like you describe could be something like: ```cpp //! Return nullopt if the option is not set, the value if it is an integer in //! [min, max], or an error if it is not an integer or is out of range. template <std::integral Int> util::Result<std::optional<Int>> GetArg(const std::string& name, Int min, Int max) const; ``` That would make each call site one line and give every option the same parsing and error format. It would also fit #31260, which turns `GetArg` default arguments into compile-time setting declarations and could handle min and max arguments the same way.
ryanofsky (Migrated from github.com) commented 2026-11-24 16:11:51 +00:00

In commit "Configuration argument handling improvements." (9611ea5584)

The commit message and PR description still say -limitclustersize=0 and -bantime=0 remain valid, but this code now rejects 0 for both (-bantime too), so they could move to the list with -limitclustercount and -timeout.

The same paragraph says 0 still means "disabled", but for several of these options 0 is the strictest setting rather than disabled: -maxsendbuffer=0 pauses sending whenever anything is queued, -maxtipage=0 keeps the node in IBD, and -mempoolexpiry=0 expires every transaction. It could just say that these options still accept 0. The Ralph review pointed this out too.

In commit "Configuration argument handling improvements." (9611ea5584050b6decbeec528d5dfafabee6adbd) The commit message and PR description still say `-limitclustersize=0` and `-bantime=0` remain valid, but this code now rejects 0 for both ([`-bantime`](https://github.com/bitcoin/bitcoin/blob/9611ea5584050b6decbeec528d5dfafabee6adbd/src/init.cpp#L1214-L1216) too), so they could move to the list with `-limitclustercount` and `-timeout`. The same paragraph says 0 still means "disabled", but for several of these options 0 is the strictest setting rather than disabled: `-maxsendbuffer=0` pauses sending whenever anything is queued, `-maxtipage=0` keeps the node in IBD, and `-mempoolexpiry=0` expires every transaction. It could just say that these options still accept 0. The [Ralph review](https://review.fish.foo/report/36861-aa8bfe2a137cceda68737c2874c5367f655dc5db-2656-1.html#finding-finding%3A6) pointed this out too.
ryanofsky (Migrated from github.com) commented 2026-11-24 16:11:53 +00:00

In commit "Configuration argument handling improvements." (9611ea5584)

I think this comment has the effect backwards. Expire() removes entries older than the cutoff, so a cutoff in the future would expire every transaction at the next check, not stop them from expiring. Maybe: "so a negative value would move the expiration cutoff into the future and expire every transaction." The Ralph review caught this.

In commit "Configuration argument handling improvements." (9611ea5584050b6decbeec528d5dfafabee6adbd) I think this comment has the effect backwards. [`Expire()`](https://github.com/bitcoin/bitcoin/blob/9611ea5584050b6decbeec528d5dfafabee6adbd/src/txmempool.cpp#L865) removes entries older than the cutoff, so a cutoff in the future would expire every transaction at the next check, not stop them from expiring. Maybe: "so a negative value would move the expiration cutoff into the future and expire every transaction." The [Ralph review](https://review.fish.foo/report/36861-9611ea5584050b6decbeec528d5dfafabee6adbd-2794-6.html#finding-finding%3A6) caught this.
maflcko (Migrated from github.com) reviewed 2026-11-24 18:38:23 +00:00
maflcko (Migrated from github.com) commented 2026-11-24 18:38:23 +00:00

That would make each call site one line

This may be true in Rust, but I don't think this is true in C++. Recall that the clang-format doesn't allow stuff like if (auto r = args.GetArg("-foo", 0, 100); !r) return util::Error{...}; else if (*r) opts.foo = **r;

Also, the alternative, where the result is assigned in the outer scope (before the if) is ugly and tedious, because the result will leak the scope after the if handling.

Finally, passing the min and max without named args will be confusing, when normally the second arg meant the default value. Also, having to redundantly pass the min/max when not needed seems redundant.

So the better option would be:

template <std::integral Int>
struct GetArgOptions {
    Int min{std::numeric_limits<Int>::min()};
    Int max{std::numeric_limits<Int>::max()};
};

template <std::integral Int>
std::optional<util::Result<Int>> GetArg(const std::string& name, GetArgOptions<Int> opts = {}) const;

This would result in code like:

    if (const auto foo = args.GetArg<u16>("-foo", {.max = 100})) {
        if (!*foo) return util::Error{util::ErrorString(*foo)};
        opts.foo = **foo;
// foo is not leaked outside this scope, nice
    }
> That would make each call site one line This may be true in Rust, but I don't think this is true in C++. Recall that the clang-format doesn't allow stuff like `if (auto r = args.GetArg("-foo", 0, 100); !r) return util::Error{...}; else if (*r) opts.foo = **r;` Also, the alternative, where the result is assigned in the outer scope (before the if) is ugly and tedious, because the result will leak the scope after the if handling. Finally, passing the min and max without named args will be confusing, when normally the second arg meant the default value. Also, having to redundantly pass the min/max when not needed seems redundant. So the better option would be: ```cpp template <std::integral Int> struct GetArgOptions { Int min{std::numeric_limits<Int>::min()}; Int max{std::numeric_limits<Int>::max()}; }; template <std::integral Int> std::optional<util::Result<Int>> GetArg(const std::string& name, GetArgOptions<Int> opts = {}) const; ``` This would result in code like: ```cpp if (const auto foo = args.GetArg<u16>("-foo", {.max = 100})) { if (!*foo) return util::Error{util::ErrorString(*foo)}; opts.foo = **foo; // foo is not leaked outside this scope, nice }
jlopp (Migrated from github.com) reviewed 2026-11-25 18:13:26 +00:00
Lines 1177-1180
jlopp (Migrated from github.com) commented 2026-11-25 18:13:26 +00:00

added release notes

added release notes
DrahtBot commented 2026-11-25 19:11:58 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/45672897049/job/139412907538
LLM reason (✨ experimental): CI failed the doc_release_note_snippets lint check because doc/release-notes-36861.md does not include its PR reference.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `lint`: https://github.com/bitcoin/bitcoin/actions/runs/45672897049/job/139412907538</sub> <sub>LLM reason (✨ experimental): CI failed the `doc_release_note_snippets` lint check because `doc/release-notes-36861.md` does not include its PR reference.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
ryanofsky (Migrated from github.com) approved these changes 2026-11-30 16:11:16 +00:00
ryanofsky (Migrated from github.com) left a comment

Code review ACK 830af36b82. This makes numeric options that master silently accepts with nonsensical values (negative buffer sizes, ban times and confirmation targets, -timeout=0), or that crash the node (-limitclustercount=0), fail at startup with clear errors instead.

Thanks for the release note and the clearer commit message! The remaining issues are small: the -mempoolexpiry bound still lets absurdly large values overflow when the mempool is loaded (https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4740978823), and the release note and commit message still describe 0 as "disabled" for options where it is the strictest setting (https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4740978085), and the release note could be much shorter (https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4741659479). I also still think these checks would be better in ArgsManager, and maflcko's options struct looks like a good way to do it (https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4740978473).

Code review ACK 830af36b820d3e4f331d34023aef44e3f687d927. This makes numeric options that master silently accepts with nonsensical values (negative buffer sizes, ban times and confirmation targets, `-timeout=0`), or that crash the node (`-limitclustercount=0`), fail at startup with clear errors instead. Thanks for the release note and the clearer commit message! The remaining issues are small: the `-mempoolexpiry` bound still lets absurdly large values overflow when the mempool is loaded (https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4740978823), and the release note and commit message still describe 0 as "disabled" for options where it is the strictest setting (https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4740978085), and the release note could be much shorter (https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4741659479). I also still think these checks would be better in ArgsManager, and maflcko's options struct looks like a good way to do it (https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4740978473).
Lines 1180-1183
ryanofsky (Migrated from github.com) commented 2026-11-30 15:50:20 +00:00

re: https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4699000436

In commit "init: reject invalid numeric configuration values" (830af36b82)

added release notes

Thanks! I think the note could be much shorter, though. Readers mainly need to know which options changed and roughly how, and -help already gives most of the accepted ranges, so the maximum values and per-option explanations could go. For example:

Updated settings
----------------

- Some numeric options now reject out-of-range values at startup instead of
  silently wrapping, falling back to the default, or crashing, so configurations
  that started on earlier releases may fail to start. See `bitcoind -help` for
  the accepted values. (#36861)
  - `-bantime`, `-timeout`, `-limitclustercount`, `-limitclustersize` and
    `-txconfirmtarget` reject 0 and negative values. When a wallet is loaded,
    `-txconfirmtarget` is also limited to the largest target the fee estimator
    tracks.
  - `-bytespersigop`, `-datacarriersize`, `-dbbatchsize`, `-dbcrashratio`,
    `-limitancestorcount`, `-limitdescendantcount`, `-maxreceivebuffer`,
    `-maxsendbuffer`, `-maxtipage` and `-mempoolexpiry` reject negative values,
    and most also reject values too large to store.
  - Negating `-datacarriersize`, `-dbbatchsize`, `-limitancestorcount`,
    `-limitdescendantcount`, `-maxreceivebuffer`, `-maxsendbuffer`, `-maxtipage`
    or `-mempoolexpiry` is now an error, because `-nofoo` sets these to 0, which
    doesn't mean "no limit".
  - `-dbbatchsize`, `-dbcrashratio`, `-limitclustercount` and `-maxtipage` reject
    values with trailing characters, such as `-maxtipage=1h`.

The one detail -help doesn't cover is the new -txconfirmtarget limit when a wallet is loaded, so it would be good to mention it in that option's help text too.

re: https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4699000436 In commit "init: reject invalid numeric configuration values" (830af36b820d3e4f331d34023aef44e3f687d927) > added release notes Thanks! I think the note could be much shorter, though. Readers mainly need to know which options changed and roughly how, and `-help` already gives most of the accepted ranges, so the maximum values and per-option explanations could go. For example: ```markdown Updated settings ---------------- - Some numeric options now reject out-of-range values at startup instead of silently wrapping, falling back to the default, or crashing, so configurations that started on earlier releases may fail to start. See `bitcoind -help` for the accepted values. (#36861) - `-bantime`, `-timeout`, `-limitclustercount`, `-limitclustersize` and `-txconfirmtarget` reject 0 and negative values. When a wallet is loaded, `-txconfirmtarget` is also limited to the largest target the fee estimator tracks. - `-bytespersigop`, `-datacarriersize`, `-dbbatchsize`, `-dbcrashratio`, `-limitancestorcount`, `-limitdescendantcount`, `-maxreceivebuffer`, `-maxsendbuffer`, `-maxtipage` and `-mempoolexpiry` reject negative values, and most also reject values too large to store. - Negating `-datacarriersize`, `-dbbatchsize`, `-limitancestorcount`, `-limitdescendantcount`, `-maxreceivebuffer`, `-maxsendbuffer`, `-maxtipage` or `-mempoolexpiry` is now an error, because `-nofoo` sets these to 0, which doesn't mean "no limit". - `-dbbatchsize`, `-dbcrashratio`, `-limitclustercount` and `-maxtipage` reject values with trailing characters, such as `-maxtipage=1h`. ``` The one detail `-help` doesn't cover is the new `-txconfirmtarget` limit when a wallet is loaded, so it would be good to mention it in that option's help text too.
ryanofsky (Migrated from github.com) commented 2026-11-30 16:06:43 +00:00

In commit "init: reject invalid numeric configuration values" (830af36b82)

Many of the new upper limits are much larger than any value that makes sense, since they only stop the value from wrapping. This one allows about 4 GB per connection, against defaults of 1 MB and 5 MB, so a typo like an extra few zeros would still be accepted. Since this PR adds range checks anyway, it might be better to pick limits that catch user errors now, because tightening them later would break configurations this release accepts. With maflcko's options struct, they would fit naturally in .min and .max.

In commit "init: reject invalid numeric configuration values" (830af36b820d3e4f331d34023aef44e3f687d927) Many of the new upper limits are much larger than any value that makes sense, since they only stop the value from wrapping. This one allows about 4 GB per connection, against defaults of 1 MB and 5 MB, so a typo like an extra few zeros would still be accepted. Since this PR adds range checks anyway, it might be better to pick limits that catch user errors now, because tightening them later would break configurations this release accepts. With maflcko's options struct, they would fit naturally in `.min` and `.max`.
ryanofsky (Migrated from github.com) commented 2026-11-30 15:00:37 +00:00

re: https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4684786604

passing the min and max without named args will be confusing, when normally the second arg meant the default value

Good points, and I agree the options struct is better. I was wrong that each call site would be one line, but your version still keeps each range check in one place with one error format, and returning std::optional<util::Result<Int>> keeps the result scoped to the if. It would also fit #31260, whose setting declarations already take options as designated initializers ({.legacy = true}), so .min and .max could be added there the same way.

One small thought: putting util::Result on the outside would make the error check the one callers can't skip, while with std::optional outside, forgetting the inner check only shows up as an assert when someone passes a bad value.

re: https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4684786604 > passing the min and max without named args will be confusing, when normally the second arg meant the default value Good points, and I agree the options struct is better. I was wrong that each call site would be one line, but your version still keeps each range check in one place with one error format, and returning `std::optional<util::Result<Int>>` keeps the result scoped to the `if`. It would also fit #31260, whose setting declarations already take options as designated initializers (`{.legacy = true}`), so `.min` and `.max` could be added there the same way. One small thought: putting `util::Result` on the outside would make the error check the one callers can't skip, while with `std::optional` outside, forgetting the inner check only shows up as an assert when someone passes a bad value.
ryanofsky (Migrated from github.com) commented 2026-11-30 15:00:35 +00:00

re: https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4682944850

In commit "init: reject invalid numeric configuration values" (830af36b82)

Thanks, -limitclustersize and -bantime are in the right place now. But the commit message still says 0 "already meant 'disabled'" for the options that accept it, and the new release note says 0 "keeps its existing meaning of 'disabled' or 'unlimited'". For several of these options 0 is the strictest setting instead: -maxsendbuffer=0 pauses sending whenever anything is queued, -maxtipage=0 keeps the node in IBD, and -mempoolexpiry=0 expires every transaction. This also contradicts the paragraph after it, which says that for these options 0 "means something very different from 'no limit'". The release note heading could just say:

Options that still accept zero, but now reject negative and oversized values:

and the commit message could say "Zero remains valid for ...". Similarly, the release note's negation paragraph says -nofoo used to be "quietly turning the limit off", but since negation is read as 0, it set these limits to 0 rather than turning them off. The Ralph review flagged this too.

re: https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4682944850 In commit "init: reject invalid numeric configuration values" (830af36b820d3e4f331d34023aef44e3f687d927) Thanks, `-limitclustersize` and `-bantime` are in the right place now. But the commit message still says 0 "already meant 'disabled'" for the options that accept it, and the new release note says 0 "keeps its existing meaning of 'disabled' or 'unlimited'". For several of these options 0 is the strictest setting instead: `-maxsendbuffer=0` pauses sending whenever anything is queued, `-maxtipage=0` keeps the node in IBD, and `-mempoolexpiry=0` expires every transaction. This also contradicts the paragraph after it, which says that for these options 0 "means something very different from 'no limit'". The release note heading could just say: > Options that still accept zero, but now reject negative and oversized values: and the commit message could say "Zero remains valid for ...". Similarly, the release note's negation paragraph says `-nofoo` used to be "quietly turning the limit off", but since negation is read as 0, it set these limits to 0 rather than turning them off. The [Ralph review](https://review.fish.foo/report/36861-830af36b820d3e4f331d34023aef44e3f687d927-3195-11.html#finding-finding%3A1) flagged this too.
ryanofsky (Migrated from github.com) commented 2026-11-30 15:00:39 +00:00

In commit "init: reject invalid numeric configuration values" (830af36b82)

I think this bound is still too high. LoadMempool() subtracts the expiry from NodeClock::now(), which converts it to NodeClock::duration (nanoseconds with libstdc++), so an expiry above about 2.5 million hours (292 years) overflows there. These are absurd values, but this is the check meant to prevent that. I tried it on a debug build: with a transaction in mempool.dat, -mempoolexpiry=3000000 passes this check and the node then crashes at startup on the overflow trap, while -mempoolexpiry=2000000 loads fine. Taking the bound from the clock's duration fixed it:

// LoadMempool() subtracts the expiry from NodeClock::now(), which converts
// it to NodeClock::duration, so the bound has to come from that type.
constexpr int64_t MAX_EXPIRY_HOURS{std::chrono::duration_cast<std::chrono::seconds>(NodeClock::duration::max()).count() / SECONDS_PER_HOUR};

That makes the maximum 2562047 hours on Linux, so the release note and the tests that use the current maximum would need updating. The Ralph review found this too.

In commit "init: reject invalid numeric configuration values" (830af36b820d3e4f331d34023aef44e3f687d927) I think this bound is still too high. [`LoadMempool()`](https://github.com/bitcoin/bitcoin/blob/830af36b820d3e4f331d34023aef44e3f687d927/src/node/mempool_persist.cpp#L103) subtracts the expiry from `NodeClock::now()`, which converts it to `NodeClock::duration` (nanoseconds with libstdc++), so an expiry above about 2.5 million hours (292 years) overflows there. These are absurd values, but this is the check meant to prevent that. I tried it on a debug build: with a transaction in `mempool.dat`, `-mempoolexpiry=3000000` passes this check and the node then crashes at startup on the overflow trap, while `-mempoolexpiry=2000000` loads fine. Taking the bound from the clock's duration fixed it: ```cpp // LoadMempool() subtracts the expiry from NodeClock::now(), which converts // it to NodeClock::duration, so the bound has to come from that type. constexpr int64_t MAX_EXPIRY_HOURS{std::chrono::duration_cast<std::chrono::seconds>(NodeClock::duration::max()).count() / SECONDS_PER_HOUR}; ``` That makes the maximum 2562047 hours on Linux, so the release note and the tests that use the current maximum would need updating. The [Ralph review](https://review.fish.foo/report/36861-0b33a8cca3815c7592277abb6acd6c7ea5ef85a0-3160-10.html#finding-finding%3A2) found this too.
maflcko (Migrated from github.com) reviewed 2026-11-30 17:00:12 +00:00
maflcko (Migrated from github.com) commented 2026-11-30 17:00:12 +00:00

forgetting the inner check only shows up as an assert when someone passes a bad value.

That's a good point, but I wouldn't worry too much about it. If reviewers really forget it, I presume LLMs are good at finding this, also there could be a clang-tidy check for this, if needed.

> forgetting the inner check only shows up as an assert when someone passes a bad value. That's a good point, but I wouldn't worry too much about it. If reviewers really forget it, I presume LLMs are good at finding this, also there could be a clang-tidy check for this, if needed.
jlopp (Migrated from github.com) reviewed 2026-12-01 16:59:49 +00:00
jlopp (Migrated from github.com) commented 2026-12-01 16:59:49 +00:00

Wouldn't this cause the config values to be platform-dependent since std::chrono::system_clock::duration is ns with libstdc++, µs with libc++ on macOS, and 100 ns with MSVC, giving 2562047 / 2562047788 / 25620477880 hours respectively?

Wouldn't this cause the config values to be platform-dependent since std::chrono::system_clock::duration is ns with libstdc++, µs with libc++ on macOS, and 100 ns with MSVC, giving 2562047 / 2562047788 / 25620477880 hours respectively?
maflcko (Migrated from github.com) reviewed 2026-12-01 17:35:45 +00:00
maflcko (Migrated from github.com) commented 2026-12-01 17:35:45 +00:00

Right, I don't think we want platform-dependent caps here. This makes testing tedious for no benefit. All of those are absurd values anyway, so I think just using 1year is fine, or 5 years, or 2562047hours, if this needs to be "exact".

edit: For reference, other code is also just using an arbitrary upper limit:

src/node/block_template_manager.cpp:234:    if (timeout > std::chrono::years{100}) timeout = std::chrono::years{100}; // Upper bound to avoid UB in std::chrono
src/wallet/rpc/encrypt.cpp:64:        // Clamp timeout to ~3 years to avoid overflow when computing the relock time
Right, I don't think we want platform-dependent caps here. This makes testing tedious for no benefit. All of those are absurd values anyway, so I think just using 1year is fine, or 5 years, or 2562047hours, if this needs to be "exact". edit: For reference, other code is also just using an arbitrary upper limit: ``` src/node/block_template_manager.cpp:234: if (timeout > std::chrono::years{100}) timeout = std::chrono::years{100}; // Upper bound to avoid UB in std::chrono src/wallet/rpc/encrypt.cpp:64: // Clamp timeout to ~3 years to avoid overflow when computing the relock time
ryanofsky (Migrated from github.com) approved these changes 2026-12-03 19:21:02 +00:00
ryanofsky (Migrated from github.com) commented 2026-12-03 19:19:25 +00:00

re: https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4758268700

Wouldn't this cause the config values to be platform-dependent

Good catch, you're right: NodeClock uses system_clock's duration, so my suggestion would make the limit and the error message vary by platform. A fixed cap like maflcko suggests is better. Anything up to 2562047 hours avoids the overflow on all three platforms, and a smaller one like a few years would also catch typos, as in my other comment about right-sizing these limits.

re: https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4758268700 > Wouldn't this cause the config values to be platform-dependent Good catch, you're right: `NodeClock` uses `system_clock`'s duration, so my suggestion would make the limit and the error message vary by platform. A fixed cap like maflcko suggests is better. Anything up to 2562047 hours avoids the overflow on all three platforms, and a smaller one like a few years would also catch typos, as in my [other comment](https://github.com/bitcoin/bitcoin/pull/36861#discussion_r4741893532) about right-sizing these limits.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36861
No description provided.