Skip to content

rpc generate: print useful help and error message #19455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 14, 2020

Conversation

jonatack
Copy link
Member

@jonatack jonatack commented Jul 6, 2020

This was a requested follow-up to #19133 and #17700 to alleviate confusion and head-scratching by people following tutorials that use generate. See #19455 (comment) below, #19133 (comment) and #17700 (comment).

before

$ bitcoin-cli help generate
help: unknown command: generate

$ bitcoin-cli generate
error code: -32601
error message:
Method not found

after

$ bitcoin-cli help generate
generate ( nblocks maxtries ) has been replaced by the -generate cli option. Refer to -help for more information.

$ bitcoin-cli generate
error code: -32601
error message:
generate ( nblocks maxtries ) has been replaced by the -generate cli option. Refer to -help for more information.

In the general help it remains hidden, as requested by laanwj.

$ bitcoin-cli help

== Generating ==
generateblock "output" ["rawtx/txid",...]
generatetoaddress nblocks "address" ( maxtries )
generatetodescriptor num_blocks "descriptor" ( maxtries )

@jonatack
Copy link
Member Author

jonatack commented Jul 6, 2020

Tagging @adamjonas and @MarcoFalke who suggested this feature.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 6, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

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.

@adamjonas
Copy link
Member

Concept ACK. Thanks for circling back on this.

When looking at the help options (bitcoin-cli -regtest help), this explanation looks out of place. I'd suggest rewording to at least start with the word generate to keep it alphabetical and consistent.

Screen Shot 2020-07-06 at 7 51 59 PM

@jonatack jonatack force-pushed the rpc-generate-helpful-error_message branch from 260b7c2 to 210873d Compare July 7, 2020 03:53
@jonatack
Copy link
Member Author

jonatack commented Jul 7, 2020

When looking at the help options (bitcoin-cli -regtest help), this explanation looks out of place. I'd suggest rewording to at least start with the word generate to keep it alphabetical and consistent.

Thanks Jonas! Good point -- updated.

EDIT: per review feedback below, changed it to a hidden RPC command, which won't shown up in the general help.

@jonatack jonatack force-pushed the rpc-generate-helpful-error_message branch 5 times, most recently from 8804531 to 68fe377 Compare July 7, 2020 11:04
@laanwj
Copy link
Member

laanwj commented Jul 9, 2020

I'm not sure on this. On one hand this is useful, on the other hand we did remove the similar message for getinfo a long time ago in b2f23c4. generate, though shorter ago, was removed more than a year ago (in 8bb3e4c), so it seems to be a bit late to add this.
But no strong opposition.

@jonatack jonatack force-pushed the rpc-generate-helpful-error_message branch from 68fe377 to 14e2a82 Compare July 9, 2020 15:30
@jonatack
Copy link
Member Author

No ACKs. Closing.

@jonatack jonatack closed this Jul 23, 2020
@adamjonas
Copy link
Member

adamjonas commented Aug 3, 2020

This is my fault for the slow review, but I still think it's a useful addition to reduce confusion for all the outdated tutorials out there [1, 2, 3, 4].

tACK f0aa8ae

Tried help generate, which returns a helpful prompt:

$ bitcoin-cli help generate
generate ( nblocks maxtries ) has been replaced by the -generate cli option. Refer to -help for more information.

This is much more instructive than the method not found error.

$ bitcoin-cli generate
error code: -32601
error message:
generate ( nblocks maxtries ) has been replaced by the -generate cli option. Refer to -help for more information.

And verified that it is a hidden RPC command
Screen Shot 2020-08-03 at 2 15 02 PM

I'm still an advocate for including this for the poor, unfortunate souls out there just trying to get started on regtest.

@jonatack
Copy link
Member Author

jonatack commented Aug 4, 2020

Thanks for the review @adamjonas. Re-opening to see if this gets traction.

@jonatack jonatack reopened this Aug 4, 2020
@kallewoof
Copy link
Contributor

Concept / code review ACK. LGTM

No strong opinion, but an alternative might be to PR an update on those outdated docs, and/or ping the respective authors. Perhaps both; ping and merge.

@jonatack
Copy link
Member Author

Thanks @adamjonas and @kallewoof ❤️

Good idea; I notified on the bitcoin.org github a couple months ago that generate is back as a cli option, though following up on all the tuturials would be helpful for people.

If the maintainers agree on this change, ISTM the 2 ACKs and the test coverage here may enough to merge this no-risk user-facing aid.

Comment on lines +719 to +721
# Consider RPC generate covered, because it is overloaded in
# test_framework/test_node.py and not seen by the coverage check.
covered_cmds = set({'generate'})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand this. generate is not returned by help and so I don't think its even added to the coverage list:

help_output = node.help().split('\n')

Both with and without this change, my coverage results were the same:

Uncovered RPC commands:
  - pruneblockchain

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pinheadmz Yes, it's a hidden command (not in the help, see the added test) as suggested by @laanwj. IIRC this was needed to appease a failing check in the Travis CI that despite the added test it thought there was no coverage.

@pinheadmz
Copy link
Member

pinheadmz commented Aug 12, 2020

Concept ACK

Built and tested locally, all behavior is as expected trying different combinations:

