49196 Commits

Author SHA1 Message Date
Ava Chow
d9cf658ee0 Restrict joinpsbts to PSBTv0 only 2026-04-29 15:04:22 -07:00
Ava Chow
3da0e16012 Replace PSBT.tx with PSBT::GetUnsignedTx and PSBT::GetUniqueID
The global unsigned tx is decomposed into separate fields inside of
PSBT, which mirrors what PSBTv2 will do. However, we still need to get
the global unsigned tx so PSBT::GetUnsignedTx is introduced to do that.
In order to also have a stable unique ID, we also introduce
PSBT::GetUniqueID to replace uses of PSBT.tx.GetHash().
2026-04-29 15:04:22 -07:00
Ava Chow
c568624ff2 psbt: Return std::optional from PrecomputePSBTData 2026-04-29 15:04:22 -07:00
Ava Chow
092de4f1f6 Replace PSBT::GetInputUTXO with PSBTInput::GetUTXO
Now that PSBTInput's track their own prevouts, there's no need for a
PSBT global function to fetch input specific data.
2026-04-29 15:04:22 -07:00
Ava Chow
1d1ae6f0c4 wallet, test: Remove DuplicateMockDatabase
DuplicateMockDatabase is no longer used. Furthermore, as SQLite gets
used more as a database and less as a key value store, this function
gets more complicated and more bug prone. As the benchmarks now run
equivalently quickly with a real database, retaining this duplication
function is no longer necessary.
2026-04-29 14:55:21 -07:00
Ava Chow
82bc280de4 test: Simple test for importing unused(KEY) 2026-04-29 14:53:31 -07:00
Ava Chow
80c29bc6f1 descriptor: Add unused(KEY) descriptor
unused() descriptors do not have scriptPubKeys. Instead, the wallet uses
them to store keys without having any scripts to watch for.
2026-04-29 14:53:31 -07:00
Ava Chow
82c9fe3179 psbt: Use PSBTInput and PSBTOutput fields instead of accessing global tx
PSBTInput now has the previous txid and output index, and PSBTOutput has
the amount and script. We no longer need to access the global unsigned
tx for these fields.

Additionally, we can change iterating tx.vin and tx.vout to psbtx.inputs
and psbtx.outputs.

This is in prepration for use with PSBTv2 where the global unsigned tx
will not exist.
2026-04-29 14:51:47 -07:00
Ava Chow
95897507e9 psbt: AddInput and AddOutput should take only PSBTInput and PSBTOutput 2026-04-29 14:51:47 -07:00
Ava Chow
1b7d323a72 Add PSBTInput::GetOutPoint
Helper for getting the PSBTInput COutPoint
2026-04-29 14:51:47 -07:00
Ava Chow
543d3e1cdc psbt: add PSBTv2 global tx fields
When decomposing a transaction into a PSBTv2, the tx version and
locktime need to be stored in their respective global fields. Add those
fields and fill them when constructing.
2026-04-29 14:51:47 -07:00
Ava Chow
c01c7f068c psbt: Remove default constructor
Instead of allowing PSBTs to be default constructor, force usage of the
deserialization constructor.

CombinePSBTs, DecodeBase64PSBT, and DecodeRawPSBT are all changed to
return std::optional or util::result rather than using an output
parameter to avoid the need for a default constructor.
2026-04-29 14:51:47 -07:00
Ava Chow
9671aa08c2 psbt: add tx input and output fields in PSBTInput and PSBTOutput
PSBTInput should be aware of the previous txid, output index, and
sequence numbers for inputs, extracting them from the global
unsigned tx.

PSBTOutput should be aware of the output amount and script, extracting
them from the global unsigned tx.

This prepares for PSBTv2 where these fields are serialized.
2026-04-29 14:51:47 -07:00
Ava Chow
990b084f11 Have PSBTInput and PSBTOutput know the PSBT's version 2026-04-29 14:51:47 -07:00
Ava Chow
7eacc21ff6 psbt: make PSBT structs into classes 2026-04-29 14:51:47 -07:00
Ava Chow
f926c326bb gui: Store PSBT in std::optional in PSBTOperationsDialog
Use std::optional to store the PSBT to avoid having a default constructed PSBT
2026-04-29 14:51:37 -07:00
Ava Chow
1e2d146b47 psbt: Refactor duplicate key lookup and size checks
Every key has a duplicate key lookup check, and many keys have fixed
size checks. These can be refactored to reduce code duplication.

