Skip to content
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

JSONRPCRequest-aware RPCHelpMan #16240

Merged
merged 4 commits into from
Jul 9, 2019

Conversation

kallewoof
Copy link
Contributor

@kallewoof kallewoof commented Jun 19, 2019

Every single RPC call has a helper-section at the start, which throws a help string if the user asks for help or if the user provided too few/many arguments.

const RPCHelpMan help{...};
if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
    throw std::runtime_error(help.ToString());
}

or (older version)

if (request.fHelp || request.params.size() < min || request.params.size() > max)
    throw std::runtime_error(
        RPCHelpMan{...}.ToString()
    );

It seems like an obvious improvement, and less copy-pasting, to make RPCHelpMan aware of JSONRPCRequest, and to let it handle the checks instead. Both of the above become

RPCHelpMan{...}.Check(request);

which means we save roughly 3 lines per RPC command, and the RPCHelpMan instance is never referenced afterwards, so the approach is a tiny fraction cleaner.

This is a complete update, sans a few special case locations that had special rules. 623 lines turn into 284 (which includes the addition to RPCHelpMan).

@kallewoof kallewoof force-pushed the 2019-06-json-aware-helper branch from 9096017 to 8f70239 Compare June 19, 2019 05:00
@kallewoof kallewoof changed the title JSONRPCRequest-aware RPCHelpMan RPCHelpMan-aware JSONRPCRequest Jun 19, 2019
@kallewoof kallewoof force-pushed the 2019-06-json-aware-helper branch from 8f70239 to 76b9be3 Compare June 19, 2019 05:37
@sipa
Copy link
Member

sipa commented Jun 19, 2019

Concept ACK, though it seems more appropriate that the RPC help object would gain a method the check RPC arguments, than the RPC handling code to be aware of RPC help. I'm sure the circular dependency is resolvable; don't let it stop you from cleaning things up.

Also, if these lines are all touched anyway, could you add a scripted diff to fix their indentation?

@promag
Copy link
Contributor

promag commented Jun 19, 2019

Agree with @sipa, although the request already knows about fHelp.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 19, 2019

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #16365 (Log RPC parameters (arguments) if -debug=rpcparams by LarryRuane)
  • #16362 (gui: Bilingual translation by hebasto)
  • #16244 (Move wallet creation out of the createwallet rpc into its own function by achow101)
  • #16224 (gui: Bilingual GUI error messages by hebasto)
  • #16185 (gettransaction: add an argument to decode the transaction by darosior)
  • #15974 (refactor: Avoid UniValue copy constructor by promag)
  • #15931 (Remove GetDepthInMainChain dependency on locked chain interface by ariard)
  • #15836 (Add feerate histogram to getmempoolinfo by jonasschnelli)
  • #15729 (rpc: Raise error in getbalance if minconf is not zero by promag)
  • #15450 ([GUI] Create wallet menu option by achow101)
  • #14898 (rpc listtransactions new argument options (paginatebypointer impl) by hosseinamin)
  • #14707 ([RPC] Include coinbase transactions in receivedby RPCs by andrewtoth)

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.

@kallewoof
Copy link
Contributor Author

kallewoof commented Jun 19, 2019

@sipa I initially added one, but it needs to know about JSONRPCRequest to fetch the fHelp and params.size(), but if I #include <rpc/server.h>, the linters detect a circular dependency util -> server -> util. I definitely think this would be better in RPCHelpMan, but alas..

