Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Handle getinfo in bitcoin-cli w/ -getinfo (revival of #8843) #10871
Conversation
jonasschnelli
added
the
Scripts and tools
label
Jul 19, 2017
|
Concept ACK. |
A simple tool-test like -tx's wont work here as it requires a running bitcoind. |
|
rebased |
|
bad rebase:
#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. |
|
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 |
|
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?
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. |
|
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. |
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 |
I believe that There's been discussion of adding the wallet's best block to |
jnewbery
referenced this pull request
Aug 25, 2017
Merged
Add bitcoin-cli -stdin and -stdinrpcpass functional tests #11125
|
Is this still being actively worked on? Next steps would be:
|
|
I am still working on this, just got sidetracked with other stuff. |
|
Took the test and rebased.
What discrepancies? |
See above:
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 |
I think that we should be doing that instead of comparing against |
|
I modified the test to compare against the |
jnewbery
reviewed
Sep 5, 2017
one nit inline.
Please tidy up commits. First two commits should be squashed, and final two commits should be squashed into a second commit.
| + std::vector<UniValue> batch(num); | ||
| + for (size_t i=0; i<in.size(); ++i) { | ||
| + const UniValue &rec = in[i]; | ||
| + if (!rec.isObject()) |
|
Tidied up commits |
| + } | ||
| +}; | ||
| + | ||
| +UniValue CallRPC(BaseRequestHandler *rh, const std::string& strMethod, const std::vector<std::string>& args) |
jnewbery
reviewed
Sep 6, 2017
Some comments in line.
You seem to have lost the test in your commit squashing.
| + const int ID_WALLETINFO = 2; | ||
| + | ||
| + /** Create a simulated `getinfo` request. */ | ||
| + UniValue PrepareRequest(const std::string& strMethod, const std::vector<std::string>& args) override |
jnewbery
Sep 6, 2017
Member
nit: function arguments should not be hungarian/camel case strMethod -> method
jnewbery
Sep 22, 2017
Member
nit: function arguments should not be hungarian/camel case strMethod -> method
not currently addressed
| + result.pushKV("balance", batch[ID_WALLETINFO]["result"]["balance"]); | ||
| + result.pushKV("keypoololdest", batch[ID_WALLETINFO]["result"]["keypoololdest"]); | ||
| + result.pushKV("keypoolsize", batch[ID_WALLETINFO]["result"]["keypoolsize"]); | ||
| + if (!batch[ID_WALLETINFO]["result"]["unlocked_until"].isNull()) |
| + if (gArgs.GetBoolArg("-getinfo", false)) { | ||
| + rh.reset(new GetinfoRequestHandler()); | ||
| + args.clear(); | ||
| + args.push_back("getinfo"); |
jnewbery
Sep 6, 2017
Member
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.
|
Fixed the test failure. |
laanwj
added this to Blockers
in High-priority for review
Sep 21, 2017
| +class BaseRequestHandler | ||
| +{ | ||
| +public: | ||
| + virtual UniValue PrepareRequest(const std::string& strMethod, const std::vector<std::string>& args) = 0; |
| + const int ID_WALLETINFO = 2; | ||
| + | ||
| + /** Create a simulated `getinfo` request. */ | ||
| + UniValue PrepareRequest(const std::string& strMethod, const std::vector<std::string>& args) override |
jnewbery
Sep 22, 2017
Member
nit: function arguments should not be hungarian/camel case strMethod -> method
not currently addressed
| + assert_equal(cli_get_info['paytxfee'], wallet_info['paytxfee']) | ||
| + assert_equal(cli_get_info['relayfee'], network_info['relayfee']) | ||
| + | ||
| + if 'unlocked_until' in wallet_info: |
jnewbery
Sep 22, 2017
Member
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.
|
Addressed nits (sorry for the delay). |
|
Tested ACK 5ca97e5. Thanks for sticking with this! |
| @@ -37,6 +37,7 @@ std::string HelpMessageCli() | ||
| strUsage += HelpMessageOpt("-?", _("This help message")); | ||
| strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), BITCOIN_CONF_FILENAME)); | ||
| strUsage += HelpMessageOpt("-datadir=<dir>", _("Specify data directory")); | ||
| + strUsage += HelpMessageOpt("-getinfo", _("Get general information from the remote server")); |
TheBlueMatt
Sep 27, 2017
Contributor
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).
laanwj
Sep 28, 2017
Owner
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
Sep 28, 2017
•
Contributor
@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....
|
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)"
…
|
laanwj
and others
added some commits
Sep 29, 2016
|
Added the atomicity note to the help text. |
|
utACK 5e69a43 |
laanwj
merged commit 5e69a43
into
bitcoin:master
Sep 28, 2017
1 check passed
added a commit
that referenced
this pull request
Sep 28, 2017
laanwj
removed this from Blockers
in High-priority for review
Sep 28, 2017
QingjingJing
commented
Sep 28, 2017
|
Thanks, helped.
…
|
achow101 commentedJul 18, 2017
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.