Commit Graph

293 Commits

Author SHA1 Message Date
Hennadii Stepanov
1b5ee3be59 ci: Upgrade IWYU to 0.27 compatible with Clang 23
The new IWYU release includes several improvements and bug fixes,
including:
- https://github.com/include-what-you-use/include-what-you-use/pull/1991
- https://github.com/include-what-you-use/include-what-you-use/pull/2013
- https://github.com/include-what-you-use/include-what-you-use/pull/2014
- https://github.com/include-what-you-use/include-what-you-use/pull/2058
- https://github.com/include-what-you-use/include-what-you-use/pull/2062
- https://github.com/include-what-you-use/include-what-you-use/pull/2093
2026-09-07 12:00:04 +01:00
merge-script
c90c23d388 Merge bitcoin/bitcoin#35531: txindex: hash keys and pack positions to reduce disk usage
25bed560be test: add forward-compat functional test for txindex (sedited)
703304ed8c doc: add release notes for txindex disk usage and downgrading (Andrew Toth)
8e5320a2d2 tests: cover txindex hash prefix collisions and legacy fallback (Andrew Toth)
b75efa19ba txindex: skip bloom filters and legacy lookups for new databases (Andrew Toth)
004d7c098c txindex: hash key prefixes and pack block positions (Andrew Toth)
5a255970fd refactor: move txindex db constants and legacy key to txindex_key.h (Andrew Toth)
327660134c txindex: pass the full block to DB::WriteTxs (Andrew Toth)
42771e7998 txindex: use a new block locator for downgrade safety (Andrew Toth)
4b08baed72 txindex: return optional tx and block hash from FindTx (Andrew Toth)

Pull request description:

  The current txindex uses the full 32-byte txid as keys, which takes up about 66 GB of disk space today on mainnet. Using a 5-byte key prefix instead drops the disk usage to 26 GB - cutting the size to less than half.

  Using the full 32-bytes is unnecessary since a 5-byte salted siphash will produce collisions in about 1 in 1.1 trillion. Some collisions will occur, but the penalty is just an extra disk read, deserialization and hash.
  The tx position can be appended to the key instead of used as a value, and a LevelDB iterator can seek to the prefix and then scan for the correct tx. This is an almost identical approach to `txospenderindex`.

  Also instead of storing the file position of the block, we can store only the sequence of the connected block and offset of the transaction in the block. This can be packed into a 6-byte key suffix using 3-byte representations of the sequence and offset in the block. The block file can be recovered by the CBlockIndex that is already in memory. The sequence is mapped to the block hash in the db, so we can lookup the block hash to find the CBlockIndex during reads.

  If a tx is not found with this method, we fallback to looking up the legacy entry. With this method a user with an existing db can opt to erase the `indexes/txindex` folder and reindex, or keep the current index and new entries will be appended with the smaller footprint.

  The time to index was faster on my machine with this method, 1h19m vs current 1h50m.
  Lookups are roughly the same, around 0.2ms per lookup with `getrawtransaction`.
  When testing on mainnet, I got 894,549 2-way collisions, 395 3-way collision, and 1 4-way collision that worst case could cause an extra 3 false positives when reading.

ACKs for top commit:
  l0rinc:
    diff reACK 25bed560be
  sedited:
    ACK 25bed560be
  ajtowns:
    ACK 25bed560be

Tree-SHA512: a25c79ca7e722e2f372b65f5fc11c8b194ad49f2240b4881c7e606306aabbd3604aede3f1c33606b467486affac3a3f503638f513c896935cebbc02709cb60d8
2026-08-15 15:20:47 +01:00
Andrew Toth
8e5320a2d2 tests: cover txindex hash prefix collisions and legacy fallback
Co-authored-by: l0rinc <pap.lorinc@gmail.com>
2026-08-13 23:31:36 -04:00
Andrew Toth
b75efa19ba txindex: skip bloom filters and legacy lookups for new databases
New databases never contain legacy ('t' + txid) entries.
Peek at the database before opening it, and if no legacy
entries are found, skip building bloom filters (hashed
entries are only read via iterators, which do not consult
them) and return early from lookups instead of checking
for legacy entries.
2026-08-13 23:31:36 -04:00
Andrew Toth
004d7c098c txindex: hash key prefixes and pack block positions
Use a 5-byte salted siphash to key txindex entries,
instead of the full 32-byte txid. Store the block sequence and tx position
after the hash in the key, so an iterator can scan
through any collisions and return the correct tx.

