-
Notifications
You must be signed in to change notification settings - Fork 38.7k
wallet: Move restorewallet() logic to the wallet section #23721
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
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
shaavan
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
Wow, this PR was a tough nut to crack! It took me quite a while to understand it thoroughly. That’s why I have attached my notes so that other reviewers might have an easier time reviewing this PR.
I agree with the changes introduced in this PR. Though I have some suggestions that might help improve this PR.
- I suggest you split the PR into two commits: First, introduce the RestoreWallet function, and second, use it.
- Due to the difference introduced in implementation, this snippet of code is getting duplicated. Though I can’t find a solution to avoid this, it also doesn’t feel intuitively correct. Maybe other reviewers might have some suggestions to improve upon it.
Notes:
- Introduced new pure virtual function
restoreWalletinsrc/interfaces/wallet.hfile. This function is then overridden insrc/wallet/interfaces.hfile. - This new function allows the creation of a new wallet using backed-up wallet’s data. For this purpose, it uses the (newly introduced) function RestoreWallet.
- RestoreWallet is defined under
src/wallet/wallet.hfile. This function does preliminary checks for:- If
backup_fileexist. - If first,
wallet_path(i.e., where wallet should be created) is empty, and, second, the directory can be created there.
After these steps, the LoadWallet function is called, creating a wallet variable. Finally, if the wallet variable does not exist (if(!wallet)), thewallet_fileandwallet_pathare removed from the system. Finally, the wallet variable is returned if everything works out correctly.
- If
- The LoadWalletHelper in
src/wallet/rpc/util.cpp, which used to return {wallet, warning} has now been reduced to HandleWalletError. Reason:- This function had two use cases: for
restoreWallet()insrc/wallet/rpc/backup.cppfile, and forloadWallet()insrc/wallet/rpc/wallet.cppfile. - Now, the
restoreWallet()function was updated to use a more suitable RestoreWallet function, andloadWallet()is still using the LoadWallet function. - This change leads to duplicating the following steps for both functions and removing them from the LoadWalletHelper function.
- This function had two use cases: for
DatabaseOptions options;
DatabaseStatus status;
options.require_existing = true;
bilingual_str error;
std::vector<bilingual_str> warnings;
- Finally, this PR introduced some minor changes to the
test/functional/wallet_backup.pyfile:- Changed the assert_raises_rpc_error code from -8 (RPC_INVALID_PARAMETER) to -4 (RPC_WALLET_ERROR)
- Updated code to make the error message more verbose, better explaining the cause of the error.
Currently restorewallet() logic is written in the RPC layer and it can´t be reused by GUI. So it reimplements this in the wallet and interface sections and then, GUI can access it.
|
As a followup, documentation should be updated |
2e5195e to
a3bdbf6
Compare
It also simplifies restorewallet() and loadwallet() RPC error handling.
a3bdbf6 to
62fa61f
Compare
|
ACK 62fa61f |
shaavan
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.
|
None of this is a refactor. Every commit is a behavior change. |
…the wallet section 62fa61f refactor: remove the wallet folder if the restore fails (w0xlt) abbb7ec refactor: Move restorewallet() RPC logic to the wallet section (w0xlt) 4807f73 refactor: Implement restorewallet() logic in the wallet section (w0xlt) Pull request description: Currently `restorewallet()` logic is written in the RPC layer and it can´t be reused by GUI. So it moves this to the wallet section and then, GUI can access it. This is necessary to implement the "Restore Wallet" menu item in the GUI (which is already implemented in bitcoin-core/gui#471 ). This commit also simplifies error handling and adds a new behavior: if the restore fails, the invalid wallet folder is removed. ACKs for top commit: achow101: ACK 62fa61f shaavan: crACK 62fa61f Tree-SHA512: 7ccfbad5943f38616ba0c2dd443c97a4b5bc1f6612dbf5a9e7a0263100aba36671fae929a2e7688442667be394645f44484af137a4802f204a33c4689eb27c39
Currently
restorewallet()logic is written in the RPC layer and it can´t be reused by GUI. So it moves this to the wallet section and then, GUI can access it.This is necessary to implement the "Restore Wallet" menu item in the GUI (which is already implemented in bitcoin-core/gui#471 ).
This commit also simplifies error handling and adds a new behavior: if the restore fails, the invalid wallet folder is removed.