-
Notifications
You must be signed in to change notification settings - Fork 38.7k
rpc: Prevent unloading a wallet when rescanning #26618
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
rpc: Prevent unloading a wallet when rescanning #26618
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
stickies-v
left a comment
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.
Current behaviour seems to be that unloadwallet waits until the scan is finished. Changing that by throwing could affect downstream users that are expecting unloadwallet to just wait. I think the behaviour in this PR is better if it were implemented like that from the start. I'm not sure if it's worth changing though? ~0 on this for now.
ishaanam
left a comment
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.
Current behaviour seems to be that unloadwallet waits until the scan is finished.
This is what I have observed as well. Even so, I think that it would be better if instead of waiting for the rescan to finish (which could take hours), CWallet::AbortRescan is called from unloadwallet. This seems better because unloadwallet should ideally be able to unload the wallet relatively quickly regardless of the processes that the wallet is running. A warning could be given when a rescan has been aborted by unloadwallet so that a user is not surprised.
Do you know any software that would use this behavior? I understand this could affect users but this seems a bit hacky.
I don't really have an opinion on this. But an argument for keeping the warning in 8198c76a3008094fefbbae1b11e5d5673a993158 is that an user may not realize that the wallet is still rescanning and wouldn't want to abort it when trying to unload. |
I think this is a good approach. |
|
Agree with a force option (named only / options Object). But also, we probably shouldn't return from I guess this PR is strictly better than the current behaviour, though, so Concept ACK. |
8198c76 to
bee026e
Compare
|
I added the named |
bee026e to
2567ffc
Compare
promag
left a comment
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.
Tiny concept NACK.
I think unloadwallet should just fail if a scan is in progress. We already have that behavior/warning elsewhere: Wallet is currently rescanning. Abort existing rescan or wait. I understand it can be seen as a breaking change, but makes more sense than what happened in #26463.
Regardless of the above, the current code is still not ideal, for instance, a scan can be initiated after IsScanning check if importdescriptors is called concurrently. I think you should use WalletRescanReserver because it allows checking if a rescan is in progress and at the same time prevent concurrent scans.
A test case would be nice.
|
Thanks for fixing this issue. I like the approach more where we just fail the
Definitly important to prevent bitcoind from crashing. I was able to bring bitcoind down when unloading the wallet (blocking in the background) deleting the walletdir and then importing the descriptors with the same wallet name again (an then there was a dependence that one sync finished before the other). So would be important if we would not allow loading a wallet which is currently in rescan (at least not with the same name). |
2567ffc to
3f31949
Compare
|
I have decided to remove to force option and only leave a warning in case there is a rescan. To me it's simpler and faster to type
Done, thanks. |
promag
left a comment
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.
Concept ACK, unloadwallet fails if a rescan is in progress. Needs:
- release notes
- test, not sure how
- follow-up in the GUI
3f31949 to
8aa324e
Compare
8aa324e to
109cbb8
Compare
|
Thanks, @promag. I added release notes. I think the test should be a follow-up as there are many other instances where this warning is not tested. |
The general rule of thumb is that tests are added when there are changes. |
I agree but the RPC error I'll look into adding a test though. |
|
My suggestion is to test the just introduced error, the other are indeed out of scope. |
|
Is it conceptionally possible to abort the rescan, if the wallet_dir is deleted (manually with rm -f wallet_dir)? My tests showed me that bitcoind will happily rescan further ? Or is it somehow a user-misbehaving we should not take into account ? |
|
@ziggie1984 user-misbehaving |
|
Yeah, I would think deleting data files out from under the software should be expected to crash ;) |
w0xlt
left a comment
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.
ACK 109cbb8
kouloumos
left a comment
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.
ACK 109cbb8
The implementation is consistent with how the WalletRescanReserver is used in the rest of the related RPCs as pointed out in #26618 (review) .
(check the rest of the RPCs with git grep -n "Wallet is currently rescanning. Abort existing rescan or wait")
I would also prefer to see a test as part of this PR, but looking at the linked draft PR implementation it seems that the relative complexity to include a test (other test cases missing, refactor of an existing test file) justifies a follow-up.
promag
left a comment
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.
ACK 109cbb8
|
ACK 109cbb8 |
…canning 109cbb8 doc: Add release notes for #26618 (Aurèle Oulès) b13902d rpc: Prevent unloading a wallet when rescanning (Aurèle Oulès) Pull request description: Fixes #26463. This PR prevents a user from unloading a wallet if it is currently rescanning. To test: ```bash ./src/bitcoin-cli -testnet -named createwallet wallet_name=wo disable_private_keys=true ./src/bitcoin-cli -testnet -rpcwallet=wo importdescriptors '[{ "desc": "addr(mmcuW74MyJUZuLnWXGQLoNXPrS9RbFz6gD)#tpnrahgc", "timestamp": 0, "active": false, "internal": false, "next": 0 }]' ./src/bitcoin-cli -testnet unloadwallet wo error code: -4 error message: Wallet is currently rescanning. Abort existing rescan or wait. ACKs for top commit: achow101: ACK 109cbb8 w0xlt: ACK bitcoin/bitcoin@109cbb8 kouloumos: ACK 109cbb8 promag: ACK 109cbb8 Tree-SHA512: 15fdddf4cf9f3fa08f52069fe4a25a76e04a55bb2586b031bfb0393dce7f175dcdb52823e132a7dff6a894539beeb980a1aad2a792790be036be6977628149b2
|
This was merged |
109cbb8 doc: Add release notes for bitcoin#26618 (Aurèle Oulès) b13902d rpc: Prevent unloading a wallet when rescanning (Aurèle Oulès) Pull request description: Fixes bitcoin#26463. This PR prevents a user from unloading a wallet if it is currently rescanning. To test: ```bash ./src/bitcoin-cli -testnet -named createwallet wallet_name=wo disable_private_keys=true ./src/bitcoin-cli -testnet -rpcwallet=wo importdescriptors '[{ "desc": "addr(mmcuW74MyJUZuLnWXGQLoNXPrS9RbFz6gD)#tpnrahgc", "timestamp": 0, "active": false, "internal": false, "next": 0 }]' ./src/bitcoin-cli -testnet unloadwallet wo error code: -4 error message: Wallet is currently rescanning. Abort existing rescan or wait. ACKs for top commit: achow101: ACK 109cbb8 w0xlt: ACK bitcoin@109cbb8 kouloumos: ACK 109cbb8 promag: ACK 109cbb8 Tree-SHA512: 15fdddf4cf9f3fa08f52069fe4a25a76e04a55bb2586b031bfb0393dce7f175dcdb52823e132a7dff6a894539beeb980a1aad2a792790be036be6977628149b2
Fixes #26463.
This PR prevents a user from unloading a wallet if it is currently rescanning.
To test: