49281 Commits

Author SHA1 Message Date
Ava Chow
567ff2b6d6 Merge bitcoin/bitcoin#33196: docs: clarify RPC credentials security boundary
938312d7a6 docs: clarify RPC credentials security boundary (crStiv)

Pull request description:

  Explicitly states that RPC credentials grant full administrative access to the node and filesystem resources accessible by bitcoind. Adds a new section in JSON-RPC-interface.md to address issue https://github.com/bitcoin/bitcoin/issues/32274 by documenting that providing RPC credentials to untrusted clients

  reopened #32424

  P.S. I've tried to somehow squash all the commits from the previous pr but accidentally closed the pr and had no idea how to return back, therefore created a new pr, I'm really sorry for the inconvenience

ACKs for top commit:
  achow101:
    ACK 938312d7a6
  janb84:
    re ACK 938312d7a6
  sedited:
    ACK 938312d7a6

Tree-SHA512: 54db0651cfe4a92d700d09c822db5cb68f60f17a4634eb8f132939294e7a0ca2aea15ddc4d581610976158f7546e9c4463cfe113de9500162a0f107e168833cd
2026-05-01 17:34:17 -07:00
merge-script
3c2646eacc Merge bitcoin/bitcoin#34026: fuzz: Add tests for CCoinControl methods
2104282ddd fuzz: Add tests for CCoinControl methods (Chandra Pratap)
43b09b993d fuzz: Improve oracle for existing CCoinControl tests (Chandra Pratap)

Pull request description:

  The `ccoincontrol` fuzzer misses tests for a number of `CCoinControl` operations. Add them.

  While at it, improve the oracle for the existing tests.

ACKs for top commit:
  l0rinc:
    Lightly tested code review ACK 2104282ddd
  brunoerg:
    reACK 2104282ddd
  sedited:
    Re-ACK 2104282ddd

Tree-SHA512: bfc8c9a51fca94437332056c476840d841a5b42dd6749cb34105b7ae78215ec9c3eb0f407e1a5f51b3ac20d7abb97cae7c21ad2146d5be9409edbc2cd2c568ee
2026-05-01 22:42:48 +02:00
w0xlt
bfbf1a7ef3 kernel: Expose btck_transaction_check consensus function
Add btck_transaction_check() to the libbitcoinkernel C API, exposing
context-free transaction consensus validation (consensus/tx_check.h).

Introduces btck_TxValidationState with introspection and lifecycle
functions. btck_TxValidationResult is exposed for compatibility with
existing validation-state APIs, though btck_transaction_check currently
reaches only UNSET and CONSENSUS.

Includes C++ wrapper and test coverage for btck_transaction_check using
test vectors from tx_valid.json / tx_invalid.json.
2026-04-30 17:39:25 -07:00
Ava Chow
404470505a Merge bitcoin/bitcoin#34256: test: support get_bind_addrs and feature_bind_extra on macOS & BSD
1950da94fc test: enable `rpc_bind` on macOS and BSD (Lőrinc)
7236a05503 test: enable `feature_bind_extra` on macOS and BSD (Lőrinc)

Pull request description:

  ### Problem

  Some functional tests are shown as skipped when running on macOS & BSD because `test_framework/netutil.py` only implemented the Linux-specific logic for checking which TCP sockets a node is listening on.

  ### Fix

  Add macOS and BSD implementations in `test/functional/test_framework/netutil.py` so tests can query:

  * which TCP sockets a node is listening on (`get_bind_addrs()`, via `lsof`)
  * a non-loopback interface address (`all_interfaces()`, via `ifconfig`)

  Then enable the previously Linux-only tests by switching to a shared POSIX platform guard.

  ### Commands
  <details>
  <summary><code>get_bind_addrs()</code> (<code>lsof</code> + regex)</summary>

  > Command used
  ```bash
  lsof -nP -a -p <pid> -iTCP -sTCP:LISTEN -Ftn
  ```

  > Flags

  - -D: device cache warnings
  - -n: no hostname resolution
  - -P: no service/port-name resolution
  - -a: AND all conditions
  - -p <pid>: filter by process ID
  - -iTCP: TCP sockets only
  - -sTCP:LISTEN: listening sockets only
  - -Ftn: machine-readable output (fields: type `t`, name `n`)

  > Regex parser

  ```regex
  t(IPv[46])\nn(\*|\[.+?]|[^:]+):(\d+)
  ```
  > Captured groups

  - group 1: IPv4 / IPv6 (used to disambiguate `*`)
  - group 2: host (`*`, `[::1]`, `127.0.0.1`, ...)
  - group 3: port
  </details>

  <details>
  <summary><code>all_interfaces()</code> (<code>ifconfig</code> + regex)</summary>

  > Command used

  ```bash
  ifconfig -au
  ```

  > Regex parsing

  Interface blocks:
  ```regex
  (?m)^(?P<iface>\S+):(?P<block>[^\n]*(?:\n[ \t]+[^\n]*)*)
  ```

  IPv4 extraction within each block:
  ```regex
  inet (\S+)
  ```
  </details>

  ### Notes

  The only remaining platform skips on macOS are the USDT/BPF tracing tests (`interface_usdt_*.py`).

ACKs for top commit:
  Sjors:
    ACK 1950da94fc
  achow101:
    ACK 1950da94fc
  willcl-ark:
    tACK 1950da94fc

Tree-SHA512: 4cecc88852623f3fe3a7dccceb0e71932824c1ed7f1d4ab89b953ff6b7991afbd0b016c819c17e966bed53082dd623a832752b8847711861009cd5ffc4677367
2026-04-30 14:06:01 -07:00
merge-script
25100fc28d Merge bitcoin/bitcoin#35186: util, iwyu: Add missed header
d28179bac9 util, iwyu: Add missed header (Hennadii Stepanov)

Pull request description:

  This PR amends https://github.com/bitcoin/bitcoin/pull/34669 and fixes the [CI](https://github.com/bitcoin/bitcoin/actions/runs/25182795747/job/73832160104).

ACKs for top commit:
  pinheadmz:
    ACK d28179bac9
  brunoerg:
    ACK d28179bac9

Tree-SHA512: 09c79d489d7903ae6b6b9d86c18ba176acf2cdabde5b73bcbd76a219958e5234327ca943ab13ea17a921ff501b0ebef0de68113571e9a8bf511b5ac3f8ca9f4a
2026-04-30 21:02:08 +01:00
Hennadii Stepanov
d28179bac9 util, iwyu: Add missed header 2026-04-30 20:42:12 +01:00
Ava Chow
32e479f7a5 Merge bitcoin/bitcoin#34669: feefrac: drop comparison and operator{<<,>>} for sorted wrappers
1aa78cdab6 clusterlin: adopt STL ranges algorithms (refactor) (Pieter Wuille)
747da25360 feefrac: drop comparison and operator{<<,>>} for sorted wrappers (Pieter Wuille)

Pull request description:

  Instead of having an unintuitive but strong implicit sort order on `FeeFrac` (first increasing feerate, then decreasing size), and separate overloaded `operator<<` and `operator>>` that implement a weak ordering that only looks at feerate, replace these with explicit wrapper classes which make the behavior more explicit (`ByRatio` and `ByRatioNegSize`).

  This allows for things like `ByRatio{a} <= ByRatio{b}`, instead of the earlier `!(a >> b)`. It also supports usage inside `std::min`/`std::max`/`std::less`, and `std::greater`, so one can use:
  * `std::max<ByRatioNegSize<FeeFrac>>(a, b)` to get the highest-feerate `FeeFrac`, tie-breaking by smallest size.
  * `std::ranges::sort(v, std::greater<ByRatioNegSize<FeeFrac>>{});` to sort a vector that way.

  Suggested in https://github.com/bitcoin/bitcoin/pull/34257#discussion_r2780475893.

ACKs for top commit:
  achow101:
    ACK 1aa78cdab6
  sedited:
    ACK 1aa78cdab6
  ajtowns:
    ACK 1aa78cdab6

Tree-SHA512: d76657b15f6d745e5ca01c67fd5b101fdc418e6301646d14e575b6564bfa2fe0eb40a95a7ff95a4420624ef6b67224d35e4713aa5bbc0d293e08fe44c0cc6db0
2026-04-30 11:35:53 -07:00
Vasil Dimov
11713c9fa9 net: make CConnman::m_nodes_mutex non-recursive
This change includes `s/RecursiveMutex/Mutex/` and a pile of
annotations to keep the compiler happy after the type change.

Partially resolves: https://github.com/bitcoin/bitcoin/issues/19303
2026-04-30 13:41:44 +02:00
Vasil Dimov
aec4fa2de0 net: drop the only recursive usage of CConnman::m_nodes_mutex
The only recursive usage of `CConnman::m_nodes_mutex` is from
`PeerManagerImpl::MaybeSetPeerAsAnnouncingHeaderAndIDs()` which uses
nested calls to `CConnman::ForNode()` to trim the size of
`lNodesAnnouncingHeaderAndIDs` to `<= 3`. This need not be nested, so
take it out.

Before:
```
fornode(newnode)
    if (size >= 3)
        fornode(front) handle removal of front
        pop front
    push back newnode
```

After:
```
fornode(newnode)
    push back newnode
if (size > 3)
    fornode(front) handle removal of front
    pop front
```

`lNodesAnnouncingHeaderAndIDs` is protected by `cs_main` which is locked
during the entire operation.
2026-04-30 13:21:46 +02:00
David Gumberg
eed7af666b doc: Add release note for disallowing some wallet path names 2026-04-29 16:23:24 -07:00
Ava Chow
3d7f0e4ed5 wallettool: Use GetWalletPath to determine the wallet path
Instead of computing the path separately, use GetWalletPath to use the
behavior and error checking of the typical wallet path computation.
2026-04-29 16:23:24 -07:00
Ava Chow
ef499680c8 Merge bitcoin/bitcoin#34176: wallet: crash fix, handle non-writable db directories
08925d5ee7 test: add coverage for loading a wallet in a non-writable directory (furszy)
0218966c0d test: add coverage for wallet creation in non-writable directory (furszy)
bc0090f1d6 wallet: handle non-writable db directories (furszy)

Pull request description:

  Make wallet creation and load fail with a clear error when the db directory isn’t writable.

  #### 1) For Wallet Creation

  Before: creating a wallet would return a generic error:
  "SQLiteDatabase: Failed to open database: unable to open database file"

  After: creating a wallet returns:
  "SQLiteDatabase: Failed to open database in directory <dir_path>: directory is not writable"

  #### 2) For Wallet Loading

  We currently allow loading wallets located on non-writable directories. This is problematic
  because the node crashes on any subsequent write; generating a block is enough to trigger it.
  Can be verified just by running the following test on master: 85fa4e2910

  Also, to check directory writability, this creates a tmp file rather than relying on the
  `permissions()` functions, since perms bits alone may not reliably reflect actual writability
  in some systems.

  Testing Note:
  Pushed the tests in separate commits so they can be cherry-picked on master for comparison.

ACKs for top commit:
  rkrux:
    re-ACK 08925d5ee7
  achow101:
    ACK 08925d5ee7
  seduless:
    Tested ACK 08925d5ee7

Tree-SHA512: e480eab329a1d595fe0b191e83c97956e3ff1d1e335ada8ac6fe72bc4b2bb9b13b0d49db0254d34ad75f816db06d9cd0c21d3063d7d8ee6687a7ea2324c36288
2026-04-29 15:53:01 -07:00
Ava Chow
a39cc16b43 doc: Release note for addhdkey 2026-04-29 15:11:46 -07:00
Ava Chow
89b9a01b4e wallet, rpc: Disallow importing unused() to wallets without privkeys 2026-04-29 15:11:46 -07:00
Ava Chow
35bbee6374 wallet, rpc: Disallow import of unused() if key already exists 2026-04-29 15:11:46 -07:00
Ava Chow
f3f8bcbd1d wallet: Add addhdkey RPC 2026-04-29 15:11:44 -07:00
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
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