0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-21 12:22:50 -05:00
bitcoin-bitcoin-core/src/wallet/test
Andrew Chow de3c46c938
Merge bitcoin/bitcoin#25272: wallet: guard and alert about a wallet invalid state during chain sync
9e04cfaa76 test: add coverage for wallet inconsistent state during sync (furszy)
77de5c693f wallet: guard and alert about a wallet invalid state during chain sync (furszy)

Pull request description:

  Follow-up work to my comment in #25239.

  Guarding and alerting the user about a wallet invalid state during chain synchronization.

  #### Explanation
  if the `AddToWallet` tx write fails, the method returns a wtx `nullptr` without removing the recently added transaction from the wallet's map.

  Which makes that `AddToWalletIfInvolvingMe` return false (even when the tx is on the wallet's map already), --> which makes `SyncTransaction` skip the `MarkInputsDirty` call --> which leads to a wallet invalid state where the inputs of this new transaction are not marked dirty, while the transaction that spends them still exist on the in-memory wallet tx map.

  Plus, as we only store the arriving transaction inside `AddToWalletIfInvolvingMe` when we synchronize/scan block/s from the chain and nowhere else, it makes sense to treat the transaction db write error as a runtime error to notify the user about the problem. Otherwise, the user will lose all the not stored transactions after a wallet shutdown (without be able to recover them automatically on the next startup because the chain sync would be above the block where the txs arrived).

  Note:
  On purpose, the first commit adds test coverage for it. Showing how the wallet can end up in an invalid state. The second commit corrects it with the proposed solution.

ACKs for top commit:
  achow101:
    re-ACK 9e04cfaa76
  jonatack:
    ACK 9e04cfaa76

Tree-SHA512: 81f765eca40547d7764833d8ccfae686b67c7728c84271bc00dc51272de643dafc270014079dcc9727b47577ba67b340aeb5f981588b54e69a06abea6958aa96
2022-08-02 14:06:03 -04:00
..
fuzz interfaces, refactor: Add more block information to block connected notifications 2022-07-18 13:39:55 -05:00
availablecoins_tests.cpp test: add unit test for AvailableCoins 2022-07-19 18:42:21 +02:00
coinselector_tests.cpp refactor: use CoinsResult struct in SelectCoins 2022-07-19 15:30:57 +02:00
db_tests.cpp Disallow more unsafe string->path conversions allowed by path append operators 2022-04-21 12:01:00 -05:00
init_test_fixture.cpp Disallow more unsafe string->path conversions allowed by path append operators 2022-04-21 12:01:00 -05:00
init_test_fixture.h Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
init_tests.cpp Replace use of ArgsManager with DatabaseOptions 2022-03-16 08:26:28 +01:00
ismine_tests.cpp Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
psbt_wallet_tests.cpp doc: Delete old line of code that was commented out 2022-03-16 19:33:52 +00:00
scriptpubkeyman_tests.cpp Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
spend_tests.cpp send: refactor CreateTransaction flow to return a BResult<CTransactionRef> 2022-07-08 11:18:35 -03:00
util.cpp wallet: Save wallet scan progress 2022-06-23 17:13:40 -03:00
util.h Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
wallet_crypto_tests.cpp refactor: use Span in random.* 2022-03-23 17:36:33 -05:00
wallet_test_fixture.cpp wallet: move Assert() check into constructor 2022-03-30 17:07:28 +10:00
wallet_test_fixture.h wallet: move Assert() check into constructor 2022-03-30 17:07:28 +10:00
wallet_tests.cpp Merge bitcoin/bitcoin#25272: wallet: guard and alert about a wallet invalid state during chain sync 2022-08-02 14:06:03 -04:00
wallet_transaction_tests.cpp Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
walletdb_tests.cpp Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00