mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
1d9f1cb4bdkernel: improve BlockChecked ownership semantics (stickies-v)9ba1fff29ekernel: refactor: ConnectTip to pass block pointer by value (stickies-v) Pull request description: Subscribers to the BlockChecked validation interface event may need access to the block outside of the callback scope. Currently, this is only possible by copying the block, which makes exposing this validation interface event publicly either cumbersome or with significant copy overhead. By using shared_ptr, we make the shared ownership explicit and allow users to safely use the block outside of the callback scope. By using a const-ref shared_ptr, no atomic reference count cost is incurred if a subscriber does not require block ownership. For example: in #30595, this would allow us to drop the `kernel_BlockPointer` handle entirely, and generalize everything into `kernel_Block`. This PoC is implemented in https://github.com/stickies-v/bitcoin/commits/kernel/remove-blockpointer/. --- ### Performance I have added a benchmark in a [separate branch](https://github.com/stickies-v/bitcoin/commits/2025-07/validation-interface-ownership-benched/), to ensure this change does not lead to a problematic performance regression. Since most of the overhead comes from the subscribers, I have added scenarios for `One`, `Two`, and `Ten` subscribers. From these results, it appears there is no meaningful performance difference on my machine. When `BlockChecked()` takes a `const CBlock&` reference _(master)_: | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 170.09 | 5,879,308.26 | 0.3% | 0.01 | `BlockCheckedOne` | 1,603.95 | 623,460.10 | 0.5% | 0.01 | `BlockCheckedTen` | 336.00 | 2,976,173.37 | 1.1% | 0.01 | `BlockCheckedTwo` When `BlockChecked()` takes a `const std::shared_ptr<const CBlock>&` _(this PR)_: | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 172.20 | 5,807,155.33 | 0.1% | 0.01 | `BlockCheckedOne` | 1,596.79 | 626,254.52 | 0.0% | 0.01 | `BlockCheckedTen` | 333.38 | 2,999,603.17 | 0.3% | 0.01 | `BlockCheckedTwo` ACKs for top commit: achow101: ACK1d9f1cb4bdw0xlt: reACK1d9f1cb4bdryanofsky: Code review ACK1d9f1cb4bd. These all seem like simple changes that make sense TheCharlatan: ACK1d9f1cb4bdyuvicc: Code Review ACK1d9f1cb4bdTree-SHA512: 7ed0cccb7883dbb1885917ef749ab7cae5d60ee803b7e3145b2954d885e81ba8c9d5ab1edb9694ce6b308235c621094c029024eaf99f1aab1b47311c40958095
Test library
This contains files for the test library, which is used by the test binaries (unit tests, benchmarks, fuzzers, gui tests).
Generally, the files in this folder should be well-separated modules. New code should be added to existing modules or (when in doubt) a new module should be created.
The utilities in here are compiled into a library, which does not hold any state. However, the main file setup_common
defines the common test setup for all test binaries. The test binaries will handle the global state when they
instantiate the BasicTestingSetup (or one of its derived classes).