Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Add simple light-client mode (RPC only) #10794
Conversation
jonasschnelli
added P2P Validation
labels
Jul 11, 2017
jonasschnelli
referenced
this pull request
Jul 11, 2017
Closed
Introduce auxiliary block requests #9171
|
Contains overhauled parts from #9483 |
|
I'd like to help out here, and I've spent literally days reviewing previous iterations of this change (#9076 #9483 #9171), but I can't figure out if this is going anywhere and if providing more review now is a good use of time. As I've mentioned previously, I don't think the auxiliary block download class design is great, because it duplicates functionality from the networking layer in a wholly different part of the code, and gives the wallet too much control & responsibility over low level p2p details in the case where it's used to let the wallet code prioritize which blocks to download. I've tried to describe what I think would be better alternatives in my previous review comments, like #9483 (comment). @jonasschnelli, assuming you don't want to take my previous suggestions, and do want to stick with the current design, I think it would be helpful if you could reach out to some other reviewers and get some concept acks for your current approach. It might help to put together some kind of design document, or at least a detailed comment to the top of |
|
@ryanofsky:
|
fanquake
deleted a comment
from MIGUELWAXX
Jul 11, 2017
|
Followed yesterdays discussion we had in #bitcoin-core-dev. Removed the This PR now also adds a new signal The scope of this PR is not to make the block download interface flexible for multiple "users" (like the validation and eventually the light-client wallet). |
|
fixed @ryanofsky points. |
ryanofsky
reviewed
Jul 20, 2017
Change seems pretty straightforward. Main thing missing is a test for the new RPC call.
It would be useful to get concept ACKs from @gmaxwell and @sipa to make sure concerns from the earlier design discussion (https://botbot.me/freenode/bitcoin-core-dev/msg/88437543/) are addressed now.
I don't have a very clear idea of how this functionality is going to be used, and what future plans for it are, so I personally wouldn't mind seeing a list of what the next steps & future prs might look like, or knowing some applications that could use the new option & RPC. But probably these things are clearer to others.
|
Thanks @ryanofsky. Agree about required conceptual ACKs from other devs. |
jonasschnelli
added
to In progress in Client-Mode (SPV)
Jul 21, 2017
ryanofsky
reviewed
Jul 24, 2017
utACK 1794a11. Change looks great: code & test are straightforward and commit history is well thought out.
I still can't figure out if new RPC is actually supposed to be useful for something other than debugging/testing. Seems fine if it isn't, though, because it's a simple wrapper around the functions for downloading blocks of order, which obviously are useful for SPV.
| @@ -311,7 +314,11 @@ void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) { | ||
| // Requires cs_main. | ||
| // Returns a bool indicating whether we requested this block. |
ryanofsky
Jul 24, 2017
Contributor
In commit "Add priority block request queue"
Should update comment for new return value
| @@ -466,9 +478,18 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<con | ||
| // Make sure pindexBestKnownBlock is up to date, we'll need it. | ||
| ProcessBlockAvailability(nodeid); | ||
| + if (!blocksToDownloadFirst.empty()) { | ||
| + for (auto& kv : blocksToDownloadFirst) { |
| @@ -640,6 +644,7 @@ UniValue getblockheader(const JSONRPCRequest& request) | ||
| "{\n" | ||
| " \"hash\" : \"hash\", (string) the block hash (same as provided)\n" | ||
| " \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n" | ||
| + " \"validated\" : n, (boolean) True if the block has been validated (for priority block requests)\n" |
ryanofsky
Jul 24, 2017
Contributor
In commit "Add requestblocks - a simple way to priorize block downloads"
Maybe drop part of comment in parentheses, seems to imply value will be true for priority block requests.
| + { | ||
| + if (request.params.size() < 2) | ||
| + throw JSONRPCError(RPC_INVALID_PARAMETER, "Missing blocks array"); | ||
| + UniValue hash_Uarray = request.params[1].get_array(); |
ryanofsky
Jul 24, 2017
Contributor
In commit "[RPC] Add requestblocks - a simple way to priorize block downloads"
Copy is redundant, get_array just returns reference to *this.
| + throw JSONRPCError(RPC_INVALID_PARAMETER, "Missing blocks array"); | ||
| + UniValue hash_Uarray = request.params[1].get_array(); | ||
| + if (!hash_Uarray.isArray()) | ||
| + throw JSONRPCError(RPC_INVALID_PARAMETER, "Second parameter must be an array"); |
ryanofsky
Jul 24, 2017
Contributor
In commit "[RPC] Add requestblocks - a simple way to priorize block downloads"
Can never happen, get_array call above would have thrown if the hash_Uarray / params[1] value was not an array
| + BlockMap::iterator mi = mapBlockIndex.find(hash); | ||
| + if (mi == mapBlockIndex.end()) | ||
| + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | ||
| + blocksToDownload.push_back((*mi).second); |
ryanofsky
Jul 24, 2017
Contributor
In commit "[RPC] Add requestblocks - a simple way to priorize block downloads"
Probably should write mi->second
|
Overhauled and fixed @ryanofsky points (mostly nits), also removed the new (unused) signal. |
ryanofsky
reviewed
Jul 25, 2017
utACK 9723672. Changes since last review were dropping a commit that added a BlockProcessed signal, changing order of other commits, changing brace styles, and making various suggested tweaks.
| + return ret; | ||
| + } | ||
| + else if (request.params[0].get_str() == "add") { | ||
| + if (request.params.size() < 2) { |
ryanofsky
Jul 25, 2017
Contributor
In commit "[RPC] Add requestblocks - a simple way to priorize block downloads"
Don't really need this check, because the get_array call below will trigger it's own error about the value not being an array. But if you prefer this error, you should change the check to request.params[1].isNull() to avoid making a distinction between a null and a missing value (#10281, #10783).
|
Overhauled first commit to make sure we request blocks in order: |
This is now tested on my SPV branch and could be the first reviewable step towards light clients / wallet process separation. |
jonasschnelli commentedJul 11, 2017
•
edited
This adds a simple light client mode (RPC only, no wallet support).
With this PR, It is possible to disable auto-request-blocks by passing in
-autorequestblocks=0.In that mode, one can request out-of-band blocks by calling
requestblock add ["<blockhash>", ...].Those blocks will then be requested/downloaded and can be loaded via
getblock(and they will also be passed through ZMQ).This allows a very simple light-client mode ideally when you already have a validated peer in your trusted network.
This is also a reviewable step towards light client mode for the wallet (which will ultimately allow process separation o the wallet).