-
Notifications
You must be signed in to change notification settings - Fork 813
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
wallet rescan: Add error for SPV mode and excessive depth in pruned mode #532
Conversation
Needs a rebase to fix tests. |
Rebased. Tests successful on local. Think I will want to add one more commit to check prune height against |
Codecov Report
@@ Coverage Diff @@
## master #532 +/- ##
==========================================
+ Coverage 53.33% 53.51% +0.17%
==========================================
Files 104 104
Lines 27676 27696 +20
Branches 4738 4740 +2
==========================================
+ Hits 14761 14821 +60
+ Misses 12915 12875 -40
Continue to review full report at Codecov.
|
I saw |
I think I noticed that too. The command times out but the reset continues until it's done in the background. |
Adding to this conversation: There should be an error if a pruned node is asked to rescan beyond it's prune depth. I have a tx in my wallet that is stored as What happened, I think, is that I executed |
UPDATE: This PR now adds an important error if wallet rescan is attempted on a pruned node with a depth greater than the number of blocks on disk. A new test file was added This PR also updates the regtest block parameters around pruning to make testing more practical: --- a/lib/protocol/networks.js
+++ b/lib/protocol/networks.js
@@ -775,8 +775,8 @@ regtest.block = {
bip65hash: null,
bip66height: 1251,
bip66hash: null,
- pruneAfterHeight: 1000,
- keepBlocks: 10000,
+ pruneAfterHeight: 500,
+ keepBlocks: 288,
maxTipAge: 0xffffffff,
slowHeight: 0
}; |
lib/wallet/http.js
Outdated
const valid = Validator.fromRequest(req); | ||
const height = valid.u32('height'); | ||
|
||
// Pruned node can only rescan the blocks it has on disk | ||
if (this.options.node.rpc.client.node.chain.options.prune) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two modes in wallet:
- Wallet as a plugin, in which case
lib/wallet/plugin
is being called that initializes the wallet - Wallet is run as a separate server, in which case
lib/wallet/node
is the main file that does all that.
Even if in the first case this "can" be a way to get information about the node that wallet is communicating with, this data wont be there for Wallet that is running as a separate service.
Also wallet as a separate service sometimes might change the node it is communicating with. It might be fullnode
one time and pruned
another time or spv
.
So I think, when establishing connection we should communicate with node and add admin
endpoint where we will grab the meta information we are interested about. (We need to think this through though, what else is interesting and can be used in the future).
rebased on master, testing against |
@nodar-chkuaselidze @braydonf Did some updates:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and reviewed.
Tests are failing on timeouts generating blocks again, hm seems like sometimes it does sometimes it doesn't... |
NICE! Little rebase-on-master fixed the testing issue |
Adding a TODO here that my tests should not be using |
Ok this PR got a little long, but I think it's in great shape now. Going to put a recap in this comment: Motivation: Wallet can not rescan an SPV chain at all. Pruned nodes can only rescan the limited number of blocks on disk. In the case of a pruned node, rescanning beyond the depth of the chain stored on disk means transactions will be marked as "unconfirmed" forever. Solution: Wallet asks chain what its properties are and throws an error in either case described. Method:
|
In SPV mode,
rescan
doesn't actually do anything. If a user creates a watch-only wallet by importing anxpub
while in SPV mode, that wallet will not necessarily be in sync with the chain. Unlike fullnode, arescan
will not sync the wallet. This PR adds an error that redirects the user toreset
which, in SPV mode at least, should not take too long and will discover any wallet transactions that occurred before the import point.This issue also applies to pruned nodes, if historical transactions for the imported address were confirmed before the prune height. However a pruned node can not
reset
. We could expand the error to cover pruned nodes as well.We might also want to add a note in the docs that importing keys into a pruned node may not correctly recover those keys' blockchain history.
Or... is it possible to enable
reset
on a pruned node?