Fall back to the legacy key lookup if the tx is not found.

Co-authored-by: Pieter Wuille <pieter@wuille.net>
Co-authored-by: l0rinc <pap.lorinc@gmail.com>
Co-authored-by: Anthony Towns <aj@erisian.com.au>
2026-08-13 23:31:36 -04:00
Andrew Toth
5a255970fd refactor: move txindex db constants and legacy key to txindex_key.h
No behavior change. Moving constants to a new file to make the next commit easier to review.
2026-08-13 23:31:36 -04:00
Andrew Toth
327660134c txindex: pass the full block to DB::WriteTxs
Move the per-transaction position computation from CustomAppend into
DB::WriteTxs, so the DB layer receives the whole block instead of a
pre-built vector of positions. This is a non-functional refactor.
2026-08-13 23:31:36 -04:00
Andrew Toth
42771e7998 txindex: use a new block locator for downgrade safety
The hashed txindex entries cannot be found by older nodes. Record sync
progress under a new locator key so a downgraded node will not rely on
entries indexed by upgraded nodes, and instead continue syncing from the
legacy locator.
2026-08-13 23:31:36 -04:00
Andrew Toth
4b08baed72 txindex: return optional tx and block hash from FindTx
Co-authored-by: l0rinc <pap.lorinc@gmail.com>
2026-08-13 23:31:36 -04:00
MarcoFalke
fab1a62c87 refactor: Use inline constexpr for string literals in headers
This is needed for the next scripted-diff commit, which would otherwise
turn the const from `static const char*` into `inline const char*`.
2026-08-05 08:34:58 +02:00
MarcoFalke
5555d5dcb5 scripted-diff: Use inline constexpr over static constexpr
Both are fine and this refactor shouldn't change any behavior.

However, inline constexpr will ensure each symbol has a single address
across all TU, making the release binary smaller.

Review note: In theory the script may also cover functions, but they
were handled in the prior commit, to remove the redundant inline for
them.

-BEGIN VERIFY SCRIPT-
 sed --regexp-extended -i 's/^(static constexpr|constexpr static)\>/inline constexpr/g' $( \
   git grep --extended-regexp -l '^(static constexpr|constexpr static)' -- \
     '*.h' \
     ':(exclude)src/crc32c' \
     ':(exclude)src/ipc/libmultiprocess' \
     ':(exclude)src/minisketch' \
 )
-END VERIFY SCRIPT-
2026-08-05 08:32:32 +02:00
merge-script
c8459b6bdc Merge bitcoin/bitcoin#35568: txospenderindex: disable bloom filters to optimize disk usage
6d0ea4cf5b doc: add release notes (Andrew Toth)
a2b1c86903 txospenderindex: disable bloom filters to optimize disk usage (Andrew Toth)

Pull request description:

  LevelDB bloom filters are only consulted on `Get` point reads. This can be verified in https://github.com/bitcoin/bitcoin/blob/master/src/leveldb/table/table.cc#L224-L228. `InternalGet` is the only place that consults the filter, and it is only reached via a `Get` or `Exists` point read. The filters are never consulted for iterator seeks with an iterator created via `NewIterator`.
  txospenderindex only reads via iterator seeks, so building them is wasted effort and space.

  For a db as large as txospenderindex, this results in measurable performance and disk usage.
  On master, a full sync took 4h37m, and the resulting db was 85.0 GiB.
  On this branch, a full sync took 3h57m, and the resulting db was 80.9 GiB.
  So this is a sync speedup of 39 minutes (1.17x), and a disk space reduction of 4.2 GiB.

ACKs for top commit:
  l0rinc:
    ACK 6d0ea4cf5b
  sedited:
    Re-ACK 6d0ea4cf5b
  fjahr:
    Code review ACK 6d0ea4cf5b