src/bitcoin-cli -regtest -generate
src/bitcoin-cli -regtest generate
src/bitcoin-cli -regtest help generate
src/bitcoin-cli -regtest help -generate
src/bitcoin-cli -regtest -help -generate

Only thing that caught me as far as interface is the fact that there is help and -help. The extra help menu is a bit of an easter egg? But that's out of scope for this PR I think.

@laanwj
Copy link
Member

laanwj commented Aug 12, 2020

Only thing that caught me as far as interface is the fact that there is help and -help. The extra help menu is a bit of an easter egg? But that's out of scope for this PR I think.

They are principally different on purpose. Like for any UNIX-ish application, -help or --help shows the help message for the local binary. This includes the different options how to connect to the server.

On the other hand, help is a command for the remote server. It shows the help for the specific RPC server it connects to, and fails if there is none.

Copy link
Member

@pinheadmz pinheadmz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK f0aa8ae

Thanks for your answers to my questions @jonatack and @laanwj

Show Signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

ACK f0aa8aeea5a183ea44a877255d12db7732f2e0a8
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAl80EaUACgkQ5+KYS2KJ
yTrkBw//dEwEnhDeko2ScTnzl/4mZSJLR0KG4D//BhWq+bhsSKKslWUQDMdJDYE/
HljPiuButxN01vJOVowqYV6ZGIPEVLiILu/R7OYkU81KLUPtZwsaouT9b0/8opmZ
/uXysTqvUa9UUfrk01vxkU63+viAQdpe5WBaf6dURdBjodRdoxL41r60GhMlacoe
wS75MuzR+pojiyr/Wf9s+t2BKDVO79rhoClhdOo9xiud4kqomdpmyQh2/86T5moe
LgTOjufZGAl/0haI1EAlWmtw0+AjMl6hRnrVUcgblElOJ201HZoE2Qj0L8bkykU1
I890Cu28PFWFeeK6xX3ev/ja6v2iLzrq1VsKmH1WRkEYaOkL8GvH4MJHwuQSlsFS
/h+dxMFjPvmigZMQTuaHDtDrsRGLqMTd6WEYoIC/NKRK+7UjgpGjzSiiRBS4g7iB
pVTTpei9/zjvXwlvr427+ji1kbWt2YKQdqrDeMIHHc5gcsFY9E1vgSKDw94TjVyt
YwOHlYG+ezhULsxNbW/D40ox1veFDkK/I0DkHN0AcUP7RuKTTdAiZ4B6+Fturk0f
3eFNIxf3qilCy5LPfRBcqtQ8GkpVgvcDpsO83cEeffyTIxrtRrPDULRc0upI81Jd
mi6DrhAultLW1xFvAjB8EBTTEVrdg9doVD5vMqHM+CFGm+wnyvM=
=wdk/
-----END PGP SIGNATURE-----

pinheadmz's public key is on keybase

@jonatack
Copy link
Member Author

Thanks @pinheadmz!

@laanwj laanwj merged commit dabab06 into bitcoin:master Aug 14, 2020
@jonatack jonatack deleted the rpc-generate-helpful-error_message branch August 14, 2020 09:32
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 16, 2020
f0aa8ae test: add rpc_generate functional test (Jon Atack)
92d94ff rpc: print useful help and error message for generate (Jon Atack)
8d32d20 test: consider generate covered in _get_uncovered_rpc_commands() (Jon Atack)

Pull request description:

  This was a requested follow-up to bitcoin#19133 and bitcoin#17700 to alleviate confusion and head-scratching by people following tutorials that use `generate`. See bitcoin#19455 (comment) below, bitcoin#19133 (comment) and bitcoin#17700 (comment).

  before
  ```
  $ bitcoin-cli help generate
  help: unknown command: generate

  $ bitcoin-cli generate
  error code: -32601
  error message:
  Method not found
  ```

  after
  ```
  $ bitcoin-cli help generate
  generate ( nblocks maxtries ) has been replaced by the -generate cli option. Refer to -help for more information.

  $ bitcoin-cli generate
  error code: -32601
  error message:
  generate ( nblocks maxtries ) has been replaced by the -generate cli option. Refer to -help for more information.
  ```

  In the general help it remains hidden, as requested by laanwj.
  ```
  $ bitcoin-cli help

  == Generating ==
  generateblock "output" ["rawtx/txid",...]
  generatetoaddress nblocks "address" ( maxtries )
  generatetodescriptor num_blocks "descriptor" ( maxtries )
  ```

ACKs for top commit:
  adamjonas:
    utACK f0aa8ae
  pinheadmz:
    ACK f0aa8ae

Tree-SHA512: d083652589ad3e8228c733455245001db22397559c3946e7e573cf9bd01c46e9e88b72d934728ec7f4361436ae4c74adb8f579670b09f479011924357e729af5
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 14, 2021
Summary:
PR rationale:
> This was a requested follow-up to #19133 and #17700 to alleviate confusion and head-scratching by people following tutorials that use `generate`.

> test: consider generate covered in _get_uncovered_rpc_commands()

> rpc: print useful help and error message for generate

> test: add rpc_generate functional test

This is a backport of [[ bitcoin/bitcoin#19455 | core#19455 ]]

Test Plan:

`ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10091
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants