refactor: Use NotNull for CreateNewBlock and pimpls #36451

pull maflcko wants to merge 4 commits into bitcoin:master from maflcko:2610-more-not-null-refactor changing 30 files +78 −52
  1. maflcko commented at 11:35 AM on October 7, 2026: member

    Current code uses nullable smart pointers for some stuff that is never null. This is perfectly fine, but a bit confusing:

    • When reading the code, it is not clear which pointer is nullable or never null.
    • Pointers that are never null still have confusing null checks (with possible error handling return branches), which are always dead in coverage reports or when applying mutation testing.
    • While some places have the redundant null checks on pointers that are never null, other places do not, which adds to the confusion.

    Clarify this at compile-time by using NotNull (or a plain reference)

  2. DrahtBot renamed this:
    refactor: Use NotNull for CreateNewBlock and pimpls
    refactor: Use NotNull for CreateNewBlock and pimpls
    on Oct 7, 2026
  3. DrahtBot added the label Refactoring on Oct 7, 2026
  4. DrahtBot commented at 11:35 AM on October 7, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK enochaz, l0rinc, ViniciusCestarii, ryanofsky
    Concept ACK stickies-v
    Approach ACK sedited
    Stale ACK Sjors

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36808 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36808.svg"></sub> (iwyu: Fix warnings in src/test/fuzz and treat them as errors by hebasto)
    • #36598 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36598.svg"></sub> ([Demo] validation: remove AssumeUTXO by l0rinc)
    • #36525 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36525.svg"></sub> (mining: add getTotalFees(), protect m_block_template with mutex by Sjors)
    • #36356 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36356.svg"></sub> (mining: move getblocktemplate cache into BlockTemplateManager by w0xlt)
    • #35671 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35671.svg"></sub> (mining: add TxCollection to bandwidth-efficiently validate external block templates by Sjors)
    • #35591 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35591.svg"></sub> ([DO NOT MERGE] Erlay: bandwidth-efficient transaction relay protocol (Full implementation) by sr-gi)
    • #34132 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34132.svg"></sub> (coins,dbwrapper: make point-read and txindex lookup failures fatal by l0rinc)
    • #33922 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/33922.svg"></sub> (mining: add getMemoryLoad() and track template non-mempool memory footprint by Sjors)
    • #33117 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/33117.svg"></sub> (Interfaces: Expose UTXO Snapshot Loading and Add Progress Notifications by D33r-Gee)
    • #32468 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/32468.svg"></sub> (rpc: generateblock to allow multiple outputs with custom payouts by polespinasa)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. sedited commented at 11:54 AM on October 7, 2026: contributor

    Concept ACK

  6. maflcko marked this as a draft on Oct 7, 2026
  7. maflcko commented at 12:06 PM on October 7, 2026: member

    The Windows MSVC bugs are a bit tiring. Can someone remove it? Ref: https://github.com/bitcoin/bitcoin/issues/36153

  8. DrahtBot added the label CI failed on Oct 7, 2026
  9. stickies-v commented at 1:22 PM on October 7, 2026: contributor

    Concept ACK

  10. hebasto commented at 7:55 AM on October 14, 2026: member

    The Windows MSVC bugs are a bit tiring.

    Here is an MRE: https://godbolt.org/z/Kadaq5h46.

    However, https://en.cppreference.com/cpp/compiler_support/20 lists P1825R0 as implemented in MSVC since v19.24 VS 2019 16.4.

  11. in src/node/block_template_manager.cpp:130 in fa0e2f600b outdated
     126 | @@ -127,7 +127,7 @@ void BlockTemplateManager::InterruptWait(bool& interrupt_wait)
     127 |  }
     128 |  
     129 |  std::unique_ptr<CBlockTemplate> BlockTemplateManager::WaitAndCreateNewBlock(
     130 | -    const std::unique_ptr<CBlockTemplate>& block_template,
     131 | +    const CBlockTemplate& block_template,
    


    Sjors commented at 3:42 AM on October 20, 2026:

    In fa0e2f600bf901f7c8d4e1574b4d3ad1e80a5cff refactor: Return NotNull from CreateNewBlock: this might be worth its own commit, e.g. https://github.com/Sjors/bitcoin/commit/d5591a9143cae9829fb1c8a375b88b4297ff7070


    maflcko commented at 6:26 AM on October 20, 2026:

    I think it is easier to review knowing that it can not be null, so I'll leave as-is for now, but happy to rebase on your commit, if other reviewers prefer that.

  12. in src/node/miner.cpp:243 in fa0e2f600b outdated
     239 | @@ -240,7 +240,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
     240 |               Ticks<MillisecondsDouble>(time_2 - time_1),
     241 |               Ticks<MillisecondsDouble>(time_2 - time_start));
     242 |  
     243 | -    return std::move(pblocktemplate);
     244 | +    return util::NotNull{std::move(pblocktemplate)};
    


    Sjors commented at 3:51 AM on October 20, 2026:

    In fa0e2f600bf901f7c8d4e1574b4d3ad1e80a5cff refactor: Return NotNull from CreateNewBlock: having to add util::NotNull{...} is a bit tedious. But if you forget, the error is clear enough:

    note: explicit constructor is not a candidate
       49 |     constexpr explicit NotNull(U&& u) noexcept(...)
          |                        ^
    

    (the current code is fine, I don't think we should make the constructor implicit)


    maflcko commented at 6:25 AM on October 20, 2026:

    Yes, being explicit is intentional, since the NotNull ctor acts as an Assert on the value.

  13. Sjors commented at 4:01 AM on October 20, 2026: member

    Concept ACK, at least in the context of CreateNewBlock in fa0e2f600bf901f7c8d4e1574b4d3ad1e80a5cff it adds much useful clarity.

  14. maflcko marked this as ready for review on Nov 6, 2026
  15. maflcko force-pushed on Nov 6, 2026
  16. maflcko commented at 3:23 PM on November 6, 2026: member

    edit: took ralph nit

  17. test: Add some NotNull test cases
    Suggested in https://github.com/bitcoin/bitcoin/pull/34844#pullrequestreview-5427569147
    faf85b0321
  18. maflcko force-pushed on Nov 6, 2026
  19. DrahtBot removed the label CI failed on Nov 6, 2026
  20. Sjors approved
  21. Sjors commented at 8:44 AM on November 10, 2026: member

    ACK fa7e949f74168bf02a6b7abcb1687141c8c58fd0

  22. maflcko commented at 8:48 AM on November 10, 2026: member

    @Sjors Wrong thread? Usually my commits start with fa..., so this seems off.

  23. Sjors commented at 11:59 AM on November 10, 2026: member

    Oops, wrong hash, not wrong thread.

  24. DrahtBot requested review from stickies-v on Nov 10, 2026
  25. DrahtBot requested review from sedited on Nov 10, 2026
  26. ViniciusCestarii commented at 6:38 PM on November 10, 2026: contributor

    ACK fa7e949f74168bf02a6b7abcb1687141c8c58fd0

    Funny that the nullptr return in CreateNewBlock was dead since its introduction.

  27. in src/rpc/mining.cpp:411 in fa7e949f74 outdated
     405 | @@ -407,8 +406,7 @@ static RPCMethod generateblock()
     406 |      {
     407 |          LOCK(chainman.GetMutex());
     408 |          {
     409 | -            std::unique_ptr<node::CBlockTemplate> block_template{block_template_manager.CreateNewTemplate({.use_mempool = false, .coinbase_output_script = coinbase_output_script})};
     410 | -            CHECK_NONFATAL(block_template);
    


    l0rinc commented at 7:06 AM on November 11, 2026:

    fa7e949 refactor: Return NotNull from CreateNewBlock:

    There's another one in https://github.com/bitcoin/bitcoin/blob/6f1365e34f518fdc9fb963cd246abeb47a34ce8b/src/rpc/mining.cpp#L911 that we could remove


    maflcko commented at 8:19 AM on November 11, 2026:

    I can see that it can be removed, but I think it is fine to keep, because the type is still a nullable uniq ptr. The general idea was that the compiler would force you at compile time to remove a check if it didn't make any sense. This one, I can see go both ways, so I'll leave as-is

  28. in src/node/block_template_manager.cpp:135 in fa7e949f74 outdated
     131 | @@ -132,7 +132,7 @@ std::unique_ptr<CBlockTemplate> BlockTemplateManager::WaitAndCreateNewBlock(
     132 |                  // We assume tip_block is set, because this is an instance
     133 |                  // method on BlockTemplate and no template could have been
     134 |                  // generated before a tip exists.
     135 | -                tip_changed = Assume(tip_block) && tip_block != block_template->block.hashPrevBlock;
     136 | +                tip_changed = Assume(tip_block) && tip_block != block_template.block.hashPrevBlock;
    


    l0rinc commented at 7:18 AM on November 11, 2026:

    nit: not for this PR, but if you touch this line again (and don't mind turning a missing tip into an abort), maybe this would be a bit simpler (and would match the comment above it):

                    tip_changed = *Assert(tip_block) != block_template.block.hashPrevBlock;
    

    maflcko commented at 8:19 AM on November 11, 2026:

    I presume the Assume was written intentionally, so I think I'll leave as-is for now.


    Sjors commented at 10:59 AM on November 11, 2026:

    It was intentional: #31283 (review)

    Could be reconsidered, but that seems better for a seperate PR.

  29. in src/dbwrapper.cpp:407 in fa7e949f74
     405 |  }
     406 |  
     407 |  CDBIterator* CDBWrapper::NewIterator()
     408 |  {
     409 | -    return new CDBIterator{*this, std::make_unique<CDBIterator::IteratorImpl>(DBContext().pdb->NewIterator(DBContext().iteroptions))};
     410 | +    return new CDBIterator{*this, util::NotNull{std::make_unique<CDBIterator::IteratorImpl>(DBContext().pdb->NewIterator(DBContext().iteroptions))}};
    


    l0rinc commented at 7:36 AM on November 11, 2026:

    There are a few noisy util::NotNull{std::make_unique<T>(...)} usages here (dbwrapper.cpp, net.cpp (×2), txmempool.h), in a follow-up we could add a util::MakeNotNullUnique:

    /// Like std::make_unique, but returns a NotNullUniquePtr.
    template <typename T, typename... Args>
    NotNullUniquePtr<T> MakeNotNullUnique(Args&&... args)
    {
        return NotNull{std::make_unique<T>(std::forward<Args>(args)...)};
    }
    

    maflcko commented at 8:19 AM on November 11, 2026:

    Sure, can be added in a new commit or new pull


    maflcko commented at 2:36 PM on November 12, 2026:

    thx, added a new commit in the beginning

  30. in src/node/miner.cpp:132 in fa7e949f74


    l0rinc commented at 7:48 AM on November 11, 2026:

    nit: unrelated, but since we're touching CreateNewBlock, we could also avoid the naked new here:

    -    pblocktemplate.reset(new CBlockTemplate());
    +    pblocktemplate = std::make_unique<CBlockTemplate>();
    

    maflcko commented at 8:19 AM on November 11, 2026:

    Sure, could roll into a new commit or new pull


    maflcko commented at 2:38 PM on November 12, 2026:

    thx, modified the last commit

  31. l0rinc approved
  32. l0rinc commented at 7:52 AM on November 11, 2026: contributor

    ACK fa7e949f74168bf02a6b7abcb1687141c8c58fd0

    Checked that CreateNewBlock can't return null, that the converted pimpls are always initialized and never reset, and that the only movable one (MuSig2SecNonce) isn't used after a move. Remaining nits are fine in follow-ups.

  33. sedited commented at 11:20 AM on November 12, 2026: contributor

    Approach ACK

    Do you want to add the pimpl m_internals in validationinterface.h? Would also support the comments that you left unresolved from l0rinc being taken here.

  34. util: refactor: Add and use MakeNotNullShared and MakeNotNullUnique fa4785828e
  35. maflcko force-pushed on Nov 12, 2026
  36. maflcko force-pushed on Nov 12, 2026
  37. DrahtBot added the label CI failed on Nov 12, 2026
  38. maflcko force-pushed on Nov 12, 2026
  39. maflcko removed the label CI failed on Nov 12, 2026
  40. DrahtBot added the label CI failed on Nov 12, 2026
  41. DrahtBot commented at 2:56 PM on November 12, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/43239307477/job/131255305827</sub> <sub>LLM reason (✨ experimental): CI failed because IWYU added a missing <memory> include to src/addrman.h, leaving an uncommitted diff that the check rejects.</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  42. DrahtBot removed the label CI failed on Nov 12, 2026
  43. l0rinc commented at 10:41 AM on November 13, 2026: contributor

    reACK fa2187d8f7e5faf436ae8362e47af53866c8832b

    Since my last review, added non-null smart-pointer factories and simplified block-template allocation.

    Happy to re-review if @sedited’s suggestion is also applied.

  44. DrahtBot requested review from sedited on Nov 13, 2026
  45. DrahtBot requested review from ViniciusCestarii on Nov 13, 2026
  46. DrahtBot requested review from Sjors on Nov 13, 2026
  47. refactor: Mark pimpls as NotNull
    Suggested in https://github.com/bitcoin/bitcoin/pull/34844#pullrequestreview-5268474301
    
    Mostly to see at compile time which m_impl is nullable. E.g.:
    src/ipc/libmultiprocess/include/mp/proxy-io.h:  m_impl.reset();
    fa071a2c45
  48. refactor: Return NotNull from CreateNewBlock
    A nullptr is never returned, so the existing code is confusing, because
    it either has redundant and dead checks for a nullptr, or the existing
    code is "missing" them.
    
    Fix both issues by marking the type as NotNull at compile-time.
    fa91586418
  49. maflcko force-pushed on Nov 13, 2026
  50. enochaz commented at 1:36 PM on November 13, 2026: contributor

    ACK fa9158641839

    CreateNewBlock either returns a template or throws, so those null checks were dead and the wait path still checks for null before wrapping it.

  51. DrahtBot requested review from l0rinc on Nov 13, 2026
  52. l0rinc commented at 2:02 PM on November 13, 2026: contributor

    reACK fa9158641839e6dbc3cab63b07929998247b1f97

    Latest push makes ValidationSignals::m_internals non-null - its sole constructor allocates it, and nothing resets or moves it out.

  53. ViniciusCestarii commented at 6:54 PM on November 13, 2026: contributor

    reACK fa9158641839e6dbc3cab63b07929998247b1f97

  54. in src/util/not_null.h:127 in fa4785828e
     118 | @@ -119,9 +119,23 @@ NotNull(T) -> NotNull<T>;
     119 |  template <typename T, typename Deleter = std::default_delete<T>>
     120 |  using NotNullUniquePtr = NotNull<std::unique_ptr<T, Deleter>>;
     121 |  
     122 | +/// Like std::make_unique, but returns a NotNullUniquePtr.
     123 | +template <typename T, typename... Args>
     124 | +NotNullUniquePtr<T> MakeNotNullUnique(Args&&... args)
     125 | +{
     126 | +    return NotNull{std::make_unique<T>(std::forward<Args>(args)...)};
     127 | +}
    


    ryanofsky commented at 3:02 PM on November 16, 2026:

    In commit "util: refactor: Add and use MakeNotNullShared and MakeNotNullUnique" (fa4785828e804f44726102070fb1adeacbdce6e5)

    Not a blocker, and the ship may have sailed, but I think these names are not great. I'd suggest UniqueRef<T> and SharedRef<T> (with MakeUniqueRef and MakeSharedRef) instead of NotNullUniquePtr<T> and NotNullSharedPtr<T>.

    There is a big semantic difference between unique_ptr and shared_ptr: they handle lifetimes completely differently. Burying the unique vs shared distinction in the middle of the name makes a truly meaningful distinction look like noise, and makes code using these types harder to read than it needs to be. Knowing a pointer is not null is nice, because it lets you make assumptions and simplify code paths, but it's a less important property that the type name shouldn't lead with. I'd hope not to see more names like NotNullTransactionRef following this pattern.

    "Ref" seems like the right word, because a non-null smart pointer works like a reference that owns or shares what it refers to. WebKit uses the same naming: UniqueRef for a non-null unique_ptr, and Ref vs RefPtr for non-null vs nullable refcounted pointers.

    This is just an opinion from a potential user of these types, so feel free to take it or leave it.


    maflcko commented at 3:52 PM on November 16, 2026:

    Hmm, I guess this could make sense as a scripted-diff, because:

    • The NotNull docs put this in the same bucket as reference_wrapper (a not null ptr in the std lib)
    • The "not null" naming seems fine on a low level, but for high level code the inversion in the type name may be confusing

    However, stuff like if (ptr) return util::NotNull{std::move(ptr)}; would then appear inconsistent, so I am not sure about this rename?


    maflcko commented at 8:15 PM on November 17, 2026:

    However, stuff like if (ptr) return util::NotNull{std::move(ptr)}; would then appear inconsistent, so I am not sure about this rename?

    Maybe that is a good thing, because a manual NotNull construction (outside of the Make...() helpers) should be rare and it may be beneficial to make it stand out a bit more.

    Happy to push such a scripted-diff, or review a pull with it.

    <!-- [#34844 (comment)](/bitcoin-bitcoin/34844/#issuecomment-6037421299)

  55. ryanofsky approved
  56. ryanofsky commented at 3:04 PM on November 16, 2026: contributor

    Code review ACK fa9158641839e6dbc3cab63b07929998247b1f97. Nice cleanup: makes it obvious that CreateNewBlock can't fail and that these pimpls are always set, and removes the dead error paths that went with them.

  57. ryanofsky assigned ryanofsky on Nov 16, 2026
  58. ryanofsky merged this on Nov 16, 2026
  59. ryanofsky closed this on Nov 16, 2026

  60. in src/addrman.h:113 in fa071a2c45
     109 | @@ -109,7 +110,7 @@ struct AddressPosition {
     110 |  class AddrMan
     111 |  {
     112 |  protected:
     113 | -    const std::unique_ptr<AddrManImpl> m_impl;
     114 | +    const util::NotNullUniquePtr<AddrManImpl> m_impl;
    


    ryanofsky commented at 3:35 PM on November 16, 2026:

    In commit "refactor: Mark pimpls as NotNull" (fa071a2c451d2cab12e181711b2dd64d61f3ea18)

    With the current NotNull constructor, PRs like this one that introduce NotNull can look safer than they are, because changing a member to a NotNull type adds Assert calls that don't show up in the diff. It would be better to write NotNull initializers so the check is visible, using MakeNotNullUnique/MakeNotNullShared or util::NotNull{...}.

    For example, with m_impl a NotNullUniquePtr, this aborts if LoadImpl() returns null, but nothing on the line says so:

    Foo::Foo() : m_impl{LoadImpl()} {}
    

    Forwarding functions do the same: vec.emplace_back(LoadImpl()) into a vector of NotNull.

    Most other places don't have this problem, by design, because the NotNull constructor is explicit. Member initializer lists and forwarding functions are the exceptions.

    This PR has seven initializers like the one above. They all use make_unique, so they're fine, but checking them means looking outside the diff. In this PR, they could have been made clearer with:

    <details><summary>diff</summary>

    diff --git a/src/addrman.cpp b/src/addrman.cpp
    index f830acdbe3f..14f53936e3e 100644
    --- a/src/addrman.cpp
    +++ b/src/addrman.cpp
    @@ -1259,7 +1259,7 @@ std::optional<AddressPosition> AddrManImpl::FindAddressEntry(const CAddress& add
     }
    
     AddrMan::AddrMan(const NetGroupManager& netgroupman, bool deterministic, int32_t consistency_check_ratio)
    -    : m_impl(std::make_unique<AddrManImpl>(netgroupman, deterministic, consistency_check_ratio)) {}
    +    : m_impl(util::MakeNotNullUnique<AddrManImpl>(netgroupman, deterministic, consistency_check_ratio)) {}
    
     AddrMan::~AddrMan() = default;
    
    diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp
    index 77c57964a9f..ee68cefa579 100644
    --- a/src/dbwrapper.cpp
    +++ b/src/dbwrapper.cpp
    @@ -183,7 +183,7 @@ struct CDBBatch::WriteBatchImpl {
    
     CDBBatch::CDBBatch(const CDBWrapper& _parent)
         : parent{_parent},
    -      m_impl_batch{std::make_unique<CDBBatch::WriteBatchImpl>()}
    +      m_impl_batch{util::MakeNotNullUnique<CDBBatch::WriteBatchImpl>()}
     {
         m_key_scratch.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
         m_value_scratch.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
    diff --git a/src/musig.cpp b/src/musig.cpp
    index 38a49fa2f37..d344e6e34da 100644
    --- a/src/musig.cpp
    +++ b/src/musig.cpp
    @@ -100,7 +100,7 @@ public:
         bool IsValid() { return m_nonce != nullptr; }
     };
    
    -MuSig2SecNonce::MuSig2SecNonce() : m_impl{std::make_unique<MuSig2SecNonceImpl>()} {}
    +MuSig2SecNonce::MuSig2SecNonce() : m_impl{util::MakeNotNullUnique<MuSig2SecNonceImpl>()} {}
    
     MuSig2SecNonce::MuSig2SecNonce(MuSig2SecNonce&&) noexcept = default;
     MuSig2SecNonce& MuSig2SecNonce::operator=(MuSig2SecNonce&&) noexcept = default;
    diff --git a/src/node/txdownloadman_impl.cpp b/src/node/txdownloadman_impl.cpp
    index 7443367b6bf..4b8f0a54543 100644
    --- a/src/node/txdownloadman_impl.cpp
    +++ b/src/node/txdownloadman_impl.cpp
    @@ -15,7 +15,7 @@
     namespace node {
     // TxDownloadManager wrappers
     TxDownloadManager::TxDownloadManager(const TxDownloadOptions& options) :
    -    m_impl{std::make_unique<TxDownloadManagerImpl>(options)}
    +    m_impl{util::MakeNotNullUnique<TxDownloadManagerImpl>(options)}
     {}
     TxDownloadManager::~TxDownloadManager() = default;
    
    diff --git a/src/node/txreconciliation.cpp b/src/node/txreconciliation.cpp
    index 9a1f640f5a4..fb6e2417ec3 100644
    --- a/src/node/txreconciliation.cpp
    +++ b/src/node/txreconciliation.cpp
    @@ -144,7 +144,7 @@ public:
         }
     };
    
    -TxReconciliationTracker::TxReconciliationTracker(uint32_t recon_version) : m_impl{std::make_unique<TxReconciliationTracker::Impl>(recon_version)} {}
    +TxReconciliationTracker::TxReconciliationTracker(uint32_t recon_version) : m_impl{util::MakeNotNullUnique<TxReconciliationTracker::Impl>(recon_version)} {}
    
     TxReconciliationTracker::~TxReconciliationTracker() = default;
    
    diff --git a/src/test/fuzz/util/check_globals.cpp b/src/test/fuzz/util/check_globals.cpp
    index 431519dc269..11a2a34dd62 100644
    --- a/src/test/fuzz/util/check_globals.cpp
    +++ b/src/test/fuzz/util/check_globals.cpp
    @@ -56,5 +56,5 @@ struct CheckGlobalsImpl {
         }
     };
    
    -CheckGlobals::CheckGlobals() : m_impl(std::make_unique<CheckGlobalsImpl>()) {}
    +CheckGlobals::CheckGlobals() : m_impl(util::MakeNotNullUnique<CheckGlobalsImpl>()) {}
     CheckGlobals::~CheckGlobals() = default;
    diff --git a/src/txrequest.cpp b/src/txrequest.cpp
    index 53136a8e710..0fb25f592e2 100644
    --- a/src/txrequest.cpp
    +++ b/src/txrequest.cpp
    @@ -709,7 +709,7 @@ public:
     };
    
     TxRequestTracker::TxRequestTracker(bool deterministic) :
    -    m_impl{std::make_unique<TxRequestTracker::Impl>(deterministic)} {}
    +    m_impl{util::MakeNotNullUnique<TxRequestTracker::Impl>(deterministic)} {}
    
     TxRequestTracker::~TxRequestTracker() = default;
    
    

    </details>

    Other PRs could follow the same convention.

    The compiler could also catch these cases by making the constructor that takes a plain smart pointer private, so a NotNull could only be created with MakeNotNullUnique/MakeNotNullShared or a checking function like util::CheckNotNull(expr).

  61. maflcko deleted the branch on Nov 16, 2026
  62. wp5mvk46vz-hue commented at 5:23 PM on November 16, 2026: none

    ا

  63. bitcoin deleted a comment on Nov 16, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-23 23:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me