Co-Authored-By: David Gumberg <davidzgumberg@gmail.com>
2026-04-29 14:50:52 -07:00
Ava Chow
88384180d3 test: PSBTs should roundtrip through RPCs that do nothing 2026-04-29 14:50:52 -07:00
David Gumberg
001877500d test: construct psbt with unknown field programmatically 2026-04-29 14:50:52 -07:00
Ava Chow
0cb884e6df psbt: Fill hash preimages and taproot builder from SignatureData
Filling these fields was missing.
2026-04-29 14:50:52 -07:00
Ava Chow
57820c472b bench: Utilize setup() for WalletLoading and use a real database
Instead of making a mock database and duplicating it for the benchmark,
use a real database. Also use setup() to avoid measuring the overhead in
the benchmark.
2026-04-29 14:49:39 -07:00
Ava Chow
9a7604fd25 bench: Use setup() in WalletMigration to prepare the legacy wallet
WalletMigration needs a new wallet with legacy records for each run of
the benchmark. This can be done in setup() rather than duplicating the
records of an initial wallet.
2026-04-29 14:49:39 -07:00
Ava Chow
426a94e7bd bench: Utilize setup() in WalletEncrypt to create the encryption wallet
WalletEncrypt needs an unencrypted wallet in order for the benchmark to
encrypt a wallet. This was previously achieved by duplicating the
contents of an initial wallet for each run of the benchmark. We can
instead use setup() to unload the previously loaded wallet and then
create a new wallet with unencrypted keys.
2026-04-29 14:49:37 -07:00
Ava Chow
d672455d20 bench: Utilitze setup() in WalletBalance for marking caches dirty
WalletBalance benchmarks the balance computation function and should
exclude the setup step of (optionally) marking caches as dirty. Instead,
that is moved into setup().
2026-04-29 14:46:34 -07:00
Ava Chow
61412ef887 bench: Utilize setup() in WalletCreate to cleanup previous wallets
The WalletCreate benchmark should only be for creating a wallet and
exclude the unloading of the newly created wallet. Instead, unloading
can be done in setup() and after the benchmark completes.
2026-04-29 14:45:51 -07:00
David Gumberg
451fdd26a4 test: wallet: Constructing a DSPKM that can't TopUp() throws. 2026-04-29 14:15:16 -07:00
Ava Chow
32946e0291 wallet: Setup new autogenerated descriptors on construction
Instead of having a caller use SetupDescriptorGeneration, just have a
constructor that takes those arguments and sets up the descriptor with
the autogenerated key.
2026-04-29 14:15:16 -07:00
Ava Chow
e20aaff70f wallet: Construct ExternalSignerSPKM with the new descriptor
Instead of constructing then setting the descriptor with
SetupDescriptor, just pass in that descriptor to the constructor.
2026-04-29 14:15:16 -07:00
Ava Chow
aa4f7823aa wallet: include keys when constructing DescriptorSPKM during import
When importing a descriptor, all of the descriptor data should be
provided at the same time in the constructor.
2026-04-29 14:15:16 -07:00
Ava Chow
6538f69135 fuzz: Skip adding descriptor to wallet if it cannot be expanded 2026-04-29 14:15:16 -07:00
David Gumberg
8be5ee554b test: wallet: Check that loading wallet with both unencrypted and encrypted keys fails. 2026-04-29 14:15:16 -07:00
Ava Chow
80b0c25992 wallet: Load everything into DescSPKM on construction
Instead of creating a DescSPKM that is then progressively loaded, we
should instead create it all at once in a factory function when loading.
2026-04-29 14:15:16 -07:00
David Gumberg
f713fd1725 refactor: wallet: Don't reuse WALLET_BLANK flag for born-encrypted wallets.
With the split between LoadWallet and CreateNew, it's no longer
necessary to utilize the blank flag to prevent the wallet from having
descriptors automatically being generated. Instead, CreateNew can take a
separate parameter to indicate whether the wallet is to be born
encrypted and therefore should not have any keys generated.
2026-04-29 14:15:16 -07:00
Ava Chow
cd912c4e10 wallet: Consolidate generation setup callers into one function 2026-04-29 14:15:16 -07:00
Ava Chow
0301c758ea wallet migration, fuzz: Migrate hd seed once
If a wallet has multiple HD chains that have the same seed, we should
only migrate that seed a single time.