Tree-SHA512: fb88b9f9a16ff31562d388e3fd9fd9590c7864dbe6093cd9430ecbce9cdc3f2a8d3fc612aade743d26ad4c6eca1e5dc9b3f1ca28d75caea1209e5c784895405d
2026-07-12 12:39:54 +02:00
Martin Zumsande
3679f1ecf5 index: Don't commit ahead of the flushed chainstate
Otherwise, if the node has an unclean restart,
indexes with state (coinstatsindex) couldn't reorg to the
last flushed tip and would be corrupted.

Also updates documentation of Commit() -
the locator functionality isn't used, so the previous text was wrong:
We must have the best block in our block index after a restart.

Co-authored-by: Fabian Jahr <fjahr@protonmail.com>
2026-07-09 16:21:28 +02:00
Martin Zumsande
65735728a5 index: Remove return value from Commit()
Since it unused in the current code.
2026-07-09 16:21:28 +02:00
Andrew Toth
a2b1c86903 txospenderindex: disable bloom filters to optimize disk usage
LevelDB bloom filters are only consulted on Get point reads.
They are not consulted for iterator seeks.
txospenderindex only reads via iterator seeks, so building
them is wasted effort and space.
2026-07-04 11:19:19 -04:00
Lőrinc
ce06878288 index: shrink txospenderindex value markers
`TxoSpenderIndex` uses LevelDB values only as presence markers. `FindSpender` iterates over keys and loads the spending transaction from the disk position stored in each key.
Write new entries with a zero-byte span instead of a serialized empty string, so rebuilt indexes avoid one extra byte per spender entry.
Existing indexes remain readable because the lookup path does not deserialize the marker value.
2026-07-01 14:46:17 -07:00
Lőrinc
d3e40af259 index: shorten indexer thread names
`BaseIndex` currently uses the same name for logs, `getindexinfo`, prune locks, and the sync thread.
Linux truncates system thread names to 15 visible bytes after the `b-` prefix, so long indexer names are clipped in system tools.

Pass a separate thread name explicitly at each `BaseIndex` call site and shorten the OS-visible indexer names to `txidx`, `blkfltbscidx`, `coinstatsidx`, and `txospenderidx`.
Add an `Assume` to `ThreadRename()` so future OS-visible thread names keep fitting the same Linux limit.
The public index names, `getindexinfo` keys, command-line options, and on-disk paths stay unchanged.

Co-authored-by: winterrdog <winterrdog@users.noreply.github.com>
Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
Co-authored-by: sedited <seb.kung@gmail.com>
Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
2026-06-16 11:16:00 +02:00
merge-script
00af5620f0 Merge bitcoin/bitcoin#35206: doc: fix doxygen links to threads in developer-notes.md
d5adb9d09b doc: fix doxygen links to threads in developer-notes.md (Matthew Zipkin)

Pull request description:

  The "threads" section of `developer-notes.md` has links to anchor tags in the code generated by doxygen. As far as I can tell this was introduced in #18645 and changes to this section of this document have continued the pattern. The problem is, the content at `https://doxygen.bitcoincore.org` gets re-rendered daily and those anchor tags are generated internally by doxygen, so they are all broken now.

  This PR adds doxygen syntax `\anchor XXXX` comments in the code where functions that run in these threads are defined, and then those stable, human-readable anchor tags are applied to the links in the doc.

  I have generated the doxygen output from this branch, hosted it on my own web server, and created a modified `developer-notes.md` with these anchor tags and my server as host for demonstration:

  https://gist.github.com/pinheadmz/ed3dda7d3c8d589e3989040519190b84#threads

  Just note when looking at this:
  - `main` is at the bottom of the html page so it might not look right at first
  - `initload` is a lambda inside `AppInitMain` so thats where doxygen renders the anchor

ACKs for top commit:
  fanquake:
    ACK d5adb9d09b
  rkrux:
    lgtm ACK d5adb9d

