1792 Commits

Author SHA1 Message Date
merge-script
d20f10affb
Merge bitcoin/bitcoin#33268: wallet: Identify transactions spending 0-value outputs, and add tests for anchor outputs in a wallet
113a4228229baedda2a730e097f2d59ad58a4b0d wallet: Add m_cached_from_me to cache "from me" status (Ava Chow)
609d265ebc51abfe9a9ce570da647b6839dc1214 test: Add a test for anchor outputs in the wallet (Ava Chow)
c40dc822d74aea46e4a21774ca282e008f609c2a wallet: Throw an error in sendall if the tx size cannot be calculated (Ava Chow)
39a7dbdd277d1dea9a70314d8cc5ae057999ee88 wallet: Determine IsFromMe by checking for TXOs of inputs (Ava Chow)
e76c2f7a4111f87080e31539f83c21390fcd8f3b test: Test wallet 'from me' status change (Ava Chow)

Pull request description:

  One of the ways that the wallet would determine if a transaction was sent from the wallet was by checking if the total amount being spent by a transaction from outputs known to the wallet was greater than 0. This has worked fine until recently since there was no reason for 0-value outputs to be created. However, with ephemeral dust and P2A, it is possible to create standard 0-value outputs, and the wallet was not correctly identifying the spends of such outputs. This PR updates `IsFromMe` to only check whether the wallet knows any of the inputs, rather than checking the debit amount of a transaction.

  Additionally, a new functional test is added to test for this case, as well as a few other anchor output related scenarios. This also revealed a bug in `sendall` which would cause an assertion error when trying to spend all of the outputs in a wallet that has anchor outputs.

  Fixes #33265

ACKs for top commit:
  rkrux:
    lgtm ACK 113a4228229baedda2a730e097f2d59ad58a4b0d
  enirox001:
    Tested ACK 113a422. Ran the full functional test suite including `wallet_anchor.py`; all tests passed. Fix for 0 value anchor detection and sendall size errors looks good. LGTM.
  furszy:
    ACK 113a4228229baedda2a730e097f2d59ad58a4b0d

Tree-SHA512: df2ce4b258d1875ad0b4f27a5b9b4437137a5889a7d5ed7fbca65f904615e9572d232a8b8d070760f75ac168c1a49b7981f6b5052308575866dc610d191ca964
2025-09-12 14:42:08 +01:00
Ava Chow
591eea7b5a
Merge bitcoin/bitcoin#33082: wallet, refactor: Remove Legacy check and error
d3c5e47391e2f158001e3e199d625852c7f18998 wallet, refactor: Remove Legacy check and error (pablomartin4btc)
30c6f64eed304560464f9601b80c811c186db20a test: Remove unnecessary LoadWallet() calls (pablomartin4btc)