This fixes a fuzz crash that occurs once the return value of
AddDescriptorKeyWithDB is checked during descriptor construction.
2026-04-29 14:15:16 -07:00
will
2424e52836 lint: doc: detail lint tool install methods
Installing tools in the dockerfile using `COPY --from` is better , but
not all tools we use publish an OCI image to a non-docker.io registry.

As we are frequently rate-limited from docker.io, only install tools
which publish to another registry, e.g. ghcr.io.
2026-04-29 21:50:14 +01:00
Sjors Provoost
5fefa5a654 Don't pin Python patch version
.python-version always matches the minimum supported Python version.
It's main purpose is to catch accidental use of too modern syntax
in scripts and functional tests.

We (currently) don't specify a minimum patch version, so it's not
necessary to do so here. The minor verion is enough.

This also avoids requiring users to keep a potentially unsafe old
patch version installed.
2026-04-29 21:50:13 +01:00
will
fd15b55c2e lint: use requirements.txt 2026-04-29 21:50:12 +01:00
will
5f4d3383da lint: switch to ruff for formatting and linting
- use dedicated ruff.toml for configuration
- download via docker image layer at build time
2026-04-29 21:50:10 +01:00
will
a53b81ce4e lint: switch to uv for python management in linter
https://docs.astral.sh/uv/

Install python in the linter using uv and a venv.
This is faster and more simple than building pyenv.
2026-04-29 21:49:42 +01:00
merge-script
fb0e8612d6 Merge bitcoin/bitcoin#35175: multi_index: fix compilation failure with boost >= 1.91
0bc9d354df multi_index: fix compilation failure with boost >= 1.91 (Cory Fields)

Pull request description:

  This effectively reverts a3cb309e7c from PR #30194.

  That PR reduced the `multi_index` type signatures as recommended upstream, but this is no longer supported as of boost 1.91 because it is no longer necessary. 1.91 drops support for the pre-c++11 work-arounds that bloated the type signatures to begin with.

  The upstream `BOOST_MULTI_INDEX_ENABLE_MPL_SUPPORT` define is meant to provide compatibility with removed features, but it does not work for this case. Using `indexed_by` directly when defining the `multi_index` (as opposed to inheriting from it) works with all versions, and avoids the use of the back-compat define.

  This is a slight regression when building against boost < 1.91 because the bloated type signatures are reintroduced in that case, but it's not significant enough to go to the trouble of introducing version detection and ifdefs.

ACKs for top commit:
  maflcko:
    review ACK 0bc9d354df 🎶
  hebasto:
    ACK 0bc9d354df.
  w0xlt:
    ACK 0bc9d354df

Tree-SHA512: 883ee998efd16d944628653ca204e3d2acaf2554b2eced40556143a66d6072a3625861d961d1a4a194a7b8d4d448562581e5d11a09380754a5635a871d2a0aa1
2026-04-29 19:49:53 +01:00
Ava Chow
2b0dc0d228 wallet: Disallow . and .. from wallet names
Wallet names that are also paths that contain . and .. are unintuitive
and can result in unexpected behavior, particularly in migration.
Therefore we should disallow users from specifying wallet names that
contain . and .. as path elements.
2026-04-29 11:15:40 -07:00
Lőrinc
d084bc88be doc: clarify IWYU workflow
Document the CI wrapper as the reproducible IWYU entrypoint instead of suggesting ad hoc native runs.
Also describe how to handle suspected false positives, explain when local `IWYU pragma` workarounds are appropriate, and add an example rationale to an existing pragma.

Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
Co-authored-by: Daniel Pfeifer <daniel@pfeifer-mail.de>
2026-04-29 18:10:39 +02:00
Lőrinc
7c7cec4567 ci: update IWYU patch reference
Point the patch comment at the `clang_22` stdlib C include map now used by the native IWYU job.
2026-04-29 18:01:37 +02:00
merge-script
cef58341a0 Merge bitcoin/bitcoin#32876: refactor: use options struct for signing and PSBT operations
eab72d14d7 refactor: use SignOptions for MutableTransactionSignatureCreator (Sjors Provoost)
5ed41752c5 refactor: use SignOptions for SignTransaction (Sjors Provoost)
dc4a5d1270 refactor: use PSBTFillOptions for filling and signing (Sjors Provoost)

