Skip to content

Conversation

@w0xlt
Copy link
Contributor

@w0xlt w0xlt commented Dec 9, 2021

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 9, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23497 (Add src/node/ and src/wallet/ code to node:: and wallet:: namespaces by ryanofsky)

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.

Copy link
Contributor

@shaavan shaavan left a 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.

  1. I suggest you split the PR into two commits: First, introduce the RestoreWallet function, and second, use it.
  2. 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 restoreWallet in src/interfaces/wallet.h file. This function is then overridden in src/wallet/interfaces.h file.
  • 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.h file. This function does preliminary checks for:
    1. If backup_file exist.
    2. 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)), the wallet_file and wallet_path are removed from the system. Finally, the wallet variable is returned if everything works out correctly.
  • The LoadWalletHelper in src/wallet/rpc/util.cpp, which used to return {wallet, warning} has now been reduced to HandleWalletError. Reason:
    1. This function had two use cases: for restoreWallet() in src/wallet/rpc/backup.cpp file, and for loadWallet() in src/wallet/rpc/wallet.cpp file.
    2. Now, the restoreWallet() function was updated to use a more suitable RestoreWallet function, and loadWallet() is still using the LoadWallet function.
    3. This change leads to duplicating the following steps for both functions and removing them from the LoadWalletHelper function.
    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.py file:
    1. Changed the assert_raises_rpc_error code from -8 (RPC_INVALID_PARAMETER) to -4 (RPC_WALLET_ERROR)
    2. 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.
@Rspigler
Copy link
Contributor

As a followup, documentation should be updated

@w0xlt w0xlt force-pushed the restore_wallet_gui branch 4 times, most recently from 2e5195e to a3bdbf6 Compare December 15, 2021 14:48
@w0xlt w0xlt force-pushed the restore_wallet_gui branch from a3bdbf6 to 62fa61f Compare December 15, 2021 21:59
@achow101
Copy link
Member

ACK 62fa61f

Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crACK 62fa61f

Great work, @w0xlt!

@maflcko maflcko merged commit a306429 into bitcoin:master Dec 16, 2021
@maflcko maflcko changed the title wallet, refactor: Move restorewallet() logic to the wallet section wallet: Move restorewallet() logic to the wallet section Dec 16, 2021
@maflcko
Copy link
Member

maflcko commented Dec 16, 2021

None of this is a refactor. Every commit is a behavior change.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 16, 2021
…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
@w0xlt w0xlt deleted the restore_wallet_gui branch December 16, 2021 18:19
@bitcoin bitcoin locked and limited conversation to collaborators Dec 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants