Repository navigation
[WIP][Experimental] Add Hybrid full block SPV mode - #9076
jonasschnelli wants to merge 1 commit into
Conversation
|
Possibly dumb question but to be sure I am understanding the change correctly: In pure SPV mode, this will still download and store full blocks for everything after the oldest key-birthday? |
Yes. Right now the |
efd58a0 to
d073718
Compare
|
If a sync is in progress, it can look like this: |
c3cfe1a to
eb13afe
Compare
|
What are major things that need to be done to finalize this change? Are making hybrid SPV mode compatible with pruning, and improving reorg handling critical parts of this change, or would they be future improvements? Looking through the code, there are lots of minor things I could comment on, but I'm assuming I should hold off if you're mainly looking for "conceptual review" right now from core developers (the concept does seems great to me). I do have one piece of feedback, though. Based on my understanding of the change, I think the following flag / feature descriptions might be more comprehensible to users:
I think I like these names more than "hybrid SPV" / "full SPV", just because I think the modern usage of the term "SPV" refers to the wallets that don't download full blocks, don't validate transactions, barely require any storage, and sync almost immediately, and this is not what is implemented in these new modes. I do understand that historically the term SPV refered to a wider variety of network/storage saving schemes, but I don't think it would be good to go back and muddy the more clear modern meaning of what an SPV wallet is. |
Feels free to comment on the minor things directly in the code.
Yes. Seems fine for me. But we just need to make sure that users know that no validation happens on the "prioritized blocks".
Yes. Though I think an expected feature would be to drop the part where we store blocks on the disk when using |
There was a problem hiding this comment.
this is not quite right English and I don't understand what it is saying. Do you mean "we haven't already downloaded this block nor do we have its data"?
"we don't" tends to mean "we should not".
There was a problem hiding this comment.
Thanks, will change.
The bigger cost is that the wallet could end up downloading a completely fake chain, since it isn't anchored to the genesis block. Presumably the client has no idea what block height or difficulty to expect and so evil peers could feed the SPV client minimum difficulty blocks of their own construction containing transactions that don't exist on the main chain. |
ryanofsky
left a comment
There was a problem hiding this comment.
Only about halfway through the diffs, but here are my comments so far (all minor).
There was a problem hiding this comment.
Remove unused split argument?
There was a problem hiding this comment.
Can this be dropped? Number of nodes seems to change during the test.
There was a problem hiding this comment.
Sleep probably deserves comment if sync_spv and sync_blocks (in util.py) aren't enough to be able to remove it.
There was a problem hiding this comment.
Could do vBlocksToDownload(std::move(vBlocksToDownloadIn)) to avoid copying vector.
There was a problem hiding this comment.
Would be nice to name the variable after the command line argument it comes from (currently "-spvonly", possibly something else like "partial sync" in the future).
There was a problem hiding this comment.
Maybe s/check mapBlocksInFlight/exclude blocks in flight/ to be more specific. (I had thought it was doing the opposite the first time reading this).
There was a problem hiding this comment.
Relying on this fHeadersChain argument here is bugging me (the argument is optional and defaults to false), since it seems easy for callers to screw up. I think it would be best to either make it a mandatory argument and/or provide some overload like the following, that would pass in the right value automatically for callers:
bool CheckFinal(const CMerkleTx& mtx, int flags=-1)
{
return CheckFinal(mtx, flags, mtx.fSPV);
}
|
We've done this 6 months ago in Vcash and will be deploying it soon (ZeroLedger). With the extensions we call it SPV+. Let us know if we can help. 👍 |
|
@ryanofsky
Why would your peer reveal information about the age of his keys? We are downloading blocks from different peers and I don't see a possibility to meaningful track ages of the wallets keys because they way of how we retrieve blocks in identical to how we retrieve blocks in standard IBD.
Because we already have downloaded and built the headers-only-chain, all "SPV" downloaded blocks are linked to the genesis block. Though, not through verification, only through a simple PoW/chainwork check. And there are also the checkpoints (though not sure how long). |
|
@john-connor can you post a link to any code you think would be useful please? |
There was a problem hiding this comment.
Maybe this could be called NotifyHeaderTip instead of UpdatedBlockHeaderTip? It doesn't seem good to have two different but confusingly similar names for this.
There was a problem hiding this comment.
New variable seems to be unused. Could you continue to pass null to MarkBlockAsInFlight instead of this? Probably deserves comment if this variable is actually being used in some unseen way.
There was a problem hiding this comment.
Having validated default true seems less safe than having validated default false, or not having a default at all.
Also it seems like validated == !fSpv. Seems like this argument could be changed to an fSpv, or the other fSpv's could be changed to validated variables for more consistency.
There was a problem hiding this comment.
Should be DEFAULT_ENABLE_PURE_SPV
There was a problem hiding this comment.
It'd be good to say what best means in a comment.
There was a problem hiding this comment.
Above you are acquiring a lock when you read the nBestSpvHeight variable. Is it not necessary to have a lock when writing the same variable?
There was a problem hiding this comment.
Is this actually supposed to be bestSPVBlockHeight not nBestSpvHeight? Why compare against previous height instead of current? If this is intended would suggest adding a comment to explain and also renaming bestSPVBlockHeight to previousBestSPVBlockHeight to make clear this is supposed to be the previous height.
There was a problem hiding this comment.
I don't understand in general what the resend wallet transaction code is for, and probably this isn't the place to explain it, but it might be nice to have a comment here saying how the SPV condition relates.
eb13afe to
8414d80
Compare
8414d80 to
96bdeff
Compare
|
Binaries are available here: https://bitcoin.jonasschnelli.ch/pulls/9076/ |
|
@jonasschnelli Conceptually, I'm not for putting the ability to change the node's security model into Core's code base right now. To me, this client should target being a fully validating node. Otherwise, the code will become more complex and difficult to reason about. I hope this does not come across as throwing stones because that's not how I mean it. Coincidentally, I thought a lot about this recently due to work on #9180. That PR effectively created another flavor of a non-fully validating hybrid mode and the feedback in that PR may apply here. If nothing else, this comment will link in that work on another potential hybrid mode possibility if you hadn't seen it already. |
|
@mruddy That's a fair view, and probably one that is shared by some contributors. Let me offer some other perspective, though. I believe that conceptually, in the long term, the Bitcoin Core wallet should be more isolated and separated from the node/consensus logic. I'm unsure what this will mean for organization of code base, but at least it should run as a separate process for security reasons. There is ongoing discussion on how the wallet and node processes should interact, but my view is that they should just use the P2P protocol. The P2P protocol was designed for supporting light wallets, and our server side implementation of it is well tested for this purpose. Apart from questions about mempool tracking and feerate estimation, there is effectively no server side work to accomplish this. I see this PR as a step towards the client side. It's just allowing the wallet code to run with consensus enforcement done in another process. It's different from the checkpoints discussion in that it doesn't result in a node that acts like a full node. |
|
@sipa Thanks for the additional insight. I can see that. The node security model is distinct from the wallet security model. The longer term goal of wallet-node separation seems appealing. I'm still concerned about keeping complexity down while maintaining these logical separations in a single repo. For example, do you think it would be valid feedback for the current patch that changes to ProcessNewBlock and AcceptBlock violate wallet-node code level separation? If the interface between the processes is the P2P protocol, then I think the difference should be handled as separate cases at the P2P level (e.g.- in ProcessMessage). A wallet process may accept P2P block messages and do something with them, but that processing should be way different than what a node process does. If the wallet process was doing all the same work all over again, then the main benefits of the separation would be only run time process/network isolation and perhaps availability. I'm assuming that the wallet-node design evolves so that the wallet process becomes heavily dependent on its trusted node process (which is ok) to determine the validity of and then pass on only valid and possibly filtered blocks and transactions. Why even check the header in the wallet process? Just take what is received from the trusted node, and update the TXO info. Having a designed goal for the wallet process would help giving feedback for this PR because, for example, it may be the case that the wallet only needs to maintain a header chain for re-org handling and then set (maybe bloom) filters in its trusted nodes to get what it needs for TXO management. There could be lots of flag interactions like, for wallet processes, only connect to explicitly designated endpoints rather than trying to find seed nodes, etc... I think a good vision for how the wallet and node should interact would help review this PR. Then questions about code base structure, and whether to keep it all in the same binary or not can be answered. |
|
So is this a step towards being able to run bitcoind as a NETWORK_NODE and run bitcoin-qt as an SPV client connecting to it (and trusting it)? |
|
needs rebase |
|
What would be involved in getting with working with pruned-node ability also? And why not make it download all the headers so that it is at least connect to the genesis block as suggested by @dooglus ? |
|
Closing in favour of #9483 |
work in progress, seeks conceptual review
very experimental right now
This adds a hybrid and pure SPV mode to bitcoin cores wallet (including GUI).
The main out-of-band block requests are handled over the new "lock-free" class
CBlockRequest.This is a generic interface to allow retrieving a range of blocks (only headers PoW check, no validation) and throw them through the
SyncTransaction()signals (could also be useful for ZMQ, etc,).Hybrid mode
Can be enabled by
-spv.If enabled, the wallet tries to download blocks from the depth where the wallet was created (oldest key-birthday). Those requested blocks are getting prioritized in
FindNextBlocksToDownload().Once the next block (in order/sequence) has been retrieved, it gets sent through the
SyncTransaction signal. Those - non-verified transactions will get aspv=trueflag (visible in the GUI as well as over RPC).The blocks are kept on the disk for later verification.
In the background, the IBD/verification is still processing/downloading blocks. Once a transaction was verified by connecting/verifying its block, the SPV flag gets removed from the transaction.
This result in a hybrid full-block SPV mode where the users doesn't need to download more (they later need to verify the blocks near the tip anyways) but its possible to already see incoming transactions and send out coins
Pure SPV
Can be enabled by
-spvonly.Result in not downloading blocks for verification.
Current limitations
Thanks for feedback.