I would love to fix the indentation, but not sure how a scripted-diff would be used in this case. (I started working on that, with a sample commit at kallewoof@b969457 in https://github.com/kallewoof/bitcoin/commits/json-aware-helper-whitespaced-sample but got stuck on how to do scripted-diff part).

Edit: it may be acceptable to link to commit with ?w=1 which should show it empty, like kallewoof@b969457?w=1 -- that's almost as good as a scripted diff..

@fanquake
Copy link
Member

Concept ACK - nice cleanup / deduplication.

@kallewoof kallewoof force-pushed the 2019-06-json-aware-helper branch from f2bb974 to 31599d8 Compare June 19, 2019 09:40
@kallewoof kallewoof changed the title RPCHelpMan-aware JSONRPCRequest JSONRPCRequest-aware RPCHelpMan Jun 19, 2019
@kallewoof
Copy link
Contributor Author

kallewoof commented Jun 19, 2019

@sipa @promag I realized I could inline the helper method and implement it after JSONRPCRequest to get around linker issues, so this is now an RPCHelpMan method, as you recommended.

There is also a whitespace only commit (e7124e3) which blows the diff up a bit, but if reviewers check per-commit and use -w/?w=1 properly, it should be manageable. I can drop the whitespace commit too.

@promag
Copy link
Contributor

promag commented Jun 19, 2019

@kallewoof see dfdf7f2 for a scripted diff, produced by running on your 31599d8:

git diff -U0 HEAD~3.. | ./contrib/devtools/clang-format-diff.py -p0 -i -v

@kallewoof kallewoof force-pushed the 2019-06-json-aware-helper branch from e7124e3 to a3b264a Compare June 19, 2019 11:47
@kallewoof
Copy link
Contributor Author

kallewoof commented Jun 19, 2019

@promag I had no idea you could do that. Thanks, very cool!

Edit: not sure what is going wrong. Running this from cli gives me

Formatting b/src/rpc/blockchain.cpp
No such file or directory

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

Tend to NACK on fixing the code style in lines that are not touched otherwise. This breaks git blame and all cherry-pick/rebase/merge operations by default (see the list of conflicts).

src/rpc/util.h Outdated Show resolved Hide resolved
@promag
Copy link
Contributor

promag commented Jun 19, 2019

Makes sense @MarcoFalke, not worth it.

@kallewoof kallewoof force-pushed the 2019-06-json-aware-helper branch from a3b264a to 6da27e8 Compare June 19, 2019 13:31
@kallewoof
Copy link
Contributor Author

@MarcoFalke

Tend to NACK on fixing the code style in lines that are not touched otherwise. This breaks git blame and all cherry-pick/rebase/merge operations by default (see the list of conflicts).

I would normally agree, but the RPC code is out-of-this-world awful with indentation. I think it may be worth to run through it once, especially since the review effort required is near-nil.

@kallewoof kallewoof force-pushed the 2019-06-json-aware-helper branch from 6da27e8 to 5a3f382 Compare June 19, 2019 13:34
@maflcko
Copy link
Member

maflcko commented Jun 19, 2019

especially since the review effort required is near-nil.

Just because something is easy to review doesn't mean it should be done. Beside the things it breaks that I mentioned previously, it will also conflict with a bunch of my local branches, where I restructure the help to make it more consistent and compile-time-safe (use compile time checks and compile-time generated help). Those changes are going to actually touch the lines, so a reformat could make sense at that point in time (maybe).

Also, I'd say it is not clear if the rpc help must live in the scope of the rpc method. Maybe the help should live at the same scope as the rpc method? I'd say unclear right now, but if it is ever going to change, it would need another reformat. Doing another project-wide break of git blame/cherry-pick/merge/rebase

I think you underestimate the cost of merge conflicts. If you feel strong about the reformat, it should probably be split up into a separate pull request to be evaluated on its own. Otherwise, my NACK will still hold on this pull.

@kallewoof kallewoof force-pushed the 2019-06-json-aware-helper branch from 5a3f382 to 2b4e540 Compare June 19, 2019 14:02
@kallewoof
Copy link
Contributor Author

Understood. Would have been a nice clean up but I'm not gonna lose sleep over it. :) Dropped the whitespace commit.

src/rpc/mining.cpp Outdated Show resolved Hide resolved
@kallewoof kallewoof force-pushed the 2019-06-json-aware-helper branch from 2b4e540 to a388c8f Compare June 19, 2019 17:00
@kallewoof
Copy link
Contributor Author

@MarcoFalke: Updated getblocktemplate to display default as {} rather than {"mode":"template"}.

src/rpc/server.h Outdated Show resolved Hide resolved
@kallewoof kallewoof force-pushed the 2019-06-json-aware-helper branch 2 times, most recently from 79cb80a to b93d7ab Compare June 19, 2019 17:40
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

ACK d9c41cc, github commit sort ftw.. Yet another simple tidy up to RPC documentation. Renaming rpc/protocol.{h.cpp} LGTM - thanks to @laanwj. Also confirmed moved code.

src/rpc/util.h Outdated
* the user is asking for help information, and throw help when appropriate.
*/
inline void Check(const JSONRPCRequest& request) const {
if (request.fHelp || !IsValidNumArgs(request.params.size())) throw std::runtime_error(ToString());
Copy link
Contributor

Choose a reason for hiding this comment

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

09f0bf5

nit, add { }.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

@kallewoof kallewoof force-pushed the 2019-06-json-aware-helper branch from d9c41cc to b6fb617 Compare July 8, 2019 00:54
@kallewoof
Copy link
Contributor Author

@promag Thanks for the review! Note that I only renamed protocol.cpp, and moved some parts out of protocol.h into request.h -- protocol.h is still there, just smaller.

@laanwj
Copy link
Member

laanwj commented Jul 8, 2019

code rview and lightly tested ACK b6fb617

@maflcko
Copy link
Member

maflcko commented Jul 8, 2019

I do think this is slightly risky, as it gets rid of a lot of special-case code, is our test coverage of RPC good enough to be confident about changing this for all methods at once?

I checked all call-sites as part of

so this should only be refactoring. Though, you are right, most of it is not covered by tests.

@maflcko
Copy link
Member

maflcko commented Jul 9, 2019

ACK b6fb617, looked at the diff, verified move-only where applicable

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

ACK b6fb617aaa, looked at the diff, verified move-only where applicable
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUhX0AwAtwImLc9meZaRYasAtXwhpkTQpZ9bC0l6hK6uvUGSr4N8n3v63bezavGZ
pbddzccHclbs5gAtbJMsWkFmR7vKbfDgZi02MZLQqLwc5r+X8/rJdgscfFhMeHNy
WCQ8ZCJy5VAC5GA6SfshB8VWK+oQpx9GHCKc5OEMFRr7Sc8go0osRxWbMaNuJQdg
RGgzZ0/e2FS17czydBb5O3k2XTawUUfIa49zFq69kxSntpJdnmMJrqbAg8l0cKDK
OYd/HkWIVgx1LBtTBmLEF0sKuymhmqMfPbEoFOUXYqiGSTaQsZeS9cJDpc+Cy8Qa
+icW5+C23plWHC/+N89AeE6g3zcdxG1P1pIRP0YfRjQMx1lKxCuYeCep8vr2pNw7
X+SpZaoyRJWaoQnL4mPjtGP/7n+QXXjYj2MCq8yNz2uPzyqrvcfq7ZaP+IW5SBmY
Yl+J9K6FwTkneVkhDMjYMzoJLDwDH4yVrgChwMHYN7HEVY2M0WZhsSE9/HDgscqg
jEii4j6x
=rpAy
-----END PGP SIGNATURE-----

Timestamp of file with hash 890e34cddd2f763e5555c79809bdd129b142d59574aa8799ab8f1a06a0c076c6 -

@maflcko maflcko merged commit b6fb617 into bitcoin:master Jul 9, 2019
maflcko pushed a commit that referenced this pull request Jul 9, 2019
b6fb617 rpc: switch to using RPCHelpMan.Check() (Karl-Johan Alm)
c7a9fc2 Make the RPCHelpMan aware of JSONRPCRequest and add Check() helper (Karl-Johan Alm)
5c5e32b rpc: migrate JSONRPCRequest functionality into request.cpp (Karl-Johan Alm)
0ab8ba1 rpc: fix RPC help requirements for getblocktemplate (Karl-Johan Alm)

Pull request description:

  Every single RPC call has a helper-section at the start, which throws a help string if the user asks for help or if the user provided too few/many arguments.

  ```C++
  const RPCHelpMan help{...};
  if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
      throw std::runtime_error(help.ToString());
  }
  ```

  or (older version)

  ```C++
  if (request.fHelp || request.params.size() < min || request.params.size() > max)
      throw std::runtime_error(
          RPCHelpMan{...}.ToString()
      );
  ```

  It seems like an obvious improvement, and less copy-pasting, to make `RPCHelpMan` aware of `JSONRPCRequest`, and to let it handle the checks instead. Both of the above become

  ```C++
  RPCHelpMan{...}.Check(request);
  ```

  which means we save roughly 3 lines per RPC command, and the `RPCHelpMan` instance is never referenced afterwards, so the approach is a tiny fraction cleaner.

  This is a complete update, sans a few special case locations that had special rules. 623 lines turn into 284 (which includes the addition to `RPCHelpMan`).

ACKs for top commit:
  laanwj:
    code rview and lightly tested ACK b6fb617
  MarcoFalke:
    ACK b6fb617, looked at the diff, verified move-only where applicable

Tree-SHA512: eb73f47f812512905b852e313281d1c8df803db40a6188aa39d5a7586631664db6764491152a8a96769946c796dc56d38c6e3a66ddd06ba3fb9d20050e6274e1
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 10, 2019
b6fb617 rpc: switch to using RPCHelpMan.Check() (Karl-Johan Alm)
c7a9fc2 Make the RPCHelpMan aware of JSONRPCRequest and add Check() helper (Karl-Johan Alm)
5c5e32b rpc: migrate JSONRPCRequest functionality into request.cpp (Karl-Johan Alm)
0ab8ba1 rpc: fix RPC help requirements for getblocktemplate (Karl-Johan Alm)

Pull request description:

  Every single RPC call has a helper-section at the start, which throws a help string if the user asks for help or if the user provided too few/many arguments.

  ```C++
  const RPCHelpMan help{...};
  if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
      throw std::runtime_error(help.ToString());
  }
  ```

  or (older version)

  ```C++
  if (request.fHelp || request.params.size() < min || request.params.size() > max)
      throw std::runtime_error(
          RPCHelpMan{...}.ToString()
      );
  ```

  It seems like an obvious improvement, and less copy-pasting, to make `RPCHelpMan` aware of `JSONRPCRequest`, and to let it handle the checks instead. Both of the above become

  ```C++
  RPCHelpMan{...}.Check(request);
  ```

  which means we save roughly 3 lines per RPC command, and the `RPCHelpMan` instance is never referenced afterwards, so the approach is a tiny fraction cleaner.

  This is a complete update, sans a few special case locations that had special rules. 623 lines turn into 284 (which includes the addition to `RPCHelpMan`).

ACKs for top commit:
  laanwj:
    code rview and lightly tested ACK b6fb617
  MarcoFalke:
    ACK b6fb617, looked at the diff, verified move-only where applicable

Tree-SHA512: eb73f47f812512905b852e313281d1c8df803db40a6188aa39d5a7586631664db6764491152a8a96769946c796dc56d38c6e3a66ddd06ba3fb9d20050e6274e1
@kallewoof kallewoof deleted the 2019-06-json-aware-helper branch October 17, 2019 08:32
laanwj added a commit that referenced this pull request Dec 15, 2019
…t action

7d26357 rpc: require second argument only for scantxoutset start action (Andrew Chow)

Pull request description:

  It was reported on [IRC](http://www.erisian.com.au/bitcoin-core-dev/log-2019-12-11.html#l-377) that `scantxoutset`'s API was broken in 0.19.0:

  ```
  <belcher> i think scantxoutset may have been broken in bitcoin core 0.19 ? regardless of what parameters i run it with (e.g. "scantxoutset abort", "scantxoutset status") it just returns the help doc, according to the release notes the only change was https://github.com/bitcoin/bitcoin/pull/16285/files but i dont see anything that wouldve broken it, it works fine in 0.18
  <belcher> im on regtest, in case its important
  <harding> I can confirm `scantxoutset abort` returns the help doc on latest master.  Waiting for 0.18.1 to start now to attempt to reproduce there.
  <harding> It looks like it's expecting a second parameter (even though that doesn't make sense with "abort").
  <jonatack> Same for me as well
  <harding> Can also confirm that `scantxoutset abort` returns the expected result on 0.18.1.
  ```

  As noted in the conversation, previously, the second argument of `scanobjects` is only required for the `start` action. `Stop` and `abort` actions did not and could work without them.

  It appears that this was broken by #16240 which enforced the size of the arguments to match the listed required arguments.

  To fix this issue, this PR makes the `scanobjects` argument an optional argument. Then only in the `start` action do we check whether the `scanobjects` argument is there and throw an informative error about that. Also a test is added for this case.

ACKs for top commit:
  laanwj:
    ACK 7d26357
  promag:
    ACK 7d26357.

Tree-SHA512: 828bdfe47f4fffa5d00a2cf88db6cea4a2714d9c49276841ca5cbdd1603b87bb6862147b86edcf36d7b40314ddb80b1a07fd399faf288572c55cc788c5cf9526
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 16, 2019
…et start action

7d26357 rpc: require second argument only for scantxoutset start action (Andrew Chow)

Pull request description:

  It was reported on [IRC](http://www.erisian.com.au/bitcoin-core-dev/log-2019-12-11.html#l-377) that `scantxoutset`'s API was broken in 0.19.0:

  ```
  <belcher> i think scantxoutset may have been broken in bitcoin core 0.19 ? regardless of what parameters i run it with (e.g. "scantxoutset abort", "scantxoutset status") it just returns the help doc, according to the release notes the only change was https://github.com/bitcoin/bitcoin/pull/16285/files but i dont see anything that wouldve broken it, it works fine in 0.18
  <belcher> im on regtest, in case its important
  <harding> I can confirm `scantxoutset abort` returns the help doc on latest master.  Waiting for 0.18.1 to start now to attempt to reproduce there.
  <harding> It looks like it's expecting a second parameter (even though that doesn't make sense with "abort").
  <jonatack> Same for me as well
  <harding> Can also confirm that `scantxoutset abort` returns the expected result on 0.18.1.
  ```

  As noted in the conversation, previously, the second argument of `scanobjects` is only required for the `start` action. `Stop` and `abort` actions did not and could work without them.

  It appears that this was broken by bitcoin#16240 which enforced the size of the arguments to match the listed required arguments.

  To fix this issue, this PR makes the `scanobjects` argument an optional argument. Then only in the `start` action do we check whether the `scanobjects` argument is there and throw an informative error about that. Also a test is added for this case.

ACKs for top commit:
  laanwj:
    ACK 7d26357
  promag:
    ACK 7d26357.

Tree-SHA512: 828bdfe47f4fffa5d00a2cf88db6cea4a2714d9c49276841ca5cbdd1603b87bb6862147b86edcf36d7b40314ddb80b1a07fd399faf288572c55cc788c5cf9526
deadalnix added a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 10, 2020
Summary: This ensure names are consistent with [[bitcoin/bitcoin#16240 | PR16240]]

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D6496
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 10, 2020
Summary:
This si a partial backport of Core [[bitcoin/bitcoin#16240 | PR16240]] : bitcoin/bitcoin@5c5e32b

Depends on D6496

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D6497
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 10, 2020
Summary:
This is a partial backport of Core [[bitcoin/bitcoin#16240 | PR16240]] : bitcoin/bitcoin@c7a9fc2

Depends on D6497

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D6498
sidhujag pushed a commit to syscoin-core/syscoin that referenced this pull request Nov 10, 2020
…et start action

7d26357 rpc: require second argument only for scantxoutset start action (Andrew Chow)

Pull request description:

  It was reported on [IRC](http://www.erisian.com.au/bitcoin-core-dev/log-2019-12-11.html#l-377) that `scantxoutset`'s API was broken in 0.19.0:

  ```
  <belcher> i think scantxoutset may have been broken in bitcoin core 0.19 ? regardless of what parameters i run it with (e.g. "scantxoutset abort", "scantxoutset status") it just returns the help doc, according to the release notes the only change was https://github.com/bitcoin/bitcoin/pull/16285/files but i dont see anything that wouldve broken it, it works fine in 0.18
  <belcher> im on regtest, in case its important
  <harding> I can confirm `scantxoutset abort` returns the help doc on latest master.  Waiting for 0.18.1 to start now to attempt to reproduce there.
  <harding> It looks like it's expecting a second parameter (even though that doesn't make sense with "abort").
  <jonatack> Same for me as well
  <harding> Can also confirm that `scantxoutset abort` returns the expected result on 0.18.1.
  ```

  As noted in the conversation, previously, the second argument of `scanobjects` is only required for the `start` action. `Stop` and `abort` actions did not and could work without them.

  It appears that this was broken by bitcoin#16240 which enforced the size of the arguments to match the listed required arguments.

  To fix this issue, this PR makes the `scanobjects` argument an optional argument. Then only in the `start` action do we check whether the `scanobjects` argument is there and throw an informative error about that. Also a test is added for this case.

ACKs for top commit:
  laanwj:
    ACK 7d26357
  promag:
    ACK 7d26357.

Tree-SHA512: 828bdfe47f4fffa5d00a2cf88db6cea4a2714d9c49276841ca5cbdd1603b87bb6862147b86edcf36d7b40314ddb80b1a07fd399faf288572c55cc788c5cf9526
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Dec 22, 2021
…et start action

7d26357 rpc: require second argument only for scantxoutset start action (Andrew Chow)

Pull request description:

  It was reported on [IRC](http://www.erisian.com.au/bitcoin-core-dev/log-2019-12-11.html#l-377) that `scantxoutset`'s API was broken in 0.19.0:

  ```
  <belcher> i think scantxoutset may have been broken in bitcoin core 0.19 ? regardless of what parameters i run it with (e.g. "scantxoutset abort", "scantxoutset status") it just returns the help doc, according to the release notes the only change was https://github.com/bitcoin/bitcoin/pull/16285/files but i dont see anything that wouldve broken it, it works fine in 0.18
  <belcher> im on regtest, in case its important
  <harding> I can confirm `scantxoutset abort` returns the help doc on latest master.  Waiting for 0.18.1 to start now to attempt to reproduce there.
  <harding> It looks like it's expecting a second parameter (even though that doesn't make sense with "abort").
  <jonatack> Same for me as well
  <harding> Can also confirm that `scantxoutset abort` returns the expected result on 0.18.1.
  ```

  As noted in the conversation, previously, the second argument of `scanobjects` is only required for the `start` action. `Stop` and `abort` actions did not and could work without them.

  It appears that this was broken by bitcoin#16240 which enforced the size of the arguments to match the listed required arguments.

  To fix this issue, this PR makes the `scanobjects` argument an optional argument. Then only in the `start` action do we check whether the `scanobjects` argument is there and throw an informative error about that. Also a test is added for this case.

ACKs for top commit:
  laanwj:
    ACK 7d26357
  promag:
    ACK 7d26357.

Tree-SHA512: 828bdfe47f4fffa5d00a2cf88db6cea4a2714d9c49276841ca5cbdd1603b87bb6862147b86edcf36d7b40314ddb80b1a07fd399faf288572c55cc788c5cf9526
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Dec 22, 2021
…et start action

7d26357 rpc: require second argument only for scantxoutset start action (Andrew Chow)

Pull request description:

  It was reported on [IRC](http://www.erisian.com.au/bitcoin-core-dev/log-2019-12-11.html#l-377) that `scantxoutset`'s API was broken in 0.19.0:

  ```
  <belcher> i think scantxoutset may have been broken in bitcoin core 0.19 ? regardless of what parameters i run it with (e.g. "scantxoutset abort", "scantxoutset status") it just returns the help doc, according to the release notes the only change was https://github.com/bitcoin/bitcoin/pull/16285/files but i dont see anything that wouldve broken it, it works fine in 0.18
  <belcher> im on regtest, in case its important
  <harding> I can confirm `scantxoutset abort` returns the help doc on latest master.  Waiting for 0.18.1 to start now to attempt to reproduce there.
  <harding> It looks like it's expecting a second parameter (even though that doesn't make sense with "abort").
  <jonatack> Same for me as well
  <harding> Can also confirm that `scantxoutset abort` returns the expected result on 0.18.1.
  ```

  As noted in the conversation, previously, the second argument of `scanobjects` is only required for the `start` action. `Stop` and `abort` actions did not and could work without them.

  It appears that this was broken by bitcoin#16240 which enforced the size of the arguments to match the listed required arguments.

  To fix this issue, this PR makes the `scanobjects` argument an optional argument. Then only in the `start` action do we check whether the `scanobjects` argument is there and throw an informative error about that. Also a test is added for this case.

ACKs for top commit:
  laanwj:
    ACK 7d26357
  promag:
    ACK 7d26357.

Tree-SHA512: 828bdfe47f4fffa5d00a2cf88db6cea4a2714d9c49276841ca5cbdd1603b87bb6862147b86edcf36d7b40314ddb80b1a07fd399faf288572c55cc788c5cf9526
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Dec 22, 2021
…et start action

7d26357 rpc: require second argument only for scantxoutset start action (Andrew Chow)

Pull request description:

  It was reported on [IRC](http://www.erisian.com.au/bitcoin-core-dev/log-2019-12-11.html#l-377) that `scantxoutset`'s API was broken in 0.19.0:

  ```
  <belcher> i think scantxoutset may have been broken in bitcoin core 0.19 ? regardless of what parameters i run it with (e.g. "scantxoutset abort", "scantxoutset status") it just returns the help doc, according to the release notes the only change was https://github.com/bitcoin/bitcoin/pull/16285/files but i dont see anything that wouldve broken it, it works fine in 0.18
  <belcher> im on regtest, in case its important
  <harding> I can confirm `scantxoutset abort` returns the help doc on latest master.  Waiting for 0.18.1 to start now to attempt to reproduce there.
  <harding> It looks like it's expecting a second parameter (even though that doesn't make sense with "abort").
  <jonatack> Same for me as well
  <harding> Can also confirm that `scantxoutset abort` returns the expected result on 0.18.1.
  ```

  As noted in the conversation, previously, the second argument of `scanobjects` is only required for the `start` action. `Stop` and `abort` actions did not and could work without them.

  It appears that this was broken by bitcoin#16240 which enforced the size of the arguments to match the listed required arguments.

  To fix this issue, this PR makes the `scanobjects` argument an optional argument. Then only in the `start` action do we check whether the `scanobjects` argument is there and throw an informative error about that. Also a test is added for this case.

ACKs for top commit:
  laanwj:
    ACK 7d26357
  promag:
    ACK 7d26357.

Tree-SHA512: 828bdfe47f4fffa5d00a2cf88db6cea4a2714d9c49276841ca5cbdd1603b87bb6862147b86edcf36d7b40314ddb80b1a07fd399faf288572c55cc788c5cf9526
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Dec 28, 2021
…et start action

7d26357 rpc: require second argument only for scantxoutset start action (Andrew Chow)

Pull request description:

  It was reported on [IRC](http://www.erisian.com.au/bitcoin-core-dev/log-2019-12-11.html#l-377) that `scantxoutset`'s API was broken in 0.19.0:

  ```
  <belcher> i think scantxoutset may have been broken in bitcoin core 0.19 ? regardless of what parameters i run it with (e.g. "scantxoutset abort", "scantxoutset status") it just returns the help doc, according to the release notes the only change was https://github.com/bitcoin/bitcoin/pull/16285/files but i dont see anything that wouldve broken it, it works fine in 0.18
  <belcher> im on regtest, in case its important
  <harding> I can confirm `scantxoutset abort` returns the help doc on latest master.  Waiting for 0.18.1 to start now to attempt to reproduce there.
  <harding> It looks like it's expecting a second parameter (even though that doesn't make sense with "abort").
  <jonatack> Same for me as well
  <harding> Can also confirm that `scantxoutset abort` returns the expected result on 0.18.1.
  ```

  As noted in the conversation, previously, the second argument of `scanobjects` is only required for the `start` action. `Stop` and `abort` actions did not and could work without them.

  It appears that this was broken by bitcoin#16240 which enforced the size of the arguments to match the listed required arguments.

  To fix this issue, this PR makes the `scanobjects` argument an optional argument. Then only in the `start` action do we check whether the `scanobjects` argument is there and throw an informative error about that. Also a test is added for this case.

ACKs for top commit:
  laanwj:
    ACK 7d26357
  promag:
    ACK 7d26357.

Tree-SHA512: 828bdfe47f4fffa5d00a2cf88db6cea4a2714d9c49276841ca5cbdd1603b87bb6862147b86edcf36d7b40314ddb80b1a07fd399faf288572c55cc788c5cf9526
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Jan 23, 2022
b6fb617 rpc: switch to using RPCHelpMan.Check() (Karl-Johan Alm)
c7a9fc2 Make the RPCHelpMan aware of JSONRPCRequest and add Check() helper (Karl-Johan Alm)
5c5e32b rpc: migrate JSONRPCRequest functionality into request.cpp (Karl-Johan Alm)
0ab8ba1 rpc: fix RPC help requirements for getblocktemplate (Karl-Johan Alm)

Pull request description:

  Every single RPC call has a helper-section at the start, which throws a help string if the user asks for help or if the user provided too few/many arguments.

  ```C++
  const RPCHelpMan help{...};
  if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
      throw std::runtime_error(help.ToString());
  }
  ```

  or (older version)

  ```C++
  if (request.fHelp || request.params.size() < min || request.params.size() > max)
      throw std::runtime_error(
          RPCHelpMan{...}.ToString()
      );
  ```

  It seems like an obvious improvement, and less copy-pasting, to make `RPCHelpMan` aware of `JSONRPCRequest`, and to let it handle the checks instead. Both of the above become

  ```C++
  RPCHelpMan{...}.Check(request);
  ```

  which means we save roughly 3 lines per RPC command, and the `RPCHelpMan` instance is never referenced afterwards, so the approach is a tiny fraction cleaner.

  This is a complete update, sans a few special case locations that had special rules. 623 lines turn into 284 (which includes the addition to `RPCHelpMan`).

ACKs for top commit:
  laanwj:
    code rview and lightly tested ACK b6fb617
  MarcoFalke:
    ACK b6fb617, looked at the diff, verified move-only where applicable

Tree-SHA512: eb73f47f812512905b852e313281d1c8df803db40a6188aa39d5a7586631664db6764491152a8a96769946c796dc56d38c6e3a66ddd06ba3fb9d20050e6274e1
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Jan 25, 2022
b6fb617 rpc: switch to using RPCHelpMan.Check() (Karl-Johan Alm)
c7a9fc2 Make the RPCHelpMan aware of JSONRPCRequest and add Check() helper (Karl-Johan Alm)
5c5e32b rpc: migrate JSONRPCRequest functionality into request.cpp (Karl-Johan Alm)
0ab8ba1 rpc: fix RPC help requirements for getblocktemplate (Karl-Johan Alm)

Pull request description:

  Every single RPC call has a helper-section at the start, which throws a help string if the user asks for help or if the user provided too few/many arguments.

  ```C++
  const RPCHelpMan help{...};
  if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
      throw std::runtime_error(help.ToString());
  }
  ```

  or (older version)

  ```C++
  if (request.fHelp || request.params.size() < min || request.params.size() > max)
      throw std::runtime_error(
          RPCHelpMan{...}.ToString()
      );
  ```

  It seems like an obvious improvement, and less copy-pasting, to make `RPCHelpMan` aware of `JSONRPCRequest`, and to let it handle the checks instead. Both of the above become

  ```C++
  RPCHelpMan{...}.Check(request);
  ```

  which means we save roughly 3 lines per RPC command, and the `RPCHelpMan` instance is never referenced afterwards, so the approach is a tiny fraction cleaner.

  This is a complete update, sans a few special case locations that had special rules. 623 lines turn into 284 (which includes the addition to `RPCHelpMan`).

ACKs for top commit:
  laanwj:
    code rview and lightly tested ACK b6fb617
  MarcoFalke:
    ACK b6fb617, looked at the diff, verified move-only where applicable

Tree-SHA512: eb73f47f812512905b852e313281d1c8df803db40a6188aa39d5a7586631664db6764491152a8a96769946c796dc56d38c6e3a66ddd06ba3fb9d20050e6274e1
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Jan 25, 2022
b6fb617 rpc: switch to using RPCHelpMan.Check() (Karl-Johan Alm)
c7a9fc2 Make the RPCHelpMan aware of JSONRPCRequest and add Check() helper (Karl-Johan Alm)
5c5e32b rpc: migrate JSONRPCRequest functionality into request.cpp (Karl-Johan Alm)
0ab8ba1 rpc: fix RPC help requirements for getblocktemplate (Karl-Johan Alm)

Pull request description:

  Every single RPC call has a helper-section at the start, which throws a help string if the user asks for help or if the user provided too few/many arguments.

  ```C++
  const RPCHelpMan help{...};
  if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
      throw std::runtime_error(help.ToString());
  }
  ```

  or (older version)

  ```C++
  if (request.fHelp || request.params.size() < min || request.params.size() > max)
      throw std::runtime_error(
          RPCHelpMan{...}.ToString()
      );
  ```

  It seems like an obvious improvement, and less copy-pasting, to make `RPCHelpMan` aware of `JSONRPCRequest`, and to let it handle the checks instead. Both of the above become

  ```C++
  RPCHelpMan{...}.Check(request);
  ```

  which means we save roughly 3 lines per RPC command, and the `RPCHelpMan` instance is never referenced afterwards, so the approach is a tiny fraction cleaner.

  This is a complete update, sans a few special case locations that had special rules. 623 lines turn into 284 (which includes the addition to `RPCHelpMan`).

ACKs for top commit:
  laanwj:
    code rview and lightly tested ACK b6fb617
  MarcoFalke:
    ACK b6fb617, looked at the diff, verified move-only where applicable

Tree-SHA512: eb73f47f812512905b852e313281d1c8df803db40a6188aa39d5a7586631664db6764491152a8a96769946c796dc56d38c6e3a66ddd06ba3fb9d20050e6274e1
@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.

8 participants