{
 "number": 36451,
 "repo": "bitcoin/bitcoin",
 "url": "https://github.com/bitcoin/bitcoin/pull/36451",
 "title": "refactor: Use NotNull for CreateNewBlock and pimpls",
 "author": "maflcko",
 "author_association": "MEMBER",
 "created_at": "2026-10-07T11:35:08Z",
 "updated_at": "2026-10-31T11:35:25Z",
 "description_hash": "04b26c59f1d5c659",
 "age_days": 25,
 "draft": true,
 "labels": [
  "Refactoring",
  "CI failed"
 ],
 "milestone": null,
 "base": "master",
 "head_sha": "fa0e2f600bf901f7c8d4e1574b4d3ad1e80a5cff",
 "head_ref": "2610-more-not-null-refactor",
 "head_repo": "maflcko/bitcoin-core",
 "head_history": [],
 "additions": 43,
 "deletions": 34,
 "changed_files": 20,
 "commit_count": 3,
 "size_bucket": "S",
 "mergeable_state": "unstable",
 "bot": {
  "drahtbot": {
   "present": true,
   "reviews": {
    "concept_ack": [
     {
      "login": "sedited",
      "url": "https://github.com/bitcoin/bitcoin/pull/36451#issuecomment-6037352080"
     },
     {
      "login": "stickies-v",
      "url": "https://github.com/bitcoin/bitcoin/pull/36451#issuecomment-6038861130"
     },
     {
      "login": "Sjors",
      "url": "https://github.com/bitcoin/bitcoin/pull/36451#pullrequestreview-5580502120"
     }
    ]
   },
   "conflicts": []
  }
 },
 "acks_parsed": {
  "sedited": {
   "kind": "concept_ack",
   "hash": null,
   "t": "2026-10-07T11:54:08Z",
   "stale": false
  },
  "stickies-v": {
   "kind": "concept_ack",
   "hash": null,
   "t": "2026-10-07T13:22:29Z",
   "stale": false
  },
  "Sjors": {
   "kind": "concept_ack",
   "hash": null,
   "t": "2026-10-20T04:01:42Z",
   "stale": false
  }
 },
 "acks_tally": {
  "ack": 0,
  "stale_ack": 0,
  "concept_ack": 3,
  "approach_ack": 0,
  "nack": 0,
  "concept_nack": 0,
  "approach_nack": 0
 },
 "reviews": {
  "approved": 0,
  "changes_requested": 0,
  "distinct_reviewers": [
   "Sjors",
   "hebasto",
   "sedited",
   "stickies-v"
  ]
 },
 "signals": {
  "needs_rebase": false,
  "ci_failed": true,
  "mergeable_state": "unstable",
  "last_author_activity": "2026-10-20T06:26:20Z",
  "last_reviewer_activity": "2026-10-20T04:01:42Z",
  "last_reviewer": "Sjors",
  "author_silent_days": 12,
  "waiting_on_author_days": 0,
  "days_since_update": 1
 },
 "refs": {
  "mentioned": [],
  "depends_on": [],
  "fixes": [],
  "linked_issues": [],
  "references": [],
  "conflicts": []
 },
 "stack": {
  "shares_commits_with": [],
  "based_on": [],
  "base_for": []
 },
 "review_paths": [
  "src/node/block_template_manager.cpp",
  "src/node/miner.cpp"
 ],
 "body": "Current code uses nullable smart pointers for some stuff that is never null. This is perfectly fine, but a bit confusing:\n\n* When reading the code, it is not clear which pointer is nullable or never null.\n* 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.\n* While some places have the redundant null checks on pointers that are never null, other places do not, which adds to the confusion.\n\nClarify this at compile-time by using `NotNull` (or a plain reference)",
 "commits": [
  {
   "sha": "fa5b5027fbbfdb186f5f9e94ae8128be0b191862",
   "date": "2026-10-07T11:04:11Z",
   "message": "test: Add some NotNull test cases\n\nSuggested in https://github.com/bitcoin/bitcoin/pull/34844#pullrequestreview-5427569147"
  },
  {
   "sha": "fa7a0e7744c902e327caaf7ee4d694e362729fc6",
   "date": "2026-10-07T11:11:25Z",
   "message": "refactor: Mark pimpls as NotNull\n\nSuggested in https://github.com/bitcoin/bitcoin/pull/34844#pullrequestreview-5268474301\n\nMostly to see at compile time which m_impl is nullable. E.g.:\nsrc/ipc/libmultiprocess/include/mp/proxy-io.h:  m_impl.reset();"
  },
  {
   "sha": "fa0e2f600bf901f7c8d4e1574b4d3ad1e80a5cff",
   "date": "2026-10-07T11:28:38Z",
   "message": "refactor: Return NotNull from CreateNewBlock\n\nA nullptr is never returned, so the existing code is confusing, because\nit either has redundant and dead checks for a nullptr, or the existing\ncode is \"missing\" them.\n\nFix both issues by marking the type as NotNull at compile-time."
  }
 ],
 "timeline": [
  {
   "t": "2026-10-07T11:54:08Z",
   "kind": "comment",
   "who": "sedited",
   "assoc": "MEMBER",
   "text": "Concept ACK",
   "id": "c:6037352080",
   "url": "https://github.com/bitcoin/bitcoin/pull/36451#issuecomment-6037352080",
   "hash": "e8334cc43879b73c",
   "edited": null
  },
  {
   "t": "2026-10-07T12:06:44Z",
   "kind": "comment",
   "who": "maflcko",
   "assoc": "MEMBER",
   "text": "The Windows MSVC bugs are a bit tiring. Can someone remove it? Ref: https://github.com/bitcoin/bitcoin/issues/36153",
   "id": "c:6037550515",
   "url": "https://github.com/bitcoin/bitcoin/pull/36451#issuecomment-6037550515",
   "hash": "33164fc6dee213a4",
   "edited": null
  },
  {
   "t": "2026-10-07T13:22:29Z",
   "kind": "comment",
   "who": "stickies-v",
   "assoc": "MEMBER",
   "text": "Concept ACK",
   "id": "c:6038861130",
   "url": "https://github.com/bitcoin/bitcoin/pull/36451#issuecomment-6038861130",
   "hash": "e8334cc43879b73c",
   "edited": null
  },
  {
   "t": "2026-10-14T07:55:57Z",
   "kind": "comment",
   "who": "hebasto",
   "assoc": "MEMBER",
   "text": "[quoted text omitted]\n\nHere is an MRE: https://godbolt.org/z/Kadaq5h46.\n\nHowever, https://en.cppreference.com/cpp/compiler_support/20 lists P1825R0 as implemented in MSVC since v19.24 VS 2019 16.4.",
   "id": "c:6163666679",
   "url": "https://github.com/bitcoin/bitcoin/pull/36451#issuecomment-6163666679",
   "hash": "65b03bea0bf85d5b",
   "edited": null
  },
  {
   "t": "2026-10-20T03:42:45Z",
   "kind": "review_comment",
   "who": "Sjors",
   "assoc": "MEMBER",
   "path": "src/node/block_template_manager.cpp",
   "commit": "fa0e2f600bf901f7c8d4e1574b4d3ad1e80a5cff",
   "in_reply_to": null,
   "text": "In fa0e2f600bf901f7c8d4e1574b4d3ad1e80a5cff _refactor: Return NotNull from CreateNewBlock_: this might be worth its own commit, e.g. https://github.com/Sjors/bitcoin/commit/d5591a9143cae9829fb1c8a375b88b4297ff7070",
   "id": "rc:4321233678",
   "url": "https://github.com/bitcoin/bitcoin/pull/36451#discussion_r4321233678",
   "hash": "f833e855874e5a10",
   "edited": "2026-10-20T04:01:42Z"
  },
  {
   "t": "2026-10-20T03:51:46Z",
   "kind": "review_comment",
   "who": "Sjors",
   "assoc": "MEMBER",
   "path": "src/node/miner.cpp",
   "commit": "fa0e2f600bf901f7c8d4e1574b4d3ad1e80a5cff",
   "in_reply_to": null,
   "text": "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:\n\n```\nnote: explicit constructor is not a candidate\n   49 |     constexpr explicit NotNull(U&& u) noexcept(...)\n      |                        ^\n```\n\n(the current code is fine, I don't think we should make the constructor implicit)",
   "id": "rc:4321290725",
   "url": "https://github.com/bitcoin/bitcoin/pull/36451#discussion_r4321290725",
   "hash": "bdb22cba0be423ba",
   "edited": "2026-10-20T04:02:53Z"
  },
  {
   "t": "2026-10-20T04:01:42Z",
   "kind": "review",
   "who": "Sjors",
   "assoc": "MEMBER",
   "state": "COMMENTED",
   "commit": "fa0e2f600bf901f7c8d4e1574b4d3ad1e80a5cff",
   "text": "Concept ACK, at least in the context of `CreateNewBlock` in fa0e2f600bf901f7c8d4e1574b4d3ad1e80a5cff it adds much useful clarity.",
   "id": "r:5580502120",
   "url": "https://github.com/bitcoin/bitcoin/pull/36451#pullrequestreview-5580502120",
   "hash": "5640e099db88bd6d",
   "edited": "2026-10-20T04:01:59Z"
  },
  {
   "t": "2026-10-20T06:25:37Z",
   "kind": "review_comment",
   "who": "maflcko",
   "assoc": "MEMBER",
   "path": "src/node/miner.cpp",
   "commit": "fa0e2f600bf901f7c8d4e1574b4d3ad1e80a5cff",
   "in_reply_to": 4321290725,
   "text": "Yes, being explicit is intentional, since the `NotNull` ctor acts as an `Assert`  on the value.",
   "id": "rc:4322071539",
   "url": "https://github.com/bitcoin/bitcoin/pull/36451#discussion_r4322071539",
   "hash": "468448e3e96f6ab6",
   "edited": null
  },
  {
   "t": "2026-10-20T06:26:20Z",
   "kind": "review_comment",
   "who": "maflcko",
   "assoc": "MEMBER",
   "path": "src/node/block_template_manager.cpp",
   "commit": "fa0e2f600bf901f7c8d4e1574b4d3ad1e80a5cff",
   "in_reply_to": 4321233678,
   "text": "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.",
   "id": "rc:4322075637",
   "url": "https://github.com/bitcoin/bitcoin/pull/36451#discussion_r4322075637",
   "hash": "e2a070a383f00da4",
   "edited": "2026-10-20T06:26:21Z"
  }
 ],
 "labels_log": [
  {
   "t": "2026-10-07T11:35:14Z",
   "action": "labeled",
   "label": "Refactoring",
   "who": "DrahtBot"
  },
  {
   "t": "2026-10-07T12:24:32Z",
   "action": "labeled",
   "label": "CI failed",
   "who": "DrahtBot"
  }
 ],
 "state_log": [
  {
   "t": "2026-10-07T11:35:12Z",
   "kind": "renamed",
   "who": "DrahtBot",
   "from": " refactor: Use NotNull for CreateNewBlock and pimpls ",
   "to": "refactor: Use NotNull for CreateNewBlock and pimpls"
  },
  {
   "t": "2026-10-07T12:06:10Z",
   "kind": "convert_to_draft",
   "who": "maflcko"
  }
 ],
 "text_chars": 2661,
 "text_tokens_estimate": 665,
 "changed_paths": [
  "src/addrman.h",
  "src/dbwrapper.h",
  "src/musig.h",
  "src/node/block_template_manager.cpp",
  "src/node/block_template_manager.h",
  "src/node/interfaces.cpp",
  "src/node/miner.cpp",
  "src/node/miner.h",
  "src/node/txdownloadman.h",
  "src/node/txreconciliation.h",
  "src/policy/fees/mempool_estimator.cpp",
  "src/rpc/mining.cpp",
  "src/test/fuzz/util/check_globals.h",
  "src/test/miner_tests.cpp",
  "src/test/peerman_tests.cpp",
  "src/test/util/mining.cpp",
  "src/test/util/setup_common.cpp",
  "src/test/util_not_null_tests.cpp",
  "src/test/validation_block_tests.cpp",
  "src/txrequest.h"
 ],
 "files": [
  {
   "path": "src/addrman.h",
   "add": 2,
   "del": 1
  },
  {
   "path": "src/dbwrapper.h",
   "add": 2,
   "del": 2
  },
  {
   "path": "src/musig.h",
   "add": 2,
   "del": 1
  },
  {
   "path": "src/node/block_template_manager.cpp",
   "add": 4,
   "del": 4
  },
  {
   "path": "src/node/block_template_manager.h",
   "add": 3,
   "del": 2
  },
  {
   "path": "src/node/interfaces.cpp",
   "add": 5,
   "del": 5
  },
  {
   "path": "src/node/miner.cpp",
   "add": 2,
   "del": 2
  },
  {
   "path": "src/node/miner.h",
   "add": 2,
   "del": 1
  },
  {
   "path": "src/node/txdownloadman.h",
   "add": 2,
   "del": 1
  },
  {
   "path": "src/node/txreconciliation.h",
   "add": 2,
   "del": 1
  },
  {
   "path": "src/policy/fees/mempool_estimator.cpp",
   "add": 0,
   "del": 1
  },
  {
   "path": "src/rpc/mining.cpp",
   "add": 2,
   "del": 4
  },
  {
   "path": "src/test/fuzz/util/check_globals.h",
   "add": 3,
   "del": 1
  },
  {
   "path": "src/test/miner_tests.cpp",
   "add": 0,
   "del": 1
  },
  {
   "path": "src/test/peerman_tests.cpp",
   "add": 0,
   "del": 1
  },
  {
   "path": "src/test/util/mining.cpp",
   "add": 2,
   "del": 2
  },
  {
   "path": "src/test/util/setup_common.cpp",
   "add": 0,
   "del": 1
  },
  {
   "path": "src/test/util_not_null_tests.cpp",
   "add": 8,
   "del": 0
  },
  {
   "path": "src/test/validation_block_tests.cpp",
   "add": 0,
   "del": 2
  },
  {
   "path": "src/txrequest.h",
   "add": 2,
   "del": 1
  }
 ],
 "test_lines": 21,
 "git": {
  "head": "fa0e2f600bf901f7c8d4e1574b4d3ad1e80a5cff",
  "head_matches_backup": true,
  "base": "9523d2b4a185c704994ef44d2229c3d1604cb9e5",
  "patch_id": "3e1aeaa6ca3c4184",
  "commits": [
   {
    "sha": "fa5b5027fb",
    "subject": "test: Add some NotNull test cases",
    "files": 1,
    "add": 8,
    "del": 0
   },
   {
    "sha": "fa7a0e7744",
    "subject": "refactor: Mark pimpls as NotNull",
    "files": 7,
    "add": 15,
    "del": 8
   },
   {
    "sha": "fa0e2f600b",
    "subject": "refactor: Return NotNull from CreateNewBlock",
    "files": 12,
    "add": 20,
    "del": 26
   }
  ],
  "patch_truncated": false
 },
 "patch_id": "3e1aeaa6ca3c4184",
 "input_hash": "5b94ea3e99083502",
 "extracted_at": "2026-11-02T01:09:49+00:00"
}