Pull request description:

  Replace the `sign`, `finalize` , `bip32derivs` and `sighash_type` arguments that are passed to `FillPSBT()` and `SignPSBTInput()` with a `PSBTFillOptions` struct.

  ```cpp
  struct PSBTFillOptions {
      bool sign{true};
      std::optional<int> sighash_type{std::nullopt};
      bool finalize{true};
      bool bip32_derivs{true};
  };
  ```

  Additionally this PR introduces:

  ```cpp
  struct SignOptions {
      int sighash_type{SIGHASH_DEFAULT};
  };
  ```

  This is used by `SignTransaction` and the `MutableTransactionSignatureCreator` constructor.

  These changes make it easier to add additional options later without large code churn, such as `avoid_script_path` proposed in #32857. It also makes the use of default boolean options safer compared to positional arguments that can easily get mixed up.

ACKs for top commit:
  w0xlt:
    reACK eab72d14d7
  optout21:
    ACK eab72d14d7
  sedited:
    ACK eab72d14d7

Tree-SHA512: 097e3d042e794c9f47d03e1aafad184a4525aa765d274f6497122d4f41603e902191df6fbf9ce846dbcd7372a159b67e2234da7341ec6a6776be5685e3e6e6ff
2026-04-29 15:51:38 +02:00
Vasil Dimov
75cf9708a0 ci: add one more routable address to the VMs (docker containers)
Also explicitly specify which addresses from the docker network to
assign to the VM.

With `1.1.1.5` and `1111:1111::5` set on the machine, the tests
`feature_bind_port_discover.py` and
`feature_bind_port_externalip.py` will run.
2026-04-29 14:20:05 +02:00
Vasil Dimov
1b93983bf5 test: make feature_bind_port_(discover|externalip).py auto-detect the skip condition
Instead of requiring a run with an explicit `--ihave1111and2222`, detect
whether the routable addresses are set up and if not, then skip the test.

To detect whether the addresses are set use `bitcoind` - start it
and ask it to bind on them and see if it will error with
"Unable to bind". Since this is what the tests do anyway, just start
the nodes and see if an exception will be raised like
`FailedToStartError` / "Unable to bind".

This makes it possible for the CI to run
`feature_bind_port_discover.py` and
`feature_bind_port_externalip.py` by just setting up the
addresses, without having to explicitly provide `--ihave1111and2222`.

Co-authored-by: willcl-ark <will@256k1.dev>
2026-04-29 14:18:41 +02:00
Cory Fields
0bc9d354df multi_index: fix compilation failure with boost >= 1.91
This effectively reverts a3cb309e7c from PR #30194.

That PR reduced the multi_index type signatures as recommended upstream, but
this is no longer supported as of boost 1.91 because it is no longer necessary.
1.91 drops support for the pre-c++11 work-arounds that bloated the type
signatures to begin with.

The upstream `BOOST_MULTI_INDEX_ENABLE_MPL_SUPPORT` define is meant to provide
compatibility with removed features, but it does not work for this case. Using
`indexed_by` directly when defining the `multi_index` (as opposed to inheriting
from it) works with all versions, and avoids the use of the back-compat define.

This is a slight regression when building against boost < 1.91 because the
bloated type signatures are reintroduced in that case, but it's not significant
enough to go to the trouble of introducing version detection and ifdefs.
2026-04-28 18:22:47 +00:00
Sjors Provoost
eab72d14d7 refactor: use SignOptions for MutableTransactionSignatureCreator 2026-04-28 17:43:03 +02:00
Sjors Provoost
5ed41752c5 refactor: use SignOptions for SignTransaction 2026-04-28 17:43:03 +02:00