Handle getinfo in bitcoin-cli w/ -getinfo (revival of #8843) #10871

pull achow101 wants to merge 2 commits into bitcoin:master from achow101:cli-getinfo changing 4 files +150 −15
  1. achow101 commented at 10:19 pm on July 18, 2017: member

    Since @laanwj doesn’t want to maintain these changes anymore, I will.

    This PR is a revival of #8843. I have addressed @jnewbery’s comments.

    Regarding atomicity, I don’t think that is a concern here. This is explicitly a new API and those who use it will know that this is different and that it is not atomic.

  2. jonasschnelli added the label Scripts and tools on Jul 19, 2017
  3. jonasschnelli commented at 8:15 am on July 19, 2017: contributor
    Concept ACK. Can you add a tool test for that?
  4. laanwj commented at 8:31 am on July 20, 2017: member

    Can you add a tool test for that?

    A simple tool-test like -tx’s wont work here as it requires a running bitcoind. Better to wait for bitcoin-cli testing infrastructure to be in place I guess (#10798)?

  5. achow101 force-pushed on Aug 15, 2017
  6. achow101 commented at 9:39 pm on August 15, 2017: member
    rebased
  7. jnewbery commented at 10:05 pm on August 15, 2017: member

    bad rebase:

    0bitcoin-cli.cpp: In function ‘int CommandLineRPC(int, char**)’:
    1bitcoin-cli.cpp:393:41: error: ‘GetBoolArg’ was not declared in this scope
    2         if (GetBoolArg("-getinfo", false)) {
    3                                         ^
    

    #10798 is now rebased and ready for merge. It should be fairly straightforward to rebase this on top of that to add a functional test.

  8. achow101 force-pushed on Aug 15, 2017
  9. jnewbery commented at 6:32 pm on August 23, 2017: member

    Test here if you want it: https://github.com/jnewbery/bitcoin/tree/pr10871_test

    Builds on top of #10798. Test currently fails because the output for bitcoin-cli getinfo and bitcoin-cli -getinfo is different in keypoolsize and unlocked_until. See #8843 (review) for information about keypoolsize discrepancy.

  10. TheBlueMatt commented at 6:59 pm on August 23, 2017: member
    I think the docs should at least mention something about atomicity. Every other API to Bitcoin Core is atomic, so it feels very strange to add a new one which is not.
  11. laanwj commented at 7:26 pm on August 23, 2017: member

    I think the docs should at least mention something about atomicity. Every other API to Bitcoin Core is atomic, so it feels very strange to add a new one which is not.

    I know you don’t like this particular changej, but this is reaching FUD levels here, what exactly are you concerned about happening here? -getinfo pulls the following information:

     0getnetworkinfo:
     1"version"
     2"protocolversion"
     3"timeoffset"
     4"connections"
     5"proxy"
     6"relayfee"
     7"errors"
     8
     9getblockchaininfo:
    10"blocks"
    11"difficulty"
    12"testnet"
    13
    14getwalletinfo:
    15"walletversion"
    16"balance"
    17"keypoololdest"
    18"keypoolsize"
    19"unlocked_until"
    20"paytxfee"
    

    Within a group, the values are as atomic as ever. Some of these don’t change at runtime at all, some hardly change.

    Can you indicate exactly between which two you’re afraid non-atomicity is going to give a problem, in practice?

    If not, let’s please leave this behind us.

  12. TheBlueMatt commented at 4:38 pm on August 24, 2017: member
    My only real atomicity concern is between blocks and balance - ie that you may call getinfo, see a balance and assume that it is current as of a given block height. It may be of lesser concern in just bitcoin-cli, as its not intended to be used in scripts, hence my note that I’d be ok with just documenting this behavior, though I could still see someone fucking it up in some way.
  13. laanwj commented at 4:47 pm on August 24, 2017: member

    My only real atomicity concern is between blocks and balance - ie that you may call getinfo, see a balance and assume that it is current as of a given block height.

    Yes, that’s a valid concern. Also outside this PR - there is currently no way to query up to which height the wallet has processed. Especially when the wallet and node are decoupled further w/ threads or even processes. We should add a curheight or such to getwalletinfo.

  14. jnewbery commented at 5:17 pm on August 24, 2017: member

    there is currently no way to query up to which height the wallet has processed

    I believe that getinfo itself could be misleading here. balance could be for a different height than blocks.

    There’s been discussion of adding the wallet’s best block to getwalletinfo on IRC: https://botbot.me/freenode/bitcoin-core-dev/2017-08-11/?msg=89723092&page=2 and I have a branch to do that, which I’m going to PR after #10286

  15. jnewbery commented at 4:57 pm on September 1, 2017: member

    Is this still being actively worked on? Next steps would be:

  16. achow101 commented at 5:03 pm on September 1, 2017: member
    I am still working on this, just got sidetracked with other stuff.
  17. achow101 force-pushed on Sep 5, 2017
  18. achow101 commented at 5:10 pm on September 5, 2017: member

    Took the test and rebased.

    fix the discrepencies between getinfo and -getinfo

    What discrepancies?

  19. jnewbery commented at 5:21 pm on September 5, 2017: member

    What discrepancies?

    See above:

    Test currently fails because the output for bitcoin-cli getinfo and bitcoin-cli -getinfo is different in keypoolsize and unlocked_until. See #8843 (comment) for information about keypoolsize discrepancy.

    Once #10838 is merged, then that’s no longer an issue.

    After #10838, I think the way to test this would be to collect the responses from getwalletinfo, getblockchaininfo and getnetworkinfo, merge those dictionaries (hint: https://stackoverflow.com/a/26853961) and then compare that to the response from bitcoin-cli -getinfo.

  20. achow101 commented at 5:29 pm on September 5, 2017: member

    After #10838, I think the way to test this would be to collect the responses from getwalletinfo, getblockchaininfo and getnetworkinfo, merge those dictionaries (hint: https://stackoverflow.com/a/26853961) and then compare that to the response from bitcoin-cli -getinfo.

    I think that we should be doing that instead of comparing against getinfo. This is explicitly a new thing which is similar to getinfo but not exactly replicating it.

  21. achow101 force-pushed on Sep 5, 2017
  22. achow101 commented at 9:33 pm on September 5, 2017: member
    I modified the test to compare against the get*info RPCs instead of getinfo
  23. in src/rpc/protocol.cpp:146 in 5d2341c976 outdated
    141+        throw std::runtime_error("Batch must be an array");
    142+    }
    143+    std::vector<UniValue> batch(num);
    144+    for (size_t i=0; i<in.size(); ++i) {
    145+        const UniValue &rec = in[i];
    146+        if (!rec.isObject())
    


    jnewbery commented at 11:26 pm on September 5, 2017:
    please also add braces to these if blocks

    achow101 commented at 0:10 am on September 6, 2017:
    Done
  24. jnewbery commented at 11:30 pm on September 5, 2017: member

    one nit inline.

    Please tidy up commits. First two commits should be squashed, and final two commits should be squashed into a second commit.

  25. achow101 force-pushed on Sep 6, 2017
  26. achow101 commented at 0:08 am on September 6, 2017: member
    Tidied up commits
  27. achow101 force-pushed on Sep 6, 2017
  28. in src/bitcoin-cli.cpp:283 in 226fa64cb2 outdated
    279+    {
    280+        return reply.get_obj();
    281+    }
    282+};
    283+
    284+UniValue CallRPC(BaseRequestHandler *rh, const std::string& strMethod, const std::vector<std::string>& args)
    


    jnewbery commented at 0:47 am on September 6, 2017:
    You’ve lost the static keyword for this function in your rebase.
  29. in src/bitcoin-cli.cpp:403 in 226fa64cb2 outdated
    395@@ -307,23 +396,24 @@ int CommandLineRPC(int argc, char *argv[])
    396             while (std::getline(std::cin,line))
    397                 args.push_back(line);
    398         }
    399+        std::unique_ptr<BaseRequestHandler> rh;
    400+        if (gArgs.GetBoolArg("-getinfo", false)) {
    401+            rh.reset(new GetinfoRequestHandler());
    402+            args.clear();
    403+            args.push_back("getinfo");
    


    jnewbery commented at 4:44 pm on September 6, 2017:

    I think it would be clearer to not reset args here. The only reason you’re doing this is to pass the if (args.size() < 1) check below and then extract strMethod.

    Instead, just move the if (args.size() < 1) check into the else branch. GetinfoRequestHandler.PrepareRequest() doesn’t require strMethod or args.

    Taking this further, you could add a method to DefaultRequestHandler to update the strMethod and args, and then update the PrepareRequest() method to not take any arguments.

  30. achow101 force-pushed on Sep 6, 2017
  31. in src/bitcoin-cli.cpp:253 in 226fa64cb2 outdated
    249+        if (!batch[ID_WALLETINFO].isNull()) {
    250+            result.pushKV("walletversion", batch[ID_WALLETINFO]["result"]["walletversion"]);
    251+            result.pushKV("balance", batch[ID_WALLETINFO]["result"]["balance"]);
    252+            result.pushKV("keypoololdest", batch[ID_WALLETINFO]["result"]["keypoololdest"]);
    253+            result.pushKV("keypoolsize", batch[ID_WALLETINFO]["result"]["keypoolsize"]);
    254+            if (!batch[ID_WALLETINFO]["result"]["unlocked_until"].isNull())
    


    jnewbery commented at 4:44 pm on September 6, 2017:
    nit: braces
  32. in src/bitcoin-cli.cpp:214 in 226fa64cb2 outdated
    210+    const int ID_NETWORKINFO = 0;
    211+    const int ID_BLOCKCHAININFO = 1;
    212+    const int ID_WALLETINFO = 2;
    213+
    214+    /** Create a simulated `getinfo` request. */
    215+    UniValue PrepareRequest(const std::string& strMethod, const std::vector<std::string>& args) override
    


    jnewbery commented at 4:45 pm on September 6, 2017:
    nit: function arguments should not be hungarian/camel case strMethod -> method

    jnewbery commented at 9:12 pm on September 22, 2017:

    nit: function arguments should not be hungarian/camel case strMethod -> method

    not currently addressed


    achow101 commented at 3:51 pm on September 26, 2017:
    Done
  33. jnewbery commented at 4:48 pm on September 6, 2017: member

    Some comments in line.

    You seem to have lost the test in your commit squashing.

  34. achow101 force-pushed on Sep 6, 2017
  35. achow101 force-pushed on Sep 7, 2017
  36. achow101 force-pushed on Sep 18, 2017
  37. achow101 commented at 3:36 pm on September 18, 2017: member
    Fixed the test failure.
  38. laanwj added this to the "Blockers" column in a project

  39. in src/bitcoin-cli.cpp:201 in 2cf0866df7 outdated
    197+ * as well as converting back to a JSON object that can be shown as result.
    198+ */
    199+class BaseRequestHandler
    200+{
    201+public:
    202+    virtual UniValue PrepareRequest(const std::string& strMethod, const std::vector<std::string>& args) = 0;
    


    jnewbery commented at 9:12 pm on September 22, 2017:
    nit strMethod -> method

    achow101 commented at 3:51 pm on September 26, 2017:
    Done
  40. in test/functional/bitcoin_cli.py:60 in 2cf0866df7 outdated
    55+        assert_equal(cli_get_info['keypoololdest'], wallet_info['keypoololdest'])
    56+        assert_equal(cli_get_info['keypoolsize'], wallet_info['keypoolsize'])
    57+        assert_equal(cli_get_info['paytxfee'], wallet_info['paytxfee'])
    58+        assert_equal(cli_get_info['relayfee'], network_info['relayfee'])
    59+
    60+        if 'unlocked_until' in wallet_info:
    


    jnewbery commented at 9:21 pm on September 22, 2017:

    We know that the wallet isn’t locked, so this won’t be tested. I don’t think there’s any benefit in adding a test code that won’t be executed (in fact it’s slightly deleterious since a casual reader might think that we’re actually testing this).

    Either:

    • lock the wallet and actually test this
    • add a comment saying we’re not testing the field because the wallet isn’t locked.

    I think either is fine.


    achow101 commented at 3:51 pm on September 26, 2017:
    Done
  41. jnewbery commented at 9:21 pm on September 22, 2017: member
    Looks really good. Just a few nitty comments inline
  42. achow101 force-pushed on Sep 26, 2017
  43. achow101 commented at 3:52 pm on September 26, 2017: member
    Addressed nits (sorry for the delay).
  44. jnewbery commented at 4:25 pm on September 26, 2017: member

    Tested ACK 5ca97e5f03d7352558991e8eb26bb58dc4eec453.

    Thanks for sticking with this!

  45. in src/bitcoin-cli.cpp:40 in 5ca97e5f03 outdated
    36@@ -37,6 +37,7 @@ std::string HelpMessageCli()
    37     strUsage += HelpMessageOpt("-?", _("This help message"));
    38     strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), BITCOIN_CONF_FILENAME));
    39     strUsage += HelpMessageOpt("-datadir=<dir>", _("Specify data directory"));
    40+    strUsage += HelpMessageOpt("-getinfo", _("Get general information from the remote server"));
    


    TheBlueMatt commented at 8:28 pm on September 27, 2017:
    Are you going to update the help text to note something about balance/height atomicity? The old getinfo takes cs_main and cs_wallet and returns atomic information, this no longer does. getwalletinfo will likely eventually return something so that you can report if a result was atomic here (probably a follow-up to #10286).

    achow101 commented at 0:06 am on September 28, 2017:
    What do you suggest that the text for such a note be?

    laanwj commented at 6:32 am on September 28, 2017:
    as getinfo is misleading here too, see #10871 (comment), I still don’t see this as a strong point, but as it seems to bother @TheBlueMatt very much let’s just add it…

    TheBlueMatt commented at 10:02 pm on September 28, 2017:
    @laanwj I do not believe that to be the case in any release nor on master during normal operation (there are special cases for locked wallets). It will be the case after #10286, however there is no getinfo on master either….
  46. TheBlueMatt commented at 1:39 am on September 28, 2017: member

    Something like “Note that unlike server-side RPC calls, the results of getinfo is the result of multiple non-atomic requests. Some entries in the result may represent results from different states (eg wallet balance may be as of a different block from the chain state reported)”

    On September 27, 2017 8:06:29 PM EDT, Andrew Chow notifications@github.com wrote:

    achow101 commented on this pull request.

    @@ -37,6 +37,7 @@ std::string HelpMessageCli() strUsage += HelpMessageOpt("-?", (“This help message”)); strUsage += HelpMessageOpt("-conf=", strprintf((“Specify configuration file (default: %s)”), BITCOIN_CONF_FILENAME)); strUsage += HelpMessageOpt("-datadir=", _(“Specify data directory”));

    • strUsage += HelpMessageOpt("-getinfo", _(“Get general information from the remote server”));

    What do you suggest that the text for such a note be?

    – You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/bitcoin/bitcoin/pull/10871#discussion_r141498012

  47. rpc: Handle `getinfo` locally in bitcoin-cli w/ `-getinfo`
    This adds the infrastructure `BaseRequestHandler` class that takes care
    of converting bitcoin-cli arguments into a JSON-RPC request object, and
    converting the reply into a JSON object that can be shown as result.
    
    This is subsequently used to handle the `-getinfo` option, which sends
    a JSON-RPC batch request to the RPC server with
    `["getnetworkinfo", "getblockchaininfo", "getwalletinfo"]`,
    and after reply combines the result into what looks like a `getinfo`
    result.
    
    There have been some requests for a client-side `getinfo` and this
    is my PoC of how to do it. If this is considered a good idea
    some of the logic could be moved up to rpcclient.cpp and
    used in the GUI console as well.
    
    Extra-Author: Andrew Chow <achow101@gmail.com>
    382625318d
  48. Add test for bitcoin-cli -getinfo
    Extra-Author: Andrew Chow <achow101@gmail.com>
    5e69a430ee
  49. achow101 force-pushed on Sep 28, 2017
  50. achow101 commented at 1:53 am on September 28, 2017: member
    Added the atomicity note to the help text.
  51. laanwj commented at 6:33 am on September 28, 2017: member
    utACK 5e69a43
  52. laanwj merged this on Sep 28, 2017
  53. laanwj closed this on Sep 28, 2017

  54. laanwj referenced this in commit c9a4aa8a0e on Sep 28, 2017
  55. laanwj removed this from the "Blockers" column in a project

  56. QingjingJing commented at 10:10 pm on September 28, 2017: none

    Thanks, helped.

    On Thu, Sep 28, 2017 at 2:54 AM, Andrew Chow notifications@github.com wrote:

    Added the atomicity note to the help text.

    — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bitcoin/bitcoin/pull/10871#issuecomment-332704361, or mute the thread https://github.com/notifications/unsubscribe-auth/AdBhR6LWhfiCahFF4ZmMTHD0vw0tUAmcks5smvxWgaJpZM4Ob_vu .

  57. luke-jr referenced this in commit 1a42e5c71a on Nov 6, 2017
  58. meshcollider referenced this in commit aece8a4637 on Jan 24, 2018
  59. crombiecrunch commented at 6:52 pm on February 9, 2018: none
    can someone please tell me how to apply this so that getinfo can work with the yiimp opensource pool files?
  60. MarcoFalke commented at 7:55 pm on February 9, 2018: member
    @crombiecrunch Please submit a pull request upstream, replacing getinfo[‘balance’] with getwalletinfo[‘balance’] in the open source code.
  61. schancel referenced this in commit de194bfc60 on Apr 14, 2019
  62. proteanx referenced this in commit 9a00569446 on Apr 26, 2019
  63. PastaPastaPasta referenced this in commit 3c971291bb on Feb 13, 2020
  64. PastaPastaPasta referenced this in commit 78ab47562c on Feb 13, 2020
  65. PastaPastaPasta referenced this in commit f2024366d8 on Feb 29, 2020
  66. ckti referenced this in commit 1082a0ab1a on Mar 28, 2021
  67. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-29 01:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me