0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-09 10:43:19 -05:00
bitcoin-bitcoin-core/src/wallet
Andrew Chow 360e047a71
Merge bitcoin/bitcoin#26747: wallet: fix confusing error / GUI crash on cross-chain legacy wallet restore
21ad4e26ec test: add coverage for cross-chain wallet restore (Sebastian Falbesoner)
8c7222bda3 wallet: fix GUI crash on cross-chain legacy wallet restore (Sebastian Falbesoner)

Pull request description:

  Restoring a wallet backup from another chain should result in a dedicated error message (we have _"Wallet files should not be reused across chains. Restart bitcoind with -walletcrosschain to override."_ for that). Unfortunately this is currently not the case for legacy wallet restores, as in the course of cleaning up the newly created wallet directory a `filesystem_error` exception is thrown due to the directory not being empty; the wallet database did indeed load successfully (otherwise we wouldn't know that the chain doesn't match) and hence BDB-related files and directories are already created in the wallet directory.

  For bitcoind, this leads to a very confusing error message:
  ```
  $ ./src/bitcoin-cli restorewallet test123 ~/.bitcoin/regtest/wallets/regtest_wallet/wallet.dat
  error code: -1
  error message: filesystem error: in remove: Directory not empty ["/home/thestack/.bitcoin/wallets/test123"]
  ```

  Even worse, the GUI crashes in such a scenario:
  ```
  libc++abi: terminating with uncaught exception of type std::__1::__fs::filesystem::filesystem_error: filesystem error: in remove: Directory not empty ["/home/thestack/.bitcoin/wallets/foobar"]
  Abort trap (core dumped)
  ```

  Fix this by simply deleting the whole folder via `fs::remove_all`. With this, the expected error message appears both for the `restorewallet` RPC call and in the GUI (as a message-box):

  ```
  $ ./src/bitcoin-cli restorewallet test123 ~/.bitcoin/regtest/wallets/regtest_wallet/wallet.dat
  error code: -4
  error message:
  Wallet loading failed. Wallet files should not be reused across chains. Restart bitcoind with -walletcrosschain to override.
  ```

ACKs for top commit:
  achow101:
    ACK 21ad4e26ec
  aureleoules:
    ACK 21ad4e26ec
  furszy:
    utACK 21ad4e26

Tree-SHA512: 313f6494c2fbe823bff9b975cb2d9410bb518977a1e59a5159ee9836bc012947fa50b56be0e41b1a2f50d9c0c7f4fddfdf4fbe479d8a59a6ee44bb389c804abc
2023-01-04 17:46:37 -05:00
..
rpc Merge bitcoin/bitcoin#26795: rpc: Correct RPCHelpMan for fundrawtransaction's input_weights field 2023-01-04 11:09:57 +01:00
test Merge bitcoin/bitcoin#26752: wallet: Remove mempool_sequence from interface methods 2023-01-04 17:53:58 +00:00
bdb.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
bdb.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
coincontrol.cpp Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
coincontrol.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
coinselection.cpp Merge bitcoin/bitcoin#26661: wallet: Coin Selection, return accurate error messages 2023-01-03 18:53:36 -05:00
coinselection.h Merge bitcoin/bitcoin#26661: wallet: Coin Selection, return accurate error messages 2023-01-03 18:53:36 -05:00
context.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
context.h Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
crypter.cpp Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
crypter.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
db.cpp Replace use of ArgsManager with DatabaseOptions 2022-03-16 08:26:28 +01:00
db.h Replace use of ArgsManager with DatabaseOptions 2022-03-16 08:26:28 +01:00
dump.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
dump.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
external_signer_scriptpubkeyman.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
external_signer_scriptpubkeyman.h Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
feebumper.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
feebumper.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
fees.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
fees.h Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
init.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
interfaces.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
ismine.h Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
load.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
load.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
receive.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
receive.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
salvage.cpp Replace use of ArgsManager with DatabaseOptions 2022-03-16 08:26:28 +01:00
salvage.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
scriptpubkeyman.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
scriptpubkeyman.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
spend.cpp Merge bitcoin/bitcoin#26661: wallet: Coin Selection, return accurate error messages 2023-01-03 18:53:36 -05:00
spend.h Merge bitcoin/bitcoin#26661: wallet: Coin Selection, return accurate error messages 2023-01-03 18:53:36 -05:00
sqlite.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
sqlite.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
transaction.cpp Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
transaction.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
wallet.cpp Merge bitcoin/bitcoin#26747: wallet: fix confusing error / GUI crash on cross-chain legacy wallet restore 2023-01-04 17:46:37 -05:00
wallet.h Merge bitcoin/bitcoin#26752: wallet: Remove mempool_sequence from interface methods 2023-01-04 17:53:58 +00:00
walletdb.cpp Merge bitcoin/bitcoin#26702: refactor: walletdb: drop unused FindWalletTx parameter and rename 2023-01-03 11:54:51 -05:00
walletdb.h Merge bitcoin/bitcoin#26702: refactor: walletdb: drop unused FindWalletTx parameter and rename 2023-01-03 11:54:51 -05:00
wallettool.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
wallettool.h Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
walletutil.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
walletutil.h Implement LegacyScriptPubKeyMan::MigrateToDescriptor 2022-08-25 16:25:53 -04:00