Skip to content

cli: Parse -signetchallenge like bitcoind - #36689

Open
ekzyis wants to merge 2 commits into
bitcoin:masterfrom
ekzyis:bitcoin-cli-signetchallenge-validation
Open

ekzyis wants to merge 2 commits into
bitcoin:masterfrom
ekzyis:bitcoin-cli-signetchallenge-validation

Conversation

@ekzyis

@ekzyis ekzyis commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

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 #34566 (comment)

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

@DrahtBot

DrahtBot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

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.

@ekzyis ekzyis changed the title Bitcoin cli signetchallenge validation cli: Parse -signetchallenge like bitcoind Oct 28, 2026
@ValeraFinebits

Copy link
Copy Markdown

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
ekzyis force-pushed the bitcoin-cli-signetchallenge-validation branch from 3f178e0 to cb7bb77 Compare October 29, 2026 18:38
@ekzyis

ekzyis commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

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 cb7bb77, as you suggested.

Comment thread test/functional/feature_signet.py Resolved
@Sjors

Sjors commented Oct 30, 2026

Copy link
Copy Markdown
Member

Concept ACK

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

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

@ekzyis
ekzyis force-pushed the bitcoin-cli-signetchallenge-validation branch from cb7bb77 to 54fe0ec Compare October 30, 2026 15:20
@ekzyis

ekzyis commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

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

Footnotes

  1. I also prefer Signet but I think I should have favoured consistency in feature: Use different datadirs for different signets #34566 instead of introducing Signet over SigNet ↩

We parse and validate -signetchallenge in two places: GetSignetDataDir()
and ReadSigNetArgs().

To have consistent behavior between bitcoind and bitcoin-cli, we extract
the code for -signetchallenge in ReadSigNetArgs() into a helper function
ReadSignetChallengeArg() which can be reused in GetSignetDataDir() in
the next commit.
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 with ReadSignetChallengeArg()
in GetSignetDataDir() and add tests.
@ekzyis
ekzyis force-pushed the bitcoin-cli-signetchallenge-validation branch from 54fe0ec to 28c2561 Compare November 21, 2026 22:40
@ekzyis

ekzyis commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

28c2561: rebased on master (442b152)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants