Commit Graph

48781 Commits

Author SHA1 Message Date
w0xlt
9fa4076b20 test: Test merging implicit PSBTv0 with explicit PSBTv0 2026-04-29 15:04:22 -07:00
Ava Chow
1660c18232 doc: Release notes for psbtv2 2026-04-29 15:04:22 -07:00
Antoine Poinsot
470e52a5f8 fuzz: Enforce additional version invariants in PSBT fuzzer 2026-04-29 15:04:22 -07:00
Ava Chow
5bd0579c09 test: Tests for PSBT AddInput and AddOutput 2026-04-29 15:04:22 -07:00
Ava Chow
b8b6e7f0c2 tests: Add PSBT unit test for ComputeTimeLock 2026-04-29 15:04:22 -07:00
Ava Chow
0bc1c2e508 tests: Add test vectors from BIP 370 2026-04-29 15:04:22 -07:00
Ava Chow
e0e4dbdeb5 psbt: Change default psbt version to 2 2026-04-29 15:04:22 -07:00
Ava Chow
bcc1dca77b Add psbt_version to PSBT RPCs and default to v2
walletcreatefundedpsbt, createpsbt, converttopsbt, and psbtbumpfee take
a psbt_version argument to set the version of the PSBT that they
produce. The default psbt_version is 2.
2026-04-29 15:04:22 -07:00
Ava Chow
ab38c30195 Implement PSBTv2 field merging 2026-04-29 15:04:22 -07:00
Ava Chow
93e339e29f Implement PSBTv2 AddInput and AddOutput 2026-04-29 15:04:22 -07:00
Ava Chow
b39c86ae60 Allow specifying PSBT version in constructor
The constructor will create the PSBT of the specified version, as long
as it is 0 or 2.
2026-04-29 15:04:22 -07:00
Ava Chow
dcc9a3c8df Implement PSBTv2 in decodepsbt 2026-04-29 15:04:22 -07:00
Ava Chow
5770dbd39f Add PSBT::ComputeLockTime()
Function to compute the lock time for the transaction
2026-04-29 15:04:22 -07:00
Ava Chow
863cf47b33 Update test_framework/psbt.py for PSBTv2 2026-04-29 15:04:22 -07:00
Ava Chow
925161eaf0 Implement PSBTv2 fields de/ser 2026-04-29 15:04:22 -07:00
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
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
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
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
Sjors Provoost
dc4a5d1270 refactor: use PSBTFillOptions for filling and signing
Replace the sign, finalize , bip32derivs and sighash_type arguments which
are passed to FillPSBT() and SignPSBTInput() with a PSBTFillOptions struct.

This makes 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.
2026-04-28 17:43:03 +02:00
merge-script
8592152186 Merge bitcoin/bitcoin#34911: rpc, mempool: -deprecatedrpc fullrbf and bip125-replaceable from mempool RPCs
8deed0df06 doc: add release notes for PR 34911 (rkrux)
1a85ca1dff rpc, mempool: rpcdeprecate `bip125-replaceable` key in mempool RPCs reponses (rkrux)
f89d18c3b1 rpc, mempool: rpcdeprecate `fullrbf` key in getmempoolinfo RPC response (rkrux)

Pull request description:

  mempoolfullrbf=1 behaviour has been the default since v28 and the argument has
  been removed since v29 subsequently.

  The getmempoolinfo RPC need not return the deprecated `fullrbf` key in the
  response anymore unless the user requests it via -deprecatedrpc=fullrbf node
  argument.

  Also, remove the `bip125-replaceable` key from the mempool RPCs
  responses (because it, too, has been deprecated since v29) unless the user
  requests it via -deprecatedrpc=bip125 node argument.

ACKs for top commit:
  optout21:
    ACK 8deed0df06
  sedited:
    ACK 8deed0df06
  instagibbs:
    ACK 8deed0df06

Tree-SHA512: dfbbdf04ae25dafe81758bd85715af80d736e21bb913ab09ff8fd8225587b7a1bf1dd6b0f7ea05135504e11d43371d98e5f5fc6e3717d581e870e8c2bf97811b
2026-04-27 21:18:36 +02:00
merge-script
ad3f73862b Merge bitcoin/bitcoin#35149: doc: clarify clang-tidy in developer notes
a1e534bbf0 doc: clarify clang-tidy in developer notes (rkrux)

Pull request description:

  Recently, I ran clang-tidy in my system and had to figure out setting it up
  correcty on my system (macOS) & understanding its output while tweaking
  few arguments that made the output easier to parse.

  This patch documents those in the developer notes.

ACKs for top commit:
  sedited:
    ACK a1e534bbf0

Tree-SHA512: e95cd44cdad9a9011c18136ec7f1db4e73f78f11c517f94c14cf128beaaea150881868c27e7c5c710c9cab94d285d61dc5e5278f347c229f5df495cd49c532ab
2026-04-27 16:01:54 +02:00
merge-script
f40da7afc0 Merge bitcoin/bitcoin#35153: doc: update llvm based coverage example
ef21e29298 doc: update llvm based coverage example (Max Edwards)

