8000 rpc: Add getindexinfo RPC by fjahr · Pull Request #19550 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

rpc: Add getindexinfo RPC #19550

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 20, 2020
Merged

rpc: Add getindexinfo RPC #19550

merged 3 commits into from
Aug 20, 2020

Conversation

fjahr
Copy link
Contributor
@fjahr fjahr commented Jul 18, 2020

As I was playing with indices a I was missing an RPC that gives information about the active indices in the node. I think this can be helpful for many users, especially since there are some new index candidates coming up (#14053, #18000) that can give a quick overview without the user having to parse the logs.

Feature summary:

  • Adds new RPC getindexinfo (placed in Util section)
  • That RPC only lists the actively running indices
  • For each index it gives the name, whether it is synced and up to which block height it is synced

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.

Concept ACK, why not? This can help the client determine whether the node is capable for it's needs.

Instead of returning an array, it could return an object { name: summary }, or duplicate index names are allowed?

@DrahtBot
Copy link
Contributor
DrahtBot commented Jul 19, 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.

Copy link
Member
@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Concept ACK, thanks for adding the test.

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.

review ACK, only style nits

@theStack
Copy link
Contributor

Concept ACK

@fjahr
Copy link
Contributor Author
fjahr commented Jul 19, 2020

Thanks for the reviews, I should have addressed all the comments:

  • Now returning an object with the index names as keys (names are not enforced to be unique by the code at the moment I think but the names are used to distinguish the indices in the logs so they should be unique).
  • Cherry-picked the commit that makes wait_until part of the TestFramework and used it
  • Used new RPC constructor
  • Not passing around results object anymore
  • Fixed includes sorting

@laanwj
Copy link
Member
laanwj commented Jul 22, 2020

Tested ACK f301c86
(tested with and without -txindex on regtest)

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.

Code review ACK f301c86, needs release notes.

@jonasschnelli
Copy link
Contributor

I think this is a helpful addition for connecting applications.
Code Review utACK f301c86.

@jonatack
Copy link
Member

The first commit is already merged in master. The change was embedded into commit 12410b1. Reviewing the main commit now.

@fjahr
Copy link
Contributor Author
fjahr commented Jul 25, 2020

Added const usage and research notes. Dropped first commit and rebased on master.

Copy link
Member
@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

ACK 3785cfd code review, debug build/tests, tested the RPC and its help.

return results;
},
};
}
Copy link
Member

Choose a reason for hiding this comment

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

Indentation, could clang-format listindices() if you retouch -- see details for an idea.

clang-format -i src/rpc/misc.cpp

 static RPCHelpMan listindices()
 {
-    return RPCHelpMan{"listindices",
-                "\nReturns the available indices and their status.\n",
-                {},
-                RPCResult{
-                    RPCResult::Type::OBJ, "", "", {
-                        {
-                            RPCResult::Type::OBJ, "name", "The name of the index",
-                            {
-                                {RPCResult::Type::BOOL, "synced", "Whether the index is synced or not"},
-                                {RPCResult::Type::NUM, "best_block_height", "The block height to which the index is synced"},
-                            }
-                        },
-                    },
-                },
-                RPCExamples{
-                    HelpExampleCli("listindices", "")
-                },
-                [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
-{
-    UniValue results(UniValue::VOBJ);
+    return RPCHelpMan{
+        "listindices",
+        "\nReturns the available indices and their status.\n",
+        {},
+        RPCResult{
+            RPCResult::Type::OBJ,
+            "",
+            "",
+            {
+                {RPCResult::Type::OBJ, "name", "The name of the index", {
.../...
+            },
+        },
+        RPCExamples{HelpExampleCli("listindices", "")},
+        [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
+            UniValue results(UniValue::VOBJ);
 
-    if (g_txindex) {
-        results.pushKVs(SummaryToJSON(g_txindex->GetSummary()));
-    }
+            if (g_txindex) {
+                results.pushKVs(SummaryToJSON(g_txindex->GetSummary()));
+            }
 
-    ForEachBlockFilterIndex([&results](BlockFilterIndex& index) {
-        results.pushKVs(SummaryToJSON(index.GetSummary()));
-    });
+            ForEachBlockFilterIndex([&results](BlockFilterIndex& index) {
+                results.pushKVs(SummaryToJSON(index.GetSummary()));
+            });
 
-    return results;
-},
+            return results;
+        },
     };
 }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have chosen this indentation to keep it consistent with https://github.com/bitcoin/bitcoin/pull/19528/files

@fjahr
Copy link
Contributor Author
fjahr commented Jul 25, 2020

Also fixed initializations are proposed by @jonatack . I am leaving the indentation as is since it is consistent with #19528 and the suggested change from clang-format seem pretty different from our general formatting for RPCs so far.

@jonatack
Copy link
Member

Code review re-ACK 28b4cbf per git diff 3785cfd 28b4cbf

Thanks, and sorry about that; I'm not sure the default initialization is useful in this case and in non-critical code, though I guess it can't hurt. When I saw this catch today that I had missed in my own review, I resolved to reinforce my thinking about this.

@jonatack
Copy link
Member
jonatack commented Jul 26, 2020

I was thinking getindexstatus [index], with optional index parameter - if null/omitted returns all indices.

Or getindexinfo.

Per bitcoin-cli help | grep "info\|list", "list" RPCs seem to deal with user-side financial data, and "info" RPCs are more for technical-side settings and might make more sense here.

RPCs are hard to change once released, so it seems a good idea to get them right.

@fjahr
Copy link
Contributor Author
fjahr commented Jul 28, 2020

Thanks for the suggestions! Honestly, I was a bit on the fence on the naming of this RPC anyway and since there were two reviewers in favor of this renaming and none against, I have implemented it now as getindexinfo. It also takes an index name now as suggested. Sorry reviewers, most of the code has changed now.

Please note this trade-off in the code currently: Even when an index name (even an incorrect one) is given, it will still get the status for all/both indices internally. That could be easily fixed by matching the index name param against a set of index names allowed. While less efficient, the upside of the current approach is it uses fewer LOC and that it has more flexibility in the sense that it will automatically work if a new (custom?) block filter index is introduced. I think this is ok since an internal optimization can still be done later. I am thinking of something like an IndexMan or so to encapsulate that logic better for when we have more indices in the future. But of course, I can still change this now if that is preferred.

I also went back on passing the result around, it seemed cleaner this way now. And squashed into one commit.

@promag
Copy link
Contributor
promag commented Jul 28, 2020

You may want to update PR title.

@fjahr fjahr changed the title rpc: Add listindices RPC rpc: Add getindexinfo RPC Jul 28, 2020
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.

Not sure if the format should be different if an index is specified. And if the specified index is unknown (either invalid or just because it's not available) then the resulting object would be {}. No strong opinion though.

@jonatack
Copy link
Member

Not sure if the format should be different if an index is specified. And if the specified index is unknown (either invalid or just because it's not available) then the resulting object would be {}. No strong opinion though.

This was my first thought as well: if an index is specified, ISTM the output should give feedback on the index that it understood (by displaying it, the same as when no index is specified). I'll review properly tomorrow, so don't give this comment too much weight yet.

Copy link
Member
@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

ACK in general, with some suggestions.

Perhaps the param would best be named index, for what it is, rather than name. See the param names of the other MiscRPCCommands.

Perhaps it would be better to return the same output for one index, as for all indexes when only one index is active, thereby providing feedback that the RPC correctly understood the passed index.

Based on what most of the other PRs being merged are doing (see just-merged https://github.com/bitcoin/bitcoin/pull/19473/commits), I don't think you are required to squash this into one single commit as long as they are hygienic. The more frequent pattern for this change would seem to be one commit for the change, one for the tests, and one for the release note.

@fjahr
Copy link
Contributor Author
fjahr commented Jul 31, 2020

Pushed the changes as requested. I understand now the name parameter was more thought of like a filter so I documented it as such. I also renamed it to index_name which is consistent with wallet_name which seemed the most comparable.

Copy link
Member
@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

ACK dc888cd with a question for the help

@fjahr
Copy link
Contributor Author
fjahr commented Aug 1, 2020

Addressed review comments by @jonatack

Copy link
Member
@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Code review re-ACK 47a5372 per git diff dc888cd 47a5372 🐎

luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Aug 15, 2020
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Aug 15, 2020
Copy link
Member
@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Code review re-ACK 124e1ee per git range-diff a57af89 47a5372 124e1ee no change since my last re-ACK, rebase only

@laanwj
Copy link
Member
laanwj commented Aug 20, 2020

Re-ACK 124e1ee

@laanwj laanwj merged commit 27eeb03 into bitcoin:master Aug 20, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 20, 2020
124e1ee doc: Add release notes for getindexinfo RPC (Fabian Jahr)
c447b09 test: Add tests for getindexinfo RPC (Fabian Jahr)
667bc7a rpc: Add getindexinfo RPC (Fabian Jahr)

Pull request description:

  As I was playing with indices a I was missing an RPC that gives information about the active indices in the node. I think this can be helpful for many users, especially since there are some new index candidates coming up (bitcoin#14053, bitcoin#18000) that can give a quick overview without the user having to parse the logs.

  Feature summary:
  - Adds new RPC `listindices` (placed in Util section)
  - That RPC only lists the actively running indices
  - For each index it gives the name, whether it is synced and up to which block height it is synced

ACKs for top commit:
  laanwj:
    Re-ACK 124e1ee
  jonatack:
    Code review re-ACK 124e1ee per `git range-diff a57af89 47a5372 124e1ee` no change since my last re-ACK, rebase only

Tree-SHA512: 3b7174c87951e6457fef099f530337803906baf32fb64261410b8def2c0917853d6a1bf3059cd590b1cc1523608f8916dafb327a431d27ecbf8d7454406b5b35
domob1812 added a commit to domob1812/namecoin-core that referenced this pull request Aug 24, 2020
Extend upstream bitcoin/bitcoin#19550 to
support also the namehash index.
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 15, 2021
Summary: This is a backport of [[bitcoin/bitcoin#19550 | core#19550]]

Test Plan: `ninja check-functional`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10118
@bitcoin bitcoin locked as resolved and limited conversation to collaborators 7E4F 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
0