Pull request description:

  Remove dead code due to legacy wallet removal.

  Leftovers from previous #32481.

  ---

  **Note**:

  While attempting to remove the legacy check in `CWallet::UpgradeDescriptorCache()` (which is called from `DBErrors WalletBatch::LoadWallet(CWallet* pwallet))`, I once again ran into the fact that `LoadWallet()` is used in two distinct scenarios — something I was already aware of:
  - Wallet creation – the upgrade is ignored here because no wallet flags are yet set; attempting to set a flag (ie `WALLET_FLAG_LAST_HARDENED_XPUB_CACHED` at the end of the upgrade function, if the legacy check is removed) would produce a failure (`DBErrors CWallet::LoadWallet()` -> `Assert(m_wallet_flags == 0)`).
  - Wallet loading – the upgrade proceeds correctly and the flag `WALLET_FLAG_LAST_HARDENED_XPUB_CACHED` is set.

  While revisiting this, I also noticed that some `LoadWallet()` calls in the wallet tests are unnecessary and I've removed them in the first commit.

  The following change in `UpgradeDescriptorCache()` could be done in PR #32636 as part of the separation between wallet loading and creation responsibilities.

  ```diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp

   void CWallet::UpgradeDescriptorCache()
   {
  +    // Only descriptor wallets can upgrade descriptor cache
  +    Assert(IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
  +
  -    if (!IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS) || IsLocked() || IsWalletFlagSet(WALLET_FLAG_LAST_HARDENED_XPUB_CACHED)) {
  +    if (IsLocked() || IsWalletFlagSet(WALLET_FLAG_LAST_HARDENED_XPUB_CACHED)) {
           return;
       }
  ```

ACKs for top commit:
  davidgumberg:
    crACK d3c5e47391
  achow101:
    ACK d3c5e47391e2f158001e3e199d625852c7f18998
  l0rinc:
    code review ACK d3c5e47391e2f158001e3e199d625852c7f18998

Tree-SHA512: ead37cf4061dfce59feb41ac50e807e6790e1a5e6b358e3b9c13e63d61a9cb82317a2e596cecb543f62f88a4338171788b651452425c1f40b5c1bec7fe78339e
2025-09-09 14:36:56 -07:00
Ava Chow
39a7dbdd27 wallet: Determine IsFromMe by checking for TXOs of inputs
Instead of checking whether the total amount of inputs known by the
wallet is greater than 0, we should be checking for whether the input is
known by the wallet. This enables us to determine whether a transaction
spends an of output with an amount of 0, which is necessary for marking
0-value dust outputs as spent.
2025-09-03 12:55:53 -07:00
pablomartin4btc
d3c5e47391 wallet, refactor: Remove Legacy check and error
Remove dead code due to legacy wallet removal.
2025-08-22 16:49:14 -03:00
Ava Chow
be776a1443 wallet: Remove isminetype
Since the only remaining isminetypes are ISMINE_NO and ISMINE_SPENDABLE,
this enum is now just a bool and can be removed. IsMine is changed to
return a bool and any usage of isminetypes and isminefilters are changed
to be the remaining ISMINE_SPENDABLE case.
2025-08-19 14:49:37 -07:00
merge-script
be356fc49b
Merge bitcoin/bitcoin#32896: wallet, rpc: add v3 transaction creation and wallet support
5c8bf7b39e9bffba7c4d5778b56b1ebe72f5ea1b doc: add release notes for version 3 transactions (ishaanam)
4ef8065a5e3d2fe9cd3d7a71224ef2ca2e7b495a test: add truc wallet tests (ishaanam)
5d932e14dbe41c349ab41f88088398e0ab10d335 test: extract `bulk_vout` from `bulk_tx` so it can be used by wallet tests (ishaanam)
2cb473d9f2152e33bab2c3c626801deb7841aa20 rpc: Support version 3 transaction creation (Bue-von-hon)
4c20343b4d318be62086676e0898e56221500de1 rpc: Add transaction min standard version parameter (Bue-von-hon)
c5a2d080116270ecd0414c14eb412fa30eaaedaf wallet: don't return utxos from multiple truc txs in AvailableCoins (ishaanam)
da8748ad626fc5813eb06244630e12c8ceb3cedf wallet: limit v3 tx weight in coin selection (ishaanam)
85c54106156f5bbac87f4442a0a27f1b9187125b wallet: mark unconfirmed v3 siblings as mempool conflicts (ishaanam)
0804fc3cb11089000d3b0e8bed41df0b0bf5fff1 wallet: throw error at conflicting tx versions in pre-selected inputs (ishaanam)
cc155226fee1f5c9a40ec37f6276e45c9c42b26a wallet: set m_version in coin control to default value (ishaanam)
2e9617664e70b5e586c485e7c65ce342ffd66cdf  wallet: don't include unconfirmed v3 txs with children in available coins (ishaanam)
ec2676becdf488f7a1151345a019c05dec926308 wallet: unconfirmed ancestors and descendants are always truc (ishaanam)

Pull request description:

  This PR Implements the following:
  - If creating a v3 transaction, `AvailableCoins` doesn't return unconfirmed v2 utxos (and vice versa)
  - `AvailableCoins` doesn't return an unconfirmed v3 utxo if its transaction already has a child
  - If a v3 transaction is kicked out of the mempool by a sibling, mark the sibling as a mempool conflict
  - Throw an error if pre-selected inputs are of the wrong transaction version
  - Allow setting version to 3 manually in `createrawtransaction` (uses commits from #31936)
  - Limits a v3 transaction weight in coin selection

  Closes #31348

  To-Do:
  - [x] Test a v3 sibling conflict kicking out one of our transactions from the mempool
  - [x] Implement separate size limit for TRUC children
  - [x] Test that we can't fund a v2 transaction when everything is v3 unconfirmed
  - [x] Test a v3 sibling conflict being removed from the mempool
  - [x] Test limiting v3 transaction weight in coin selection
  - [x] Simplify tests
  - [x] Add documentation
  - [x] Test that user-input max weight is not overwritten by truc max weight
  - [x] Test v3 in RPCs other than `createrawtransaction`

ACKs for top commit:
  glozow:
    reACK 5c8bf7b39e9
  achow101:
    ACK 5c8bf7b39e9bffba7c4d5778b56b1ebe72f5ea1b
  rkrux:
    ACK 5c8bf7b39e9bffba7c4d5778b56b1ebe72f5ea1b

Tree-SHA512: da8aea51c113e193dd0b442eff765bd6b8dc0e5066272d3e52190a223c903f48788795f32c554f268af0d2607b5b8c3985c648879cb176c65540837c05d0abb5
2025-08-19 06:00:50 -04:00
Ava Chow
57e8f34fe2
Merge bitcoin/bitcoin#32977: wallet: Remove wallet version and several legacy related functions
60d1042b9a4db8daf9fffdc29053652e99b7126e wallet: Remove unused `WalletFeature` enums (woltx)
66de58208a713e16f0d48bceed4d7496eae4b05b wallet: Remove `CWallet::nWalletVersion` and related functions (woltx)
7cda3d0f5bdca64b11f966a60167cde5451071a3 wallet: Remove `IsFeatureSupported()` and `CanSupportFeature()` (woltx)
ba0158522981287f2fde83f38392baac0216b0b4 wallet: `MigrateToDescriptor` no longer calls `CanSupportFeature` (woltx)
63acee279756e72f96fda14a9963281860bf318b wallet: Remove `GetClosestWalletFeature()` (woltx)
e27da3150b48ccf106ba93044bd28c6d1f505421 wallet: Remove `GetVersion()` (woltx)

Pull request description:

  This PR incorporates the suggestion provided by PRabahy and pablomartin4btc in https://github.com/bitcoin/bitcoin/pull/32944 of removing `CWallet::nWalletVersion` and several related functions, such as `SetMinVersion()`, `GetVersion()`, `GetClosestWalletFeature()`, `IsFeatureSupported()`, `CanSupportFeature()`, etc ...

  This field is no longer used in the descriptor wallet and there is still a lot of code related to it, so the changes here provide a good cleanup in the wallet code.

  Built on top of https://github.com/bitcoin/bitcoin/pull/32944

ACKs for top commit:
  maflcko:
    review ACK 60d1042b9a4db8daf9fffdc29053652e99b7126e 🐾
  achow101:
    ACK 60d1042b9a4db8daf9fffdc29053652e99b7126e
  pablomartin4btc:
    ACK 60d1042b9a4db8daf9fffdc29053652e99b7126e

Tree-SHA512: 1a7ad8e15d57df8f66545776e7d178a2cd5312c87769a29770588375e3de5f24247aab9919acf004ed3eca16d08ba595b5f1c7b2b3eef7752e89d9c295624583
2025-08-15 16:38:19 -07:00
ishaanam
85c5410615 wallet: mark unconfirmed v3 siblings as mempool conflicts 2025-08-15 10:45:36 -04:00
ishaanam
2e9617664e wallet: don't include unconfirmed v3 txs with children in available coins 2025-08-15 10:45:36 -04:00
Ava Chow
8405fdb06e
Merge bitcoin/bitcoin#33169: interfaces, chain, refactor: Remove unused getTipLocator and incaccurate getActiveChainLocator
2b00030af84efd50cfc60125db4ae49da6b7aa9a interfaces, chain, refactor: Remove inaccurate getActiveChainLocator (pablomartin4btc)
110a0f405cd696ebfd6edce07c1b347723e84a0f interfaces, chain, refactor: Remove unused getTipLocator (pablomartin4btc)

Pull request description:

  Remove `Chain::getTipLocator`, `Chain::GetLocator()`, and `Chain::getActiveChainLocator`:
  - `Chain::getTipLocator` is no longer used.
  - `Chain::GetLocator`, replaced its call by `GetLocator()`, which uses `LocatorEntries`, avoiding direct access to the chain itself (change suggested by l0rinc while reviewing this PR to maintain consistency with the overall refactoring).
  - `Chain::getActiveChainLocator`, whose name was misleading, has functionality redundant with Chain::findBlock.
    - Additionally, the comment for getActiveChainLocator became inaccurate following changes in commit ed470940cd (from PR #25717).

  This is a [follow-up](https://github.com/bitcoin/bitcoin/pull/29652#issuecomment-3151665095) to #29652.

ACKs for top commit:
  achow101:
    ACK 2b00030af84efd50cfc60125db4ae49da6b7aa9a
  furszy:
    ACK 2b00030af84efd50cfc60125db4ae49da6b7aa9a
  stickies-v:
    ACK 2b00030af84efd50cfc60125db4ae49da6b7aa9a
  w0xlt:
    ACK 2b00030af8

Tree-SHA512: b12ba6a15feeaeec692d69204a6e155e3af43edfac25597dabf14cacca1e4a2152574816e58dc544f39043c5721f5e707acf544f4541d3b9c0f8c0c40069215e
2025-08-14 11:30:45 -07:00
merge-script
9b1a7c3e8d
Merge bitcoin/bitcoin#33116: refactor: Convert uint256 to Txid
de0675f9de5feae1f070840ad7218b1378fb880b refactor: Move `transaction_identifier.h` to primitives (marcofleon)
6f068f65de17951dc459bc8637e5de15b84ca445 Remove implicit uint256 conversion and comparison (marcofleon)
9c24cda72edb2085edfa75296d6b42fab34433d9 refactor: Convert remaining instances from uint256 to Txid (marcofleon)
d2ecd6815d89c9b089b55bc96fdf93b023be8dda policy, refactor: Convert uint256 to Txid (marcofleon)
f6c0d1d23128f742dfdda253752cba7db9bb0679 mempool, refactor: Convert uint256 to Txid (marcofleon)
aeb0f783305c923ee7667c46ca0ff7e1b96ed45c refactor: Convert `mini_miner` from uint256 to Txid (marcofleon)
326f24472487dc7f447839136db2ccf60833e9a2 refactor: Convert RPCs and `merkleblock` from uint256 to Txid (marcofleon)
49b3d3a92a7250e80c56ff8c351cf1670e32c1a2 Clean up `FindTxForGetData` (marcofleon)

Pull request description:

  This is the final leg of the [type safety refactor](https://github.com/bitcoin/bitcoin/pull/32189).

  All of these changes are straightforward `uint256` --> `Txid` along with any necessary explicit conversions. Also, `transaction_identifier.h` is moved to primitives in the last commit, as `Txid` and `Wtxid` become fundamental types after this PR.

ACKs for top commit:
  stickies-v:
    re-ACK de0675f9de5feae1f070840ad7218b1378fb880b, no changes since a20724d926d5844168c6a13fa8293df8c8927efe except address review nits.
  janb84:
    re ACK de0675f9de5feae1f070840ad7218b1378fb880b
  dergoegge:
    re-ACK de0675f9de5feae1f070840ad7218b1378fb880b
  theStack:
    Code-review ACK de0675f9de5feae1f070840ad7218b1378fb880b

Tree-SHA512: 2413160fca7ab146a8d79d18ce3afcf7384cacc73c513d41928904aa453b4dd7a350064cee71e9c5d015da5904c7c81ac17603e50a47441ebc5b0c653235dd08
2025-08-13 14:50:51 -04:00
pablomartin4btc
2b00030af8 interfaces, chain, refactor: Remove inaccurate getActiveChainLocator
The getActiveChainLocator method name was misleading, and its functionality
duplicated `Chain::findBlock`. This commit removes the method and replaces
all its usages with direct `Chain::findBlock` calls.

Additionally, the comment of getActiveChainLocator has been outdated since
commit ed47094 from #25717.

Finally, in CWallet::ScanForWalletTransactions, the findBlock calls are now
unified into a single call at the start of the function.

Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
Co-authored-by: Matias Furszyfer <mfurszy@protonmail.com>
2025-08-13 00:21:17 -03:00
Ava Chow
73972d5617
Merge bitcoin/bitcoin#31296: wallet: Translate [default wallet] string in progress messages
db225cea56b0531cc42d4b89dc61b02890f432ff wallet, refactor: Replace GetDisplayName() with LogName() (Ryan Ofsky)
01737883b3ff8051253c961b7dde50d055104ef9 wallet: Translate [default wallet] string in progress messages (Ryan Ofsky)

Pull request description:

  Noticed while reviewing https://github.com/bitcoin/bitcoin/pull/31287#discussion_r1843809721 that the [default wallet] part of progress messages remains untranslated while the rest of the string is translated.

  Fix this in all places where `CWallet::ShowProgress` (which has a cancel button) and `Chain::showProgress` (which doesn't have a cancel button) are called by making "default wallet" into a translated string.

ACKs for top commit:
  achow101:
    ACK db225cea56b0531cc42d4b89dc61b02890f432ff
  pablomartin4btc:
    ACK db225cea56b0531cc42d4b89dc61b02890f432ff
  furszy:
    utACK db225cea56b0531cc42d4b89dc61b02890f432ff

Tree-SHA512: 3e76e22ee692a7403d61c66615f56d0fa5f7883dd47553bcaec2f9ffd942daaa90ceb61830206bece50da53dcd737b6438c36bcb086030b2deb68c44172f3931
2025-08-12 11:33:42 -07:00
marcofleon
9c24cda72e refactor: Convert remaining instances from uint256 to Txid
These remaining miscellaneous changes were identified by commenting out
the `operator const uint256&` conversion and the `Compare(const uint256&)`
method from `transaction_identifier.h`.
2025-08-11 16:47:43 +01:00
Hennadii Stepanov
a0eaa44925
Fix typos 2025-08-07 12:55:18 +01:00
Ava Chow
91058877ff
Merge bitcoin/bitcoin#32273: wallet: Fix relative path backup during migration.
76fe0e59ec4a5b0c5b18f46bfcbbf99628d74d77 test: Migration of a wallet ending in `../` (David Gumberg)
f0bb3d50fef08d9f981eac45841ef2df7444031b test: Migration of a wallet ending in `/` (David Gumberg)
41faef5f80d69ed984af685bd9d2a43268009fb6 test: Migration fail recovery w/ `../` in path (David Gumberg)
63c6d364376907c10b9baa3c6f4d72e3f1881abc test: Migration of a wallet with `../` in path. (David Gumberg)
70f1c99c901de64d6ccea793b7e267e20dfa49cf wallet: Fix migration of wallets with pathnames. (David Gumberg)
f6ee59b6e2995a3916fb4f0d4cbe15ece2054494 wallet: migration: Make backup in walletdir (David Gumberg)
e22c3599c6772730e72e17fc68c99feea09b4d29 test: wallet: Check direct file backup name. (David Gumberg)

Pull request description:

  Support for wallets outside of the default wallet directory was added in #11687, and these external wallets can be specified with paths relative to the wallet directory, e.g.  `bitcoin-cli loadwallet ../../mywallet`. In the RPC commands, there is no distinction between a wallet's 'name' and a wallet's 'path'. This PR fixes an issue with wallet backup during migration where the wallet's 'name-path' is used in the backup filename. This goes south when that filename is appended to the directory where we want to put the file and the wallet's 'name' actually gets treated as a path:

  ```cpp
      fs::path backup_filename = fs::PathFromString(strprintf("%s_%d.legacy.bak", (wallet_name.empty() ? "default_wallet" : wallet_name), GetTime()));
      fs::path backup_path = this_wallet_dir / backup_filename;
  ```

  Attempting to migrate a wallet with the 'name' `../../../mywallet` results in a backup being placed in `datadir/wallets/../../../mywallet/../../../mywallet_1744683963.legacy.bak`.

  If permissions don't exist to write to that folder, migration can fail.

  The solution implemented here is to put backup files in the top-level of the node's `walletdir` directory, using the folder name (and in some rare cases the file name)  of the wallet to name the backup file:

  9fa5480fc4/src/wallet/wallet.cpp (L4254-L4268)

  ##### Steps to reproduce on master
  Build and run `bitcoind` with legacy wallet creation enabled:
  ```bash
  $ cmake -B build -DWITH_BDB=ON && cmake --build build -j $(nproc)
  $ ./build/bin/bitcoind -regtest -deprecatedrpc=create_bdb
  ```

  Create a wallet with some relative path specifiers (exercise caution with where this file may be written)

  ```bash
  $ ./build/bin/bitcoin-cli -regtest -named createwallet wallet_name="../../../myrelativewallet" descriptors=false
  ```

  Try to migrate the wallet:
  ```bash
  $ ./build/bin/bitcoin-cli -regtest -named migratewallet wallet_name="../../../myrelativewallet"
  ```

  You will see a message in `debug.log` about trying to backup a file somewhere like: `/home/user/.bitcoin/regtest/wallets/../../../myrelativewallet/../../../myrelativewallet_1744686627.legacy.bak` and migration might fail because `bitcoind` doesn't have permissions to write the backup file.

ACKs for top commit:
  pablomartin4btc:
    tACK 76fe0e59ec4a5b0c5b18f46bfcbbf99628d74d77
  achow101:
    ACK 76fe0e59ec4a5b0c5b18f46bfcbbf99628d74d77
  ryanofsky:
    Code review ACK 76fe0e59ec4a5b0c5b18f46bfcbbf99628d74d77. Nice changes that (1) fix potential errors when names of wallets being migrated contain slashes, and (2) store migration backups in the top-level `-walletdir` instead of in individual wallet subdirectories.

Tree-SHA512: 5cf6ed9f44ac7d204e4e9854edd3fb9b43812e930f76343b142b3c19df3de2ae5ca1548d4a8d26226d537bca231e3a50b3ff0d963c200303fb761f2b4eb3f0d9
2025-07-29 11:15:59 -07:00
woltx
66de58208a wallet: Remove CWallet::nWalletVersion and related functions 2025-07-25 14:49:47 -07:00
Ava Chow
2e97541396
Merge bitcoin/bitcoin#32944: wallet: Remove upgradewallet RPC
d89c6fa4a71810cdb28395d4609632e1b22249b3 wallet: Remove `upgradewallet` RPC (w0xlt)

Pull request description:

  Based on discussions  in https://github.com/bitcoin/bitcoin/pull/32803, this PR proposes removing the ` upgradewallet`  RPC.

ACKs for top commit:
  maflcko:
    review ACK d89c6fa4a71810cdb28395d4609632e1b22249b3 🤙
  achow101:
    ACK d89c6fa4a71810cdb28395d4609632e1b22249b3
  pablomartin4btc:
    ACK d89c6fa4a71810cdb28395d4609632e1b22249b3
  brunoerg:
    Concept & light cr ACK d89c6fa4a71810cdb28395d4609632e1b22249b3

Tree-SHA512: 9ab89c9137ff83d7826da6b9d00d3617149a5d144129086a2685ee525087534c5ed06259075c0689ded52d33e075acb5067d185be04ecc638e27469f958f9a56
2025-07-25 12:59:52 -07:00
merge-script
5ad79b2035
Merge bitcoin/bitcoin#32593: wallet, rpc: Move (Un)LockCoin WalletBatch creation out of RPC
6135e0553e6e58fcf506700991fa178f2c50a266 wallet, rpc: Move (Un)LockCoin WalletBatch creation out of RPC (Ava Chow)

Pull request description:

  If the locked coin needs to be persisted to the wallet database, insteead of having the RPC figure out when to create a WalletBatch and having LockCoin's behavior depend on it, have LockCoin take whether to persist as a parameter so it makes the batch.

  Since unlocking a persisted locked coin requires a database write as well, we need to track whether the locked coin was persisted to the wallet database so that it can erase the locked coin when necessary.

  Keeping track of whether a locked coin was persisted is also useful information for future PRs.

  Split from #32489

ACKs for top commit:
  rkrux:
    ACK 6135e05
  Sjors:
    ACK 6135e0553e6e58fcf506700991fa178f2c50a266
  w0xlt:
    ACK 6135e0553e

Tree-SHA512: 0e2367fc4d50c62ec41443374b64c4c5ecf679998677df47fb8776cfb44704713bc45547e32e96cd30d1dbed766f5d333efb6f10eb0e71271606638e07e61a01
2025-07-24 13:38:58 -04:00
merge-script
e2f2df0ead
Merge bitcoin/bitcoin#32984: wallet: Set migrated wallet name only on success
060695c22ae7b2b0f2a1dd1417ed1b9d5a5ab542 test: Failed load after migrate should restore backup (MarcoFalke)
8a4cfddf23a4575a1042dfa97d3478727775e8dd wallet: Set migrated wallet name only on success (Ava Chow)

Pull request description:

  After a wallet is migrated and we are trying to load it, if it could not be loaded, don't try to set the wallet name. Otherwise we have a segfault.

  This can be tested by migrated a legacy wallet from another network (e.g. trying to migrate a testnet wallet on mainnet). The fixed behavior is return an error and restore the backup.

ACKs for top commit:
  davidgumberg:
    ACK 060695c22ae7b2b0f2a1d
  furszy:
    ACK 060695c22ae7b2b0f2a1dd1417ed1b9d5a5ab542
  rkrux:
    ACK 060695c22ae7b2b0f2a1dd1417ed1b9d5a5ab542
  w0xlt:
    reACK 060695c22a
  pablomartin4btc:
    ACK 060695c22ae7b2b0f2a1dd1417ed1b9d5a5ab542

Tree-SHA512: f4289e0b3dedef0a3d734c18604f2fd0df0dc65e9641bc342cfa45088d2540a3f6631bbea8bdd394b2631fa83b38e8ac37c83cfc4b53b19dcbd0b820a9beb6e4
2025-07-24 12:00:52 +01:00
David Gumberg
70f1c99c90 wallet: Fix migration of wallets with pathnames.
Co-authored-by: Russell Yanofsky <russ@yanofsky.org>
2025-07-16 17:50:58 -07:00
David Gumberg
f6ee59b6e2 wallet: migration: Make backup in walletdir 2025-07-16 17:50:58 -07:00
rkrux
2dfeb6668c
wallet: remove outdated pszSkip arg of database Rewrite func
This argument might have been used in the legacy wallets, but I don't
see any implementation using this argument in the SQLite wallets.
Removing it cleans up the code a bit.
2025-07-16 14:27:17 +05:30
Ava Chow
8a4cfddf23 wallet: Set migrated wallet name only on success
After a wallet is migrated and we are trying to load it, if it could not be
loaded, don't try to set the wallet name.
2025-07-15 16:11:36 -07:00
w0xlt
d89c6fa4a7 wallet: Remove upgradewallet RPC 2025-07-15 11:00:48 -07:00
Ava Chow
7f28e80329
Merge bitcoin/bitcoin#32758: wallet: remove dead code in legacy wallet migration
150b5c99ca11885ef15d04139d919d734e2c211a wallet: replace `reload_wallet` with inline functionality (rkrux)
0f86da382d3fdca6fc69ff277794acbc3f1e928d wallet: remove dead code in legacy wallet migration (rkrux)

Pull request description:

  A discussion on a previous [PR 32481](https://github.com/bitcoin/bitcoin/pull/32481#discussion_r2145152084) related to legacy wallet dead
  code removal made me realize that checking if the legacy
  wallet was loaded prior to the start of the migration is not
  required ever since legacy wallets can't be loaded in the first
  place. I also verified that the `load_on_start` persistent
  setting can also not cause the legacy wallets to be loaded, which
  further makes the case for removal of the above mentioned checks
  during migration.
  The current test coverage also shows these lines uncovered.

ACKs for top commit:
  achow101:
    ACK 150b5c99ca11885ef15d04139d919d734e2c211a
  furszy:
    ACK 150b5c99ca11885ef15d04139d919d734e2c211a

Tree-SHA512: 9bc7043cac1f4051228557208895e43648de3c7ffae6860c0676d1aa2db3a8ed3a09d1f9defacd96ca50bbb9699ba86652ccb0c5e55cc88be248a1fe727c13d9
2025-07-10 14:41:44 -07:00
Ava Chow
1ca62edd85
Merge bitcoin/bitcoin#32580: wallet, test: best block locator matches scan state follow-ups
1b5c545e82fe3cf5027f16b43e2306aeb8d4ef9b wallet, test: best block locator matches scan state follow-ups (rkrux)

Pull request description:

  Few follows-ups from #30221: Use `SetLastBlockProcessedInMem` more in `AttachChain`, add not null locator check in `WriteBestBlock`. Add log and few assertions in `wallet_reorgstore` test.

ACKs for top commit:
  achow101:
    ACK 1b5c545e82fe3cf5027f16b43e2306aeb8d4ef9b
  pablomartin4btc:
    cr-ACK 1b5c545e82fe3cf5027f16b43e2306aeb8d4ef9b

Tree-SHA512: 34edde55beef5714cea2e1131c29b57da2dc32ea091cd81878014de503c128f02c3ab88aee1e456541d7937e033dca5a81b03e9e2888cf781d71b62ad9b5ca5c
2025-07-09 14:35:13 -07:00
rkrux
150b5c99ca
wallet: replace reload_wallet with inline functionality
Also, update related comments because a reload is not happening
anymore. It is done because the legacy wallets could not have been
loaded prior to migration, so I don't think a reload is happening
post a successful migration, it's just load IMO.
2025-07-08 16:07:30 +05:30
merge-script
09add84fc5
Merge bitcoin/bitcoin#32618: wallet: Remove ISMINE_WATCHONLY and watchonly from RPCs
b1a8ac07e91dd1d305fcbc16ea931d60e46c0055 doc: Release note for removed watchonly parameters and results (Ava Chow)
15710869e19e707ef03492c55030dcefa16269d8 wallet: Remove ISMINE_WATCH_ONLY (Ava Chow)
4439bf4b41a6997d4d965f00a8c40efa9cf6895b wallet, spend: Remove fWatchOnly from CCoinControl (Ava Chow)
1337c72198a7d32935431d64e9e58c12f9003abc wallet, rpc: Remove watchonly from RPCs (Ava Chow)
e81d95d435744e48615973dc22acce1a291bd20d wallet: Remove watchonly balances (Ava Chow)
d20dc9c6aae089ab926fd135febd69a8f0744a18 wallet: Wallets without private keys cannot grind R (Ava Chow)
9991f49c38c084967ca66791d838c99b42f000eb test: Watchonly wallets should estimate larger size (Ava Chow)

Pull request description:

  Descriptor wallets do not use the watchonly behavior as it is not possible to mix watchonly and non-watchonly in a descriptor wallet. With legacy wallets now removed, all of the watchonly handling and reporting code is no longer needed. This PR removes watchonly options and results from the RPCs and the handling of watchonly things from the wallet's internals.

  With all of the watchonly things removed, ISMINE_WATCH_ONLY is removed as well.

  Split from #32523

  Depends on #32594 for tests that are easier to read

ACKs for top commit:
  Eunovo:
    ACK b1a8ac07e9
  maflcko:
    re-ACK b1a8ac07e91dd1d305fcbc16ea931d60e46c0055 🌈
  rkrux:
    ACK b1a8ac07e91dd1d305fcbc16ea931d60e46c0055
  furszy:
    light code review ACK b1a8ac07e91dd1d305fcbc16ea931d60e46c0055

Tree-SHA512: bc87f37a13294f7208991be8f93899b49e5bdf87c70e0f66d9c4cb09c03be6c202320406f27e9a35aa2f57319d19a3f0c07d5e5ddbc97c7edab165b1656d6612
2025-07-07 16:28:33 -04:00
rkrux
0f86da382d
wallet: remove dead code in legacy wallet migration
A discussion on a previous PR 32481 related to legacy wallet dead
code removal made me realize that checking if the legacy
wallet was loaded prior to the start of the migration is not
required ever since legacy wallets can't be loaded in the first
place. I also verified that the `load_on_start` persistent
setting can also not cause the legacy wallets to be loaded, which
further makes the case for removal of the above mentioned checks
during migration.
The current test coverage also shows these lines uncovered.
2025-07-03 14:27:47 +05:30
Ava Chow
35cae56a92
Merge bitcoin/bitcoin#31423: wallet: migration, avoid creating spendable wallet from a watch-only legacy wallet
b78990734621b8fe46c68a6e7edaf1fbd2f7d351 wallet: migration, avoid creating spendable wallet from a watch-only legacy wallet (furszy)
e86d71b749c08bde6002b9aa2baee824975a518a wallet: refactor, dedup wallet re-loading code (furszy)
1de423e0a08bbc63eed36c8772e9ef8b48e80fb8 wallet: introduce method to return all db created files (furszy)
d04f6a97ba9a55aa9455e1a805feeed4d630f59a refactor: remove sqlite dir path back-and-forth conversion (furszy)

Pull request description:

  Currently, the migration process creates a brand-new descriptor wallet with no
  connection to the user's legacy wallet when the legacy wallet lacks key material
  and contains only watch-only scripts. This behavior is not aligned with user
  expectations. If the legacy wallet contains only watch-only scripts, the migration
  process should only generate a watch-only wallet instead.

  TODO List:
  * Explain that `migratewallet` renames the watch-only after migration, and
  also that the wallet will not have keys enabled.

ACKs for top commit:
  achow101:
    ACK b78990734621b8fe46c68a6e7edaf1fbd2f7d351
  pablomartin4btc:
    tACK b78990734621b8fe46c68a6e7edaf1fbd2f7d351
  rkrux:
    LGTM ACK b78990734621b8fe46c68a6e7edaf1fbd2f7d351

Tree-SHA512: 1d583ac4b206fb477e9727daf4b5ad9c3e18b12d40e1ab4a61e8565da44c3d0327c892b51cf47b4894405d122e414cefb6b6366c357e02a74a7ca96e06762d83
2025-07-02 13:25:33 -07:00
rkrux
1b5c545e82
wallet, test: best block locator matches scan state follow-ups
Few follows-ups from #30221: Use `SetLastBlockProcessedInMem` more in
`AttachChain`, add not null locator check in `WriteBestBlock`. Add log
and few assertions in `wallet_reorgstore` test.
2025-07-02 14:30:52 +05:30
Ava Chow
d20dc9c6aa wallet: Wallets without private keys cannot grind R 2025-07-01 10:40:58 -07:00
Ava Chow
49675de035 wallet: Have GetDebit use the wallet's TXO set
Instead of looking up the previous tx in mapWallet, and then calling
IsMine on the specified output, use the TXO set and its cached IsMine
value.
2025-06-25 14:08:49 -07:00
Ava Chow
17d453cb3a wallet: Recompute wallet TXOs after descriptor migration
When a legacy wallet has been migrated to contain descriptors, but
before the transactions have been updated to match, we need to recompute
the wallet TXOs so that the transaction update will work correctly.
2025-06-25 14:08:49 -07:00
Ava Chow
764016eb22 wallet: Retrieve TXO directly in FetchSelectedInputs
Instead of searching mapWallet for the preselected inputs, search
m_txos.

wallet_fundrawtransaction.py spends external inputs and needs the change
output to also belong to the test wallet for the oversized tx test.
2025-06-25 14:08:49 -07:00
Ava Chow
96e7a89c5e wallet: Recalculate the wallet's txos after any imports 2025-06-25 14:08:49 -07:00
Ava Chow
ae0876ec42 wallet: Keep track of transaction outputs owned by the wallet
When loading transactions to the wallet, check the outputs, and keep
track of the ones that are IsMine.
2025-06-25 14:08:49 -07:00
Ava Chow
8222341d4f wallet: MarkDirty after AddWalletDescriptor
After adding a wallet descriptor (typically by import), mark all balance
caches dirty. This allows transactions that the wallet already knows
about that have outputs that are now ISMINE_SPENDABLE after the import
to actually be shown in balance calculations. Legacy wallet imports
would do this, but importdescriptors did not.
2025-06-25 14:08:27 -07:00
merge-script
8578fabb95
Merge bitcoin/bitcoin#32597: wallet: Always set descriptor cache upgraded flag for new wallets
47237cd1938058b29fdec242c3a37611e255fda0 wallet, rpc: Output wallet flags in getwalletinfo (Ava Chow)
bc2a26b296238cbead6012c071bc7741c40fbd02 wallet: Add GetWalletFlags (Ava Chow)
69f588a99a7a79d1d72300bc0f2c8475f95f6c6a wallet: Set upgraded descriptor cache flag for newly created wallets (Ava Chow)

Pull request description:

  Newly created wallets will always have an upgraded descriptor cache, so set those.

  Also, to verify this behavior, add a new `flags` field to `getwalletinfo` and check that in the functional tests.

  Split from #32489

ACKs for top commit:
  Sjors:
    ACK 47237cd1938058b29fdec242c3a37611e255fda0
  w0xlt:
    ACK 47237cd193
  rkrux:
    ACK 47237cd1938058b29fdec242c3a37611e255fda0

Tree-SHA512: 97c7f85b858efe5ced9b8aafb6cd7c1a547de6f8013b82bfc75bc567cf73c9db5e168e3980355756541305520022fd776b8d4d240d3fb34ed86c27d2acaf4863
2025-06-25 16:14:01 -04:00
Ava Chow
c668033709 wallet: Remove unused fTimeReceivedIsTxTime
fTimeReceivedIsTxTime has been unused unused since 0.3.24
2025-06-17 17:41:43 -07:00
Ava Chow
1be688f575
Merge bitcoin/bitcoin#32682: wallet: have external signer use PSBT error code EXTERNAL_SIGNER_NOT_FOUND
9dfc61d95f0082672a9b90528386e6bcd7014a78 test: detect no external signer connected (Sjors Provoost)
0a4ee93529d68a31f3ba6c7c6009954be47bbbd6 wallet: use PSBTError::EXTERNAL_SIGNER_NOT_FOUND (Sjors Provoost)
8ba2f9b7c8a6c6a91cc718d256354f7a73083b68 refactor: use util::Result for GetExternalSigner() (Sjors Provoost)

Pull request description:

  When attempting to sign a transaction involving an external signer, if the device isn't connected we throw an `std::runtime_error`. This prevents the (mainly GUI) code that's actually supposed to handle this case from running.

  This PR returns a `PSBTError::EXTERNAL_SIGNER_NOT_FOUND` instead of throwing.

  The first commit is a refactor to have `GetExternalSigner()` return a `util::Result<ExternalSigner>` so the caller can decide how to handle the error. There are two other places where call `GetExternalSigner()` which this PR doesn't change (which I think is fine there).

  Before:
  ![before](https://github.com/user-attachments/assets/2e08863b-fe76-479f-9cc0-60571b357a27)

  After (the translation already exist):
  ![after](https://github.com/user-attachments/assets/0e91c7ed-7d44-4030-beec-20d1694c270c)

  Fixes #32426

  Additionally use `LogWarning` instead of `std::cerr` for both a missing signer and failure to sign.

ACKs for top commit:
  achow101:
    ACK 9dfc61d95f0082672a9b90528386e6bcd7014a78
  brunoerg:
    code review ACK 9dfc61d95f0082672a9b90528386e6bcd7014a78

Tree-SHA512: 22515f4f0b4f50cb0ef532b729e247f11a68be9c90e384942d4277087b2e76806a1cdaa57fb51d5883dacf0a428e5279674aab37cce8c0d3d7de0f96346b8233
2025-06-16 17:32:57 -07:00
pablomartin4btc
573bcd75d7 wallet, refactor: Remove unused SetupGeneration
SetupGeneration was supposed to be the function that all SPKMs used
to setup automatic generation, but it didn't work out that way and
ended up being legacy only. It should be deleted at this point.
2025-06-10 16:34:17 -03:00
pablomartin4btc
5431f2dc21 wallet, refactor: Remove Legacy warnings and errors
Remove dead code due to legacy wallet removal.
2025-06-10 16:27:42 -03:00
Sjors Provoost
8ba2f9b7c8
refactor: use util::Result for GetExternalSigner()
This commit does not change behavior, except that the error message no longer contains the function name.
2025-06-05 11:32:23 +02:00
Ava Chow
6135e0553e wallet, rpc: Move (Un)LockCoin WalletBatch creation out of RPC
If the locked coin needs to be persisted to the wallet database,
insteead of having the RPC figure out when to create a WalletBatch and
having LockCoin's behavior depend on it, have LockCoin take whether to
persist as a parameter so it makes the batch.

Since unlocking a persisted locked coin requires a database write as
well, we need to track whether the locked coin was persisted to the
wallet database so that it can erase the locked coin when necessary.

Keeping track of whether a locked coin was persisted is also useful
information for future PRs.
2025-06-02 13:14:19 -07:00
Ryan Ofsky
01737883b3 wallet: Translate [default wallet] string in progress messages
Noticed while reviewing #31287
(https://github.com/bitcoin/bitcoin/pull/31287#discussion_r1843809721) that the
[default wallet] part of progress messages remains untranslated while the rest
of the string is translated. Fix this in all places where Wallet::ShowProgress
(which has a cancel button) and chain::showProgress (which doesn't have a
cancel button) are called by making "default wallet" into a translated string.

To minimize scope of this bugfix, this introduces a new wallet DisplayName()
method which behaves differently than the existing GetDisplayName() method. The
existing method will be cleaned up in the following commit.
2025-06-02 08:46:03 -05:00
furszy
b789907346
wallet: migration, avoid creating spendable wallet from a watch-only legacy wallet
Currently, the migration process creates a brand-new descriptor wallet with no
connection to the user's legacy wallet when the legacy wallet lacks key material
and contains only watch-only scripts. This behavior is not aligned with user
expectations. If the legacy wallet contains only watch-only scripts, the migration
process should only generate a watch-only wallet instead.
2025-05-29 01:46:26 -04:00
furszy
e86d71b749
wallet: refactor, dedup wallet re-loading code 2025-05-28 06:33:00 -04:00
Ava Chow
bc2a26b296 wallet: Add GetWalletFlags 2025-05-22 17:37:41 -07:00