Tree-SHA512: c5517823a2d668b01318b3dae3d76fdd9db8a74d8c721aeb748e4f4a6cb56cb4d24e34b2590a41f8553992005cab368fca4ce322a4f204cec16ce338337ae9ee
2026-05-27 15:48:32 +01:00
Anthony Towns
02b2c41103 logging: use util/log.h where possible
Replace usage of logging.h with util/log.h where it
suffices.
2026-05-16 03:36:51 +10:00
Matthew Zipkin
d5adb9d09b doc: fix doxygen links to threads in developer-notes.md 2026-05-06 11:48:06 -04:00
Ava Chow
0cbd220294 Merge bitcoin/bitcoin#34440: refactor: Change CChain methods to use references, add tests
7c75244ade Change pindexMostWork parameter of ActivateBestChainStep() to reference (optout)
c5eb283bca Change CChain::FindFork() to take ref (optout)
20b58e281a Change CChain::Next() to take reference (optout)
fe2d6e25e0 Change CChain::Contains() to take reference (optout)
db56bcd692 test: Add CChain::FindFork() tests (optout)
8333abdd91 test: Add CChain basic tests (optout)

Pull request description:

  Refactor `CChain` methods (`Contains()`, `Next()`, `FindFork()`) to use references instead of pointers, to minimize the risk of accidental `nullptr` dereference (memory access violation). Also add missing unit tests to the `CChain` class.

  The `CChain::Contains()` method (in `src/chain.h`) dereferences its input without checking. The `Next()` method also calls into this with a `nullptr` if invoked with `nullptr`. While most call sites have indirect guarantee that the input is not `nullptr`, it's not easy to establish this to all call sites with high confidence. These methods are publicly available. There is no known high-level use case to trigger this error, but the fix is easy, and makes the code safer.

  Changes:

  - Add basic unit tests for `CChain` class methods
  - Add unit tests for `CChain::FindFork()`
  - Change `CChain::Contains()` to take reference
  - Change `CChain::Next()` to take reference
  - Change `CChain::FindFork()` to take reference
  - Change `pindexMostWork` parameter of `ActivateBestChainStep()` to reference
  - Rename changed parameters (`* pindex` --> `& index`)

  Alternative. A simpler change is to stick with pointers, with extra checks where needed, see #34416 .

  This change is remotely related to and indirectly triggered by #32875 .

  Further ideas, not considered in this PR:

  - Change `InvalidateBlock()` and `PreciousBlock()` to take references.
  - Change `CChain` internals to store references instead of pointers
  - Change CChain to always have at least one element (genesis), that way there is always genesis and tip.
  - Check related methods to return reference (guaranteed non-null) -- `FindFork`, `FindEarliestAtLeast`, `FindForkInGlobalIndex`, `blockman.AddToBlockIndex`, etc.

ACKs for top commit:
  l0rinc:
    reACK 7c75244ade
  maflcko:
    re-review ACK 7c75244ade 🌅
  achow101:
    ACK 7c75244ade
  hodlinator:
    re-ACK 7c75244ade

Tree-SHA512: 122f40120058f7e1f0273b3afed9c54966c05f06b6f2fee45bc48430617f24a5e4320a9bb7bb0ac986f2accfa22fabae5cc941b949758ddca2e9fcd472b46c33
2026-04-22 15:49:51 -07:00
Lőrinc
af0ee28eb6 refactor: use _MiB consistently for Mebibyte conversions
Replace hard-coded MiB byte conversions (e.g. `1024*1024`, `1<<20`, `1048576`) with the existing `_MiB` literal to improve readability and avoid repeating constants.
In the few spots where arithmetic involves signed values, the result is identical to the previous code assuming those quantities never turn negative.

Also switch to brace init on every declaration assigned from `_MiB`/`_GiB` literals so a future oversized value (e.g. `unsigned int x{4096_MiB}`) becomes a compile error through the C++11 narrowing check instead of silently truncating.

Extend unit tests to cover the 32-bit `size_t` overflow boundary and to assert equivalence for integer and floating-point conversions.

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
Co-authored-by: w0xlt <94266259+w0xlt@users.noreply.github.com>
2026-04-20 11:15:41 +02:00
optout
c5eb283bca Change CChain::FindFork() to take ref
The internal null-guard in FindFork() was removed in favor of adding any missing guards at call sites.
2026-04-20 08:55:51 +02:00
optout
20b58e281a Change CChain::Next() to take reference
To minimize chance of erroneous nullptr dereference, `CChain::Next()`
is changed to take a reference instead of a pointer.
Call sites have been adapted. Notably, NextSyncBlock() now checks
the FindFork() result before calling into Next(), because
the fork lookup may return null.
2026-04-20 08:55:44 +02:00
merge-script
0e2122c62e Merge bitcoin/bitcoin#32875: index: handle case where pindex_prev equals chain tip in NextSyncBlock()
db3c25cfae index: add explicit early exit in NextSyncBlock() when the input is the chain tip (Hao Xu)

