cli: Parse -signetchallenge like bitcoind #36689

Open
ekzyis wants to merge 2 commits from bitcoin-cli-signetchallenge-validation into master AGit
ekzyis commented 2026-10-28 19:14:59 +00:00 (Migrated from github.com)

bitcoind returns an useful error when invalid hex is passed to -signetchallenge:

$ bitcoind -signet -signetchallenge=z
Error: -signetchallenge must be hex, not 'z'

The error returned by bitcoin-cli only indicates that the RPC cookie wasn't found. It doesn't hint at invalid hex:

$ bitcoin-cli -signet -signetchallenge=z getblockcount
error: Authorization failed: ...
Is your -signetchallenge correct for custom signets?

To have consistent validation of signet args in bitcoind and bitcoin-cli, we now parse -signetchallenge in a new ReadSignetChallengeArg() function which is called in GetSignetDataDir() and ReadSigNetArgs().

Addresses https://github.com/bitcoin/bitcoin/pull/34566#discussion_r3668123074

I didn't add a release note because I don't think this change of an error message warrants one.

`bitcoind` returns an useful error when invalid hex is passed to `-signetchallenge`: ``` $ bitcoind -signet -signetchallenge=z Error: -signetchallenge must be hex, not 'z' ``` The error returned by `bitcoin-cli` only indicates that the RPC cookie wasn't found. It doesn't hint at invalid hex: ``` $ bitcoin-cli -signet -signetchallenge=z getblockcount error: Authorization failed: ... Is your -signetchallenge correct for custom signets? ``` To have consistent validation of signet args in `bitcoind` and `bitcoin-cli`, we now parse `-signetchallenge` in a new `ReadSignetChallengeArg()` function which is called in `GetSignetDataDir()` and `ReadSigNetArgs()`. Addresses https://github.com/bitcoin/bitcoin/pull/34566#discussion_r3668123074 I didn't add a release note because I don't think this change of an error message warrants one.
DrahtBot commented 2026-10-28 19:15:12 +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
Concept ACK Sjors

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

Conflicts

No conflicts as of last run.

<!--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/36689 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36689.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36689#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 | | ---- | --------- | | Concept ACK | [Sjors](https://github.com/bitcoin/bitcoin/pull/36689#issuecomment-6518273655) | 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 No conflicts as of last run. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: 28c2561c9c10 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:3705f06c6a27c475c77f2533c4d016ac03c829c839b7b538bba5e4768ccf54f1:1ed10c4979af6fc548d6b8d4534d505e02e84ac4b0aa4f8633555b2ba75119e8 --> <!-- ralph-base:19128e8b77553e4362fcbf3cb8f3f7dc5a2e4253 --> <!-- ralph-head:28c2561c9c102cf95ddf19b836f0add46ce38a7a --> <!-- ralph-case:066a5ede678a4d3bd5790e056f32aa6ec0b1af0802bd189599e8a42b2fbf89b4 --> No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: standard --> --- Reviewed: [`28c2561c9c10`](<https://git.fish.foo/bitcoin/bitcoin/commit/28c2561c9c102cf95ddf19b836f0add46ce38a7a>) · [Review report](<https://review.fish.foo/report/36689-28c2561c9c102cf95ddf19b836f0add46ce38a7a-2930-6.html>) · [Previous reports](<https://review.fish.foo/traces/36689/>) [permalink](<https://review.fish.foo/report/36689-28c2561c9c102cf95ddf19b836f0add46ce38a7a-2930-6.html>)
ValeraFinebits commented 2026-10-29 16:58:27 +00:00 (Migrated from github.com)

Optional test suggestion: set signetchallenge=51 in the [signet] config section and also pass -signetchallenge=51 on the command line, then assert the multiple-values error.

This would cover the GetArg() -> GetArgs() change across configuration sources, using valid, identical values. Running this case with RPC unavailable would also verify that the diagnostic does not depend on a running node.

Optional test suggestion: set `signetchallenge=51` in the `[signet]` config section and also pass `-signetchallenge=51` on the command line, then assert the multiple-values error. This would cover the `GetArg()` -> `GetArgs()` change across configuration sources, using valid, identical values. Running this case with RPC unavailable would also verify that the diagnostic does not depend on a running node.
ekzyis commented 2026-10-29 18:41:40 +00:00 (Migrated from github.com)

Optional test suggestion: set signetchallenge=51 in the [signet] config section and also pass -signetchallenge=51 on the command line, then assert the multiple-values error.

This would cover the GetArg() -> GetArgs() change across configuration sources, using valid, identical values. Running this case with RPC unavailable would also verify that the diagnostic does not depend on a running node.

Thanks! I replaced the CLI test which passes the same invalid value twice (-signetchallenge=abc) with a test that uses signetchallenge=51 from the config and passes the same valid value (-signetchallenge=51) in cb7bb77a10, as you suggested.

> Optional test suggestion: set `signetchallenge=51` in the `[signet]` config section and also pass `-signetchallenge=51` on the command line, then assert the multiple-values error. > > This would cover the `GetArg()` -> `GetArgs()` change across configuration sources, using valid, identical values. Running this case with RPC unavailable would also verify that the diagnostic does not depend on a running node. Thanks! I replaced the CLI test which passes the same invalid value twice (`-signetchallenge=abc`) with a test that uses `signetchallenge=51` from the config and passes the same valid value (`-signetchallenge=51`) in cb7bb77a10, as you suggested.
ekzyis (Migrated from github.com) reviewed 2026-10-29 19:05:50 +00:00
ekzyis (Migrated from github.com) commented 2026-10-29 19:05:51 +00:00

I checked if we're using patterns like here which could be refactored with context managers, but there's only one similar case I've found at interface_bitcoin_cli.py:205 where we comment out rpcport in the config before running some tests and restoring it.

In the other cases, we're either restarting the node with the new changes (so undo is undesired) or node.replace_in_config() is more ergonomic.

So in case someone has more context than me to still consider this a good idea: This and similar patterns could be refactored with a context manager like this:

with extra_config(node, "signetchallenge=51"):
    assert_raises_process_error(1, "-signetchallenge cannot be multiple values.", node.cli("-signetchallenge=51").getblockcount)
I checked if we're using patterns like here which could be refactored with context managers, but there's only one similar case I've found at interface_bitcoin_cli.py:205 where we comment out `rpcport` in the config before running some tests and restoring it. In the other cases, we're either restarting the node with the new changes (so undo is undesired) or `node.replace_in_config()` is more ergonomic. So in case someone has more context than me to still consider this a good idea: This and similar patterns could be refactored with a context manager like this: ```python with extra_config(node, "signetchallenge=51"): assert_raises_process_error(1, "-signetchallenge cannot be multiple values.", node.cli("-signetchallenge=51").getblockcount) ```
Sjors commented 2026-10-30 08:14:40 +00:00 (Migrated from github.com)

Concept ACK

Consider splitting cb7bb77a10 into a pure refactor to extract the helper(s) you need, followed by the change itself.

I suggest dropping the rename in 38998ad410. It's going to invite bike-shedding (and personally I prefer Signet over SigNet).

Concept ACK Consider splitting cb7bb77a10fbccc16b90310a25d3f9f2d348bf9f into a pure refactor to extract the helper(s) you need, followed by the change itself. I suggest dropping the rename in 38998ad4104b1dca4db4dd039b0ddb5e7ea766fe. It's going to invite bike-shedding (and personally I prefer Signet over SigNet).
ekzyis commented 2026-10-30 15:28:03 +00:00 (Migrated from github.com)

Dropped the rename.1 23a88a4 now introduces ReadSignetChallengeArg() and 54fe0ec then uses it in ReadSignetDataDir() with tests. Updated commit messages accordingly.


  1. I also prefer Signet but I think I should have favoured consistency in #34566 instead of introducing Signet over SigNet ↩︎

Dropped the rename.[^1] 23a88a4 now introduces `ReadSignetChallengeArg()` and 54fe0ec then uses it in `ReadSignetDataDir()` with tests. Updated commit messages accordingly. [^1]: I also prefer Signet but I think I should have favoured consistency in #34566 instead of introducing Signet over SigNet
DrahtBot commented 2026-11-20 22:39:23 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
ekzyis commented 2026-11-21 22:43:51 +00:00 (Migrated from github.com)

28c2561c9c: rebased on master (442b152c8b)

Only conflict was in chainparamsbase.cpp: include <cassert> was replaced with include <util/check.h>.

28c2561c9c: rebased on master (442b152c8b) Only conflict was in chainparamsbase.cpp: `include <cassert>` was replaced with `include <util/check.h>`.
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!36689
No description provided.