Pull request description:

  The old example was working on my Mac but when run on Linux I was finding that I had missing coverage information.

  On some systems the old example of using xargs to pass list of profraw files can exceed xargs's argument limit resulting in multiple executions of llvm-profdata merge command which overwrites it's output file losing coverage information. This PR switches the example to using a file with a list of filenames.

  There are other ways to solve this like using bash's globbing or a one liner with temporary file but I felt like this was the most simple, robust and easy to understand.

ACKs for top commit:
  vasild:
    ACK ef21e29298
  sedited:
    ACK ef21e29298

Tree-SHA512: 2726d9b38088c1c0b6f04d4622bdc4ea28e16b13a962a3afc842798aa5e0eee4682752c73707c5580a43bdb9d0d84d542afd357f166e4dbb7f6beb7afc0522c8
2026-04-27 15:31:03 +02:00
merge-script
a7bea426b4 Merge bitcoin/bitcoin#35143: kernel: guard btck::Handle move-assignment against self-move
14547eb489 kernel: guard btck::Handle move-assignment against self-move (Thomas)

Pull request description:

  The move-assignment operator for `btck::Handle<>` in `src/kernel/bitcoinkernel_wrapper.h` unconditionally called `DestroyFunc(m_ptr)` before reading the source pointer. On a self-move (`h = std::move(h)`), this destroys the held resource and then restores the now-dangling pointer via `std::exchange(other.m_ptr, nullptr)` (since `&other == this`), which leaves `m_ptr` pointing at freed memory. The destructor then calls `DestroyFunc` again on it, resulting in a double-free.

  Trace of `h = std::move(h)` with the old code, where `h.m_ptr == P`:

  1. `DestroyFunc(m_ptr)` -> `delete P`. `this->m_ptr` still literally stores the now-dangling value `P`.
  2. `std::exchange(other.m_ptr, nullptr)` — because `&other == this`, this reads the dangling `P` back, writes `nullptr` to `m_ptr`, and returns `P`.
  3. `m_ptr = P` restores the dangling pointer.
  4. `~Handle()` later runs `DestroyFunc(P)` -> double free, UB.

  The copy-assignment operator already guards against self-assignment with `if (this != &other)`; the move variant should be symmetric. The standard library requires moved-from objects to be in a valid (at minimum, safely destructible) state, which the previous implementation violated when source and destination alias.

  `Handle<>` is the base class of 16 public types in the kernel C++ API wrapper (`Transaction`, `Block`, `BlockHeader`, `ChainParams`, `Context`, `Coin`, `BlockValidationState`, `ScriptPubkey`, `TransactionOutput`, `Txid`, `OutPoint`, `TransactionInput`, `PrecomputedTransactionData`, `BlockHash`, `BlockSpentOutputs`, `TransactionSpentOutputs`), so self-move can arise from generic algorithms operating on containers of these types (`std::sort`, `std::remove`, erase-remove idioms, etc.).

  Fix: mirror the copy-assignment pattern by guarding the move-assignment body with `if (this != &other)`, making a self-move a no-op.

  Also extend `CheckHandle` in `src/test/kernel/test_kernel.cpp` to exercise self-move-assignment for every `Handle`-derived type, checking that the stored pointer and the serialized bytes (where applicable) are unchanged.

ACKs for top commit:
  sedited:
    Thanks, ACK 14547eb489
  alexanderwiederin:
    ACK 14547eb489
  yuvicc:
    lgtm ACK 14547eb489

Tree-SHA512: 334f5ad3045d5f9b06cc0dd096bc911a992773c59cc469765c2082975a9f7a90f2349b9ad94b4b5127290de1fab2f5424a621384c1b4bb9152de99f5da8ed6aa
2026-04-26 17:55:12 -04:00
merge-script
0abbe35bb2 Merge bitcoin/bitcoin#35148: refactor: Remove confusing DataStream::in_avail() alias
fa204100e1 streams: Remove confusing DataStream::in_avail() (MarcoFalke)
fa5ab0220e move-only: Extract ProcessPong() helper (MarcoFalke)

Pull request description:

  The `in_avail` alias is confusing (see commit message), so remove it. Also extract the `ProcessPong()` helper, as the only place that called `in_avail`.

ACKs for top commit:
  l0rinc:
    code review ACK fa204100e1
  sedited:
    ACK fa204100e1

Tree-SHA512: b5a069abb471c42d39e91a3c55fc7f18fb9ccf8591408b3dd43210d0287785369b6a5d6b59b847d85247a494f208dbbe4a7e88b24caf9b3e6c8fea2157cd0ee0
2026-04-25 10:26:26 +02:00
Ava Chow
6322c1697d Merge bitcoin/bitcoin#33920: Export embedded ASMap RPC
2a90b6132a Add release notes for exportasmap (Fabian Jahr)
8cb2d926b4 rpc: Add exportasmap RPC (Fabian Jahr)