Pull request description:

  When `pindex_prev` is the chain tip, `NextSyncBlock()` should return `nullptr` (there's no next block to sync). Currently this works, but relies on the fork/reorg path to produce the result: `chain.Next(tip)` returns `nullptr`, falling through to `FindFork(tip)` which returns `tip` itself, then `chain.Next(tip)` returns `nullptr` again.
  Add an explicit early return for this case. This makes `NextSyncBlock()`'s three cases self-documenting:

  1. next block exists on the active chain — return it
  2. at the chain tip — return `nullptr`
  3. on a stale branch — find the fork point and return the block after it

  It also makes the existing comment ("Since block is not in the chain") accurate — the tip is in the chain, so it shouldn't reach that path.

ACKs for top commit:
  optout21:
    crACK db3c25cfae
  furszy:
    ACK db3c25cfae
  stickies-v:
    ACK db3c25cfae

Tree-SHA512: c1633bb3d3ffed2643c8e174c2b2283deaeffd0a06eb3fb2cf03eed097bfdc5cf6fbd7ebdcdb44fd56f712be8004ad46c730a33990fb1fc6cfa629c9b14f8cd9
2026-03-30 20:01:40 +08:00
merge-script
2fe76ed832 Merge bitcoin/bitcoin#34896: ci: Upgrade IWYU to 0.26 compatible with Clang 22
3129d4a693 ci: Rename `TIDY_LLVM_V` to `IWYU_LLVM_V` in IWYU-specific code (Hennadii Stepanov)
0b489886f8 ci: Upgrade IWYU to 0.26 compatible with Clang 22 (Hennadii Stepanov)

Pull request description:

  This PR upgrades IWYU to [0.26](https://github.com/include-what-you-use/include-what-you-use/releases/tag/0.26) and removes mapping workarounds for issues that have been fixed upstream.

ACKs for top commit:
  fanquake:
    ACK 3129d4a693

Tree-SHA512: 9a926e489573d040423461c039ecda7636beb70e8214a02c1c594cbd5b89d26331455a9872c38993fa5ee6d27fdfefc2375dedc369721b2933411542a57a3884
2026-03-25 09:06:19 +08:00
Hennadii Stepanov
0b489886f8 ci: Upgrade IWYU to 0.26 compatible with Clang 22
Additionally, removes mapping workarounds for issues that have been
fixed upstream.
2026-03-22 17:12:08 +00:00
Hennadii Stepanov
48bfcfedec iwyu, doc: Document IWYU pragma: export for <threadsafety.h> 2026-03-20 15:37:51 +00:00
Hennadii Stepanov
6d2952c3c3 serialize: Add missing <span> header
Including the missing `<span>` header in `serialize.h` allows IWYU to
correctly evaluate its redundancy elsewhere.
2026-03-19 19:13:40 +00:00
Hao Xu
db3c25cfae index: add explicit early exit in NextSyncBlock() when the input is the chain tip
When pindex_prev is the chain tip, return earlier and explicitly rather than
mixing it with the reorg case. For more detail, please see PR:
https://github.com/bitcoin/bitcoin/pull/32875

Co-authored-by: l0rinc <pap.lorinc@gmail.com>
Co-authored-by: optout <optout@nostrplebs.com>
Co-authored-by: furszy <matiasfurszyfer@protonmail.com>
2026-03-17 19:44:54 +08:00
furszy
15c4889497 index: document TxoSpenderIndex::FindSpender
Hard to know what a returned std::Expected(std::nullopt) mean
if it is not documented anywhere.
2026-03-06 01:05:52 +01:00
Fabian Jahr
a1074d852a index, rpc, test: Misc formatting fixes 2026-03-05 13:15:09 +01:00
Ava Chow
d907d65acd Merge bitcoin/bitcoin#29770: index: Check all necessary block data is available before starting to sync
fd06157d14 test: Add coverage for restarted node without any block sync (Fabian Jahr)
3d7ab7ecb7 rpc, test: Address feedback from #29668 (Fabian Jahr)
312919c9dd test: Indices can not start based on block data without undo data (Fabian Jahr)
a9a3b29dd6 index: Check availability of undo data for indices (Fabian Jahr)
881ab4fc82 support multiple block status checks in CheckBlockDataAvailability (furszy)

Pull request description:

  Currently, we check that `BLOCK_HAVE_DATA` is available for all blocks an index needs to sync during startup. However, for `coinstatsindex` and `blockfilterindex` we also need the undo data for these blocks. If that data is missing in the blocks, we are currently still starting to sync each of these indices and then crash later when we encounter the missing data.

  This PR adds explicit knowledge of which block data is needed for each index and then checks its availability during startup before initializing the sync process on them.

  This also addresses a few open comments from #29668 in the last commit.

ACKs for top commit:
  achow101:
    ACK fd06157d14
  furszy:
    utACK fd06157d14
  sedited:
    Re-ACK fd06157d14

Tree-SHA512: e2ed81c93372b02daa8ddf2819df4164f96d92de05b1d48855410ecac78d5fcd9612d7f0e63a9d57d7e75a0b46e1bea278e43ea87f2693af0220d1f9c600e416
2026-02-20 15:58:48 -08:00
sstone
3d82ec5bdd Add a "tx output spender" index
Adds an outpoint -> txid index, which can be used to find which transactions spent a given output.
We use a composite key with 2 parts (suggested by @romanz): hash(spent outpoint) and tx position, with an empty value.
To find the spending tx for a given outpoint, we do a prefix search (prefix being the hash of the provided outpoint), and for all keys that match this prefix
we load the tx at the position specified in the key and return it, along with the block hash, if does spend the provided outpoint.
To handle reorgs we just erase the keys computed from the removed block.

This index is extremely useful for Lightning and more generally for layer-2 protocols that rely on chains of unpublished transactions.
If enabled, this index will be used by `gettxspendingprevout` when it does not find a spending transaction in the mempool.
2026-02-19 11:41:53 +01:00
Fabian Jahr
a9a3b29dd6 index: Check availability of undo data for indices 2026-02-17 12:44:21 +01:00
stickies-v
37cc2a2d95 logging: use util/log.h where possible
Preparation for a future commit where kernel's dependency
on logging.cpp is removed completely.

Replace usage of logging\.h with util/log\.h where it
suffices, and fix wrong includes according to iwyu.
2026-02-02 17:22:31 +00:00
Hennadii Stepanov
91824646c5 iwyu: Add temporary mapping to work around upstream bug 2026-01-30 11:50:17 +00:00
rustaceanrob
ccf9172ab3 util: Remove FilterHeaderHasher
With respect to `std::unordered_map` documentation, the `Hash` type
defined in the template is over the `Key` and not `T`, the value. This
hasher is incorrectly named as the `FilterHeader` is the value within this map.
I consider this a bug as opposed to a refactor as the key and value
relationship is implied to be `filter header -> block hash` when it is
the opposite.

Further, the hasher for the key already exists via `BlockHasher`.

ref: https://en.cppreference.com/w/cpp/container/unordered_map.html
2026-01-20 16:26:50 +00:00
merge-script
e703360577 Merge bitcoin/bitcoin#32997: index: Deduplicate HashKey / HeightKey handling
5646e6c0d3 index: restrict index helper function to namespace (Martin Zumsande)
032f3503e3 index, refactor: deduplicate LookUpOne (Martin Zumsande)
a67d3eb91d index: deduplicate Hash / Height handling (Martin Zumsande)

Pull request description:

  The logic for `DBHashKey` / `DBHeightKey` handling and lookup of entries is shared by `coinstatsindex` and `blockfilterindex`, leading to many lines of duplicated code. De-duplicate this by moving the logic to `index/db_key.h` (using templates for the index-specific `DBVal`).

ACKs for top commit:
  fjahr:
    re-ACK 5646e6c0d3
  furszy:
    utACK 5646e6c0d3
  sedited:
    ACK 5646e6c0d3

Tree-SHA512: 6f41684d6a9fd9bb01239e9f2e39a12837554f247a677eadcc242f0c1a2d44a79979f87249c4e0305ef1aa708d7056e56dfc40e1509c6d6aec2714f202fd2e09
2025-12-27 16:18:34 +00:00
TheCharlatan
d3a479cb07 kernel: Move BlockInfo to a kernel file
This should avoid having to include interfaces/chain.h from a kernel
module. interfaces/chain.h in turn includes a bunch of non-kernel
headers, that break the desired library topology and might introduce
entanglement regressions.
2025-12-21 10:24:36 +01:00
MarcoFalke
fa5f297748 scripted-diff: [doc] Unify stale copyright headers
-BEGIN VERIFY SCRIPT-

 sed --in-place --regexp-extended \
   's;( 20[0-2][0-9])(-20[0-2][0-9])? The Bitcoin Core developers;\1-present The Bitcoin Core developers;g' \
   $( git grep -l 'The Bitcoin Core developers' -- ':(exclude)COPYING' ':(exclude)src/ipc/libmultiprocess' ':(exclude)src/minisketch' )

-END VERIFY SCRIPT-
2025-12-16 22:21:15 +01:00
Ryan Ofsky
4dfe383912 refactor: Convert ChainstateRole enum to struct
Change ChainstateRole parameter passed to wallets and indexes. Wallets and
indexes need to know whether chainstate is historical and whether it is fully
validated. They should not be aware of the assumeutxo snapshot validation
process.
2025-12-12 06:49:59 -04:00
Ryan Ofsky
352ad27fc1 refactor: Add ChainstateManager::ValidatedChainstate() method
ValidatedChainstate() accessor replaces GetChainstateForIndexing() with no
change in behavior.
2025-12-12 06:49:59 -04:00
Martin Zumsande
5646e6c0d3 index: restrict index helper function to namespace 2025-12-04 12:57:13 -05:00
Martin Zumsande
032f3503e3 index, refactor: deduplicate LookUpOne
LookUpOne is used by both coinstatsindex and blockfilterindex,
the two implementations had already started to deviate slightly
for no apparent reason.
2025-12-04 12:57:13 -05:00
Martin Zumsande
a67d3eb91d index: deduplicate Hash / Height handling
The code was largely duplicated between coinstatsindex
and blockfilterindex.
Deduplicate it by moving it to a shared file.

slight change in behavior: the index name is no longer
part of the error msg in case of (un)serialization errors.
2025-12-04 12:57:12 -05:00
merge-script
69e66efe45 Merge bitcoin/bitcoin#32882: index: remove unnecessary locator cleaning in BaseIndex::Init()
facd01e6ff refactor: remove redundant locator cleanup in BaseIndex::Init() (Hao Xu)

Pull request description:

  Leverage locator.IsNull() to simplify ReadBestBlock() and remove
  unnecessary SetNull().

ACKs for top commit:
  l0rinc:
    ACK facd01e6ff
  furszy:
    utACK facd01e6ff
  sedited:
    ACK facd01e6ff

Tree-SHA512: ca418a3d4c72b9bfdb194e03d5acfacf7b567850ab385ad3a1ec6d070eedef4aea2bb8335f8bfe0316e84c22583111fc202f7603044c5d4d05754db23f75b47f
2025-12-03 13:47:17 +00:00
merge-script
3789215f73 Merge bitcoin/bitcoin#33724: refactor: Return uint64_t from GetSerializeSize
fa6c0bedd3 refactor: Return uint64_t from GetSerializeSize (MarcoFalke)
fad0c8680e refactor: Use uint64_t over size_t for serialized-size values (MarcoFalke)
fa4f388fc9 refactor: Use fixed size ints over (un)signed ints for serialized values (MarcoFalke)
fa01f38e53 move-only: Move CBlockFileInfo to kernel namespace (MarcoFalke)
fa2bbc9e4c refactor: [rpc] Remove cast when reporting serialized size (MarcoFalke)
fa364af89b test: Remove outdated comment (MarcoFalke)

Pull request description:

  Consensus code should arrive at the same conclusion, regardless of the architecture it runs on. Using architecture-specific types such as `size_t` can lead to issues, such as the low-severity [CVE-2025-46597](https://bitcoincore.org/en/2025/10/24/disclose-cve-2025-46597/).

  The CVE was already worked around, but it may be good to still fix the underlying issue.

  Fixes https://github.com/bitcoin/bitcoin/issues/33709 with a few refactors to use explicit fixed-sized integer types in serialization-size related code and concluding with a refactor to return `uint64_t` from `GetSerializeSize`. The refactors should not change any behavior, because the CVE was already worked around.

ACKs for top commit:
  Crypt-iQ:
    crACK fa6c0bedd3
  l0rinc:
    ACK fa6c0bedd3
  laanwj:
    Code review ACK fa6c0bedd3

Tree-SHA512: f45057bd86fb46011e4cb3edf0dc607057d72ed869fd6ad636562111ae80fea233b2fc45c34b02256331028359a9c3f4fa73e9b882b225bdc089d00becd0195e
2025-11-12 09:48:10 -05:00
Ava Chow
a4e96cae7d Merge bitcoin/bitcoin#33042: refactor: inline constant return values from dbwrapper write methods
743abbcbde refactor: inline constant return value of `BlockTreeDB::WriteBatchSync` and `BlockManager::WriteBlockIndexDB` and `BlockTreeDB::WriteFlag` (Lőrinc)
e030240e90 refactor: inline constant return value of `CDBWrapper::Erase` and `BlockTreeDB::WriteReindexing` (Lőrinc)
cdab9480e9 refactor: inline constant return value of `CDBWrapper::Write` (Lőrinc)
d1847cf5b5 refactor: inline constant return value of `TxIndex::DB::WriteTxs` (Lőrinc)
50b63a5698 refactor: inline constant return value of `CDBWrapper::WriteBatch` (Lőrinc)

Pull request description:

  Related to https://github.com/bitcoin/bitcoin/pull/31144#discussion_r2223587480

  ### Summary
  `WriteBatch` always returns `true` - the errors are handled by throwing `dbwrapper_error` instead.

  ### Context
  This boolean return value of the `Write` methods is confusing because it's inconsistent with `CDBWrapper::Read`, which catches exceptions and returns a boolean to indicate success/failure. It's bad that `Read` returns and `Write` throws - but it's a lot worse that `Write` advertises a return value when it actually communicates errors through exceptions.

  ### Solution
  This PR removes the constant return values from write methods and inlines `true` at their call sites. Many upstream methods had boolean return values only because they were propagating these constants - those have been cleaned up as well.

  Methods that returned a constant `true` value that now return `void`:
  - `CDBWrapper::WriteBatch`, `CDBWrapper::Write`, `CDBWrapper::Erase`
  - `TxIndex::DB::WriteTxs`
  - `BlockTreeDB::WriteReindexing`, `BlockTreeDB::WriteBatchSync`, `BlockTreeDB::WriteFlag`
  - `BlockManager::WriteBlockIndexDB`

  ### Note
  `CCoinsView::BatchWrite` (and transitively `CCoinsViewCache::Flush` & `CCoinsViewCache::Sync`) were intentionally not changed here. While all implementations return `true`, the base `CCoinsView::BatchWrite` returns `false`. Changing this would cause `coins_view` tests to fail with:
  > terminating due to uncaught exception of type std::logic_error: Not all unspent flagged entries were cleared

  We can fix that in a follow-up PR.

ACKs for top commit:
  achow101:
    ACK 743abbcbde
  janb84:
    ACK 743abbcbde
  TheCharlatan:
    ACK 743abbcbde
  sipa:
    ACK 743abbcbde

Tree-SHA512: b2a550bff066216f1958d2dd9a7ef6a9949de518cc636f8ab9c670e0b7a330c1eb8c838e458a8629acb8ac980cea6616955cd84436a7b8ab9096f6d648073b1e
2025-11-10 09:15:24 -08:00
MarcoFalke
fad0c8680e refactor: Use uint64_t over size_t for serialized-size values
The values are small enough to fit in size_t, but to avoid having to
think about it, just use uint64_t consistently for all architectures.

On 64-bit systems, this refactor is a no-op. On 32-bit systems, it could
avoid bugs in the theoretical and unexpected case where a 32-bit size_t
is too small and overflows.
2025-10-30 17:51:40 +01:00