Pull request description:

  This depends on the embedded data PR itself (#28792), until merge this will remain in draft status. All commit but the last one are from there.

  There has been interest in exporting the embedded data back into a file. This is implemented here with a simple `exportasmap` RPC which provides this functionality. The exported file can be used to verify the data integrity or statistical analysis using e.g. `contrib/asmap-tool.py`.

ACKs for top commit:
  achow101:
    ACK 2a90b6132a
  sedited:
    ACK 2a90b6132a
  seduless:
    Tested ACK 2a90b6132a

Tree-SHA512: c8453078efe916ed95bff0695aabd9123d805970e037fad5e9317f4d43e2a4b21970030265bc82b00f3a222ee3db11346eef1fb6fc9393429b9bc6449f1830f1
2026-04-24 16:02:34 -07:00
Ava Chow
28a523fb94 Merge bitcoin/bitcoin#35097: util: Return uint64_t from _MiB and _GiB operators
fa43da21f1 refactor: Run ShouldWarnOversizedDbCache calculation in u64 (MarcoFalke)
fa5801762e util: Return uint64_t from _MiB and _GiB operators (MarcoFalke)
fa9ddb01c9 test: Use MiB operator directly in cuckoocache_tests (MarcoFalke)

Pull request description:

  Currently, the `_MiB` literal operator returns a value of type `size_t`. This is brittle and confusing:

  * It is inherently impossible to represent larger values, like storage device usage.
  * Similarly, it is not possible to even type an upper cap on the memory, see the failure in https://github.com/bitcoin/bitcoin/pull/34692#issuecomment-3973281952
  * Using `size_t` isn't required here. The function is evaluated at compile time, and even 32-bit compilers can evaluate an `uint64_t` at compile time.
  * Using `size_t` here encourages it to be used in more places, which will likely lead to more bugs and CVEs, such as https://github.com/bitcoin/bitcoin/pull/34109, https://github.com/bitcoin/bitcoin/pull/33724, etc.

  Fix all issues, by:

  * Marking the operator `consteval`, to ensure it is really only called at compile-time.
  * Returning an `uint64_t` value.
  * Using it in the place where it was previously not possible.

  Review note:

  This should have no downside, because the C++11 narrowing checks continue to work as expected. For example, typing `uint8_t{1_MiB};` will continue to fail with the correct error message `error: constant expression evaluates to 1048576 which cannot be narrowed to type 'uint8_t' (aka 'unsigned char') [-Wc++11-narrowing]` (like it does on current master).

ACKs for top commit:
  l0rinc:
    ACK fa43da21f1
  achow101:
    ACK fa43da21f1
  hebasto:
    ACK fa43da21f1, I have reviewed the code and it looks OK.
  hodlinator:
    ACK fa43da21f1

Tree-SHA512: e19f6bd18c519c2a56d44fbc9e65b02e630bc71170f02a8a8955bf5c9bb2924b55ec2f810de2bbc961162aa668b7383c9fe9b5261fa1de7d9e8413003c32fa87
2026-04-24 14:52:49 -07:00
Max Edwards
ef21e29298 doc: update llvm based coverage example
On some systems the old example of using xargs to pass list of profraw
files can exceed xargs's argument limit resulting in multiple executions
of llvm-profdata merge command which overwrites it's output file losing
coverage information. Switch to using a file with a list of filenames.
2026-04-24 15:55:16 -04:00
MarcoFalke
fa43da21f1 refactor: Run ShouldWarnOversizedDbCache calculation in u64
This follows the approach of the MiB and GiB operators.

This allows to remove some `if constexpr (SIZE_MAX == UINT64_MAX)` in
the tests.
2026-04-24 16:43:41 +02:00
MarcoFalke
fa5801762e util: Return uint64_t from _MiB and _GiB operators 2026-04-24 16:43:34 +02:00
rkrux
a1e534bbf0 doc: clarify clang-tidy in developer notes
Recently, I ran clang-tidy in my system and had to figure out setting it up
correcty on my system (macOS) & understanding its output while tweaking
few arguments that made the output easier to parse.

This patch documents those in the developer notes.
2026-04-24 19:04:43 +05:30
MarcoFalke
fa204100e1 streams: Remove confusing DataStream::in_avail()
The alias of the size() method is confusing, because:

* It claims to be part of the Bitcoin Core stream subset (streams
  interface), but this is not used by any other stream interface. Mostly
  the `write(std::span)` and `read(std::span)` define the stream
  interface.
* It casts the size_t to i32, but the only place that calls the function
  casts that back to size_t.
* Providing this alias for size() without a proper reason is confusing.

Fix all issues by removing it and using the size() method.
2026-04-24 12:46:03 +02:00
MarcoFalke
fa5ab0220e move-only: Extract ProcessPong() helper
This commit can be reviewed with the git options:
--color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
2026-04-24 12:44:51 +02:00
rkrux
8deed0df06 doc: add release notes for PR 34911 2026-04-24 15:49:45 +05:30