WIP: refactor: Add [[nodiscard]] to functions returning bool+mutable ref #34520

Draft
maflcko wants to merge 3 commits from 2602-nodiscard into master AGit
maflcko commented 2026-02-05 16:58:07 +00:00 (Migrated from github.com)

Legacy code often used a function signature of the form bool Get...(const& in, mut& in_out); to implement a getter that optionally returns a value.

In modern code, this can be replaced by std::optional<_> Get...(const& in);.

However, some legacy code remains. To ensure that the "imaginary optional" is not unwrapped when the getter returns false, add a C++17 [[nodiscard]] attribute to all those legacy functions.

There were only a few places that ignored the return value. I've fixed them in separate commits.

This should be easy to review via --word-diff-regex=. and then confirming that the attribute was added to such a getter.

Legacy code often used a function signature of the form `bool Get...(const& in, mut& in_out);` to implement a getter that optionally returns a value. In modern code, this can be replaced by `std::optional<_> Get...(const& in);`. However, some legacy code remains. To ensure that the "imaginary optional" is not unwrapped when the getter returns false, add a C++17 `[[nodiscard]]` attribute to all those legacy functions. There were only a few places that ignored the return value. I've fixed them in separate commits. This should be easy to review via `--word-diff-regex=.` and then confirming that the attribute was added to such a getter.
DrahtBot commented 2026-02-05 16:58:45 +00:00 (Migrated from github.com)

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

External sites

Reviews

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

Type Reviewers
Concept ACK sedited, ajtowns
Stale ACK HowHsu, yuvicc

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36885 (wallet, rpc: Add analyzedescriptor for multisig setups by pablomartin4btc)
  • #36831 (test: split test_IsStandard into independent test cases by yuvicc)
  • #36187 (http: Restore requirement of IPv4 bind success by hodlinator)
  • #36167 (build: Enable -Wunused by fanquake)
  • #36122 (BIP460: CISA for Taproot key path spends by fjahr)
  • #35763 (util: write JSON atomically in WriteJson by kevkevinpal)
  • #35733 (sign: Remove FillableSigningProvider by achow101)
  • #35444 (wallet: make descriptor SPKM mutex non-recursive by w0xlt)
  • #35377 (wallet: Allow importing of descriptors without private keys when the wallet has the private keys by achow101)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/34520 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/34520.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/34520#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | Concept ACK | [sedited](https://github.com/bitcoin/bitcoin/pull/34520#issuecomment-3958551668), [ajtowns](https://github.com/bitcoin/bitcoin/pull/34520#pullrequestreview-3894819258) | | Stale ACK | [HowHsu](https://github.com/bitcoin/bitcoin/pull/34520#issuecomment-3859820155), [yuvicc](https://github.com/bitcoin/bitcoin/pull/34520#issuecomment-3918951595) | 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: * [#36885](https://github.com/bitcoin/bitcoin/pull/36885) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36885.svg"></sub> (wallet, rpc: Add analyzedescriptor for multisig setups by pablomartin4btc) * [#36831](https://github.com/bitcoin/bitcoin/pull/36831) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36831.svg"></sub> (test: split `test_IsStandard` into independent test cases by yuvicc) * [#36187](https://github.com/bitcoin/bitcoin/pull/36187) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36187.svg"></sub> (http: Restore requirement of IPv4 bind success by hodlinator) * [#36167](https://github.com/bitcoin/bitcoin/pull/36167) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36167.svg"></sub> (build: Enable `-Wunused` by fanquake) * [#36122](https://github.com/bitcoin/bitcoin/pull/36122) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36122.svg"></sub> (BIP460: CISA for Taproot key path spends by fjahr) * [#35763](https://github.com/bitcoin/bitcoin/pull/35763) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35763.svg"></sub> (util: write JSON atomically in WriteJson by kevkevinpal) * [#35733](https://github.com/bitcoin/bitcoin/pull/35733) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35733.svg"></sub> (sign: Remove FillableSigningProvider by achow101) * [#35444](https://github.com/bitcoin/bitcoin/pull/35444) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35444.svg"></sub> (wallet: make descriptor SPKM mutex non-recursive by w0xlt) * [#35377](https://github.com/bitcoin/bitcoin/pull/35377) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35377.svg"></sub> (wallet: Allow importing of descriptors without private keys when the wallet has the private keys by achow101) 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-->
HowHsu commented 2026-02-06 11:15:08 +00:00 (Migrated from github.com)

ACK fac5685

ACK fac5685
yuvicc commented 2026-02-18 06:17:51 +00:00 (Migrated from github.com)

ACK fac5685e867b4a9ec334ed1ee31aabacd1c3124e

ACK fac5685e867b4a9ec334ed1ee31aabacd1c3124e
sedited commented 2026-02-25 11:16:02 +00:00 (Migrated from github.com)

Concept ACK

This looks like a good thing to add, but I wonder if handling these cases incrementally is the correct approach. Outside of these "getter" functions there are so many cases where adding nodiscard make sense too. There is modernize-use-nodiscard, but that is too noisy. An alternative might be to roll our own clang tidy plugin that checks for bool return + mutable ref or pointer argument.

Do you also want to add these couple of cases (also added one that takes a mutable pointer):

diff --git a/src/dbwrapper.h b/src/dbwrapper.h
index b2ce67c7c2..c2c2a94abd 100644
--- a/src/dbwrapper.h
+++ b/src/dbwrapper.h
@@ -154 +154 @@ public:
-    template<typename K> bool GetKey(K& key) {
+    template<typename K> [[nodiscard]] bool GetKey(K& key) {
@@ -164 +164 @@ public:
-    template<typename V> bool GetValue(V& value) {
+    template<typename V> [[nodiscard]] bool GetValue(V& value) {
diff --git a/src/qt/addresstablemodel.h b/src/qt/addresstablemodel.h
index 127378ed2f..80a5dc2ac3 100644
--- a/src/qt/addresstablemodel.h
+++ b/src/qt/addresstablemodel.h
@@ -99 +99 @@ private:
-    bool getAddressData(const QString &address, std::string* name, wallet::AddressPurpose* purpose) const;
+    [[nodiscard]] bool getAddressData(const QString &address, std::string* name, wallet::AddressPurpose* purpose) const;
diff --git a/src/txdb.cpp b/src/txdb.cpp
index 27fb76fc4a..a0f55b1cd1 100644
--- a/src/txdb.cpp
+++ b/src/txdb.cpp
@@ -199 +199 @@ std::unique_ptr<CCoinsViewCursor> CCoinsViewDB::Cursor() const
-        i->pcursor->GetKey(entry);
+        (void)i->pcursor->GetKey(entry);
Concept ACK This looks like a good thing to add, but I wonder if handling these cases incrementally is the correct approach. Outside of these "getter" functions there are so many cases where adding [[nodiscard]] make sense too. There is `modernize-use-nodiscard`, but that is too noisy. An alternative might be to roll our own clang tidy plugin that checks for bool return + mutable ref or pointer argument. Do you also want to add these couple of cases (also added one that takes a mutable pointer): ```diff diff --git a/src/dbwrapper.h b/src/dbwrapper.h index b2ce67c7c2..c2c2a94abd 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -154 +154 @@ public: - template<typename K> bool GetKey(K& key) { + template<typename K> [[nodiscard]] bool GetKey(K& key) { @@ -164 +164 @@ public: - template<typename V> bool GetValue(V& value) { + template<typename V> [[nodiscard]] bool GetValue(V& value) { diff --git a/src/qt/addresstablemodel.h b/src/qt/addresstablemodel.h index 127378ed2f..80a5dc2ac3 100644 --- a/src/qt/addresstablemodel.h +++ b/src/qt/addresstablemodel.h @@ -99 +99 @@ private: - bool getAddressData(const QString &address, std::string* name, wallet::AddressPurpose* purpose) const; + [[nodiscard]] bool getAddressData(const QString &address, std::string* name, wallet::AddressPurpose* purpose) const; diff --git a/src/txdb.cpp b/src/txdb.cpp index 27fb76fc4a..a0f55b1cd1 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -199 +199 @@ std::unique_ptr<CCoinsViewCursor> CCoinsViewDB::Cursor() const - i->pcursor->GetKey(entry); + (void)i->pcursor->GetKey(entry); ```
maflcko commented 2026-02-26 13:36:42 +00:00 (Migrated from github.com)

This looks like a good thing to add, but I wonder if handling these cases incrementally is the correct approach.

I wondered that, too. The patch here was written in 2018, but fell off the table. While I rebased it, some places where transformed to std::optional (which should be used in a few more places instead of nodiscard).

Outside of these "getter" functions there are so many cases where adding nodiscard make sense too.

Are there? I think the attribute should only be used where it really makes sense.

modernize-use-nodiscard

I think this will do the exact opposite of what we want: It ignores functions that have a mutable ref param. It only adds it to functions that don't really need it in the first place.

Happy to take a look at writing a clang-tidy plugin, maybe as a follow-up?

dbwrapper.h

I've also seen this one, but left it for a follow-up, because it is not trivial to see if and why (void) would be the correct fix here. I wanted to keep this pull focussed on mostly mechanical changes for now.

getAddressData

Thx, done

> This looks like a good thing to add, but I wonder if handling these cases incrementally is the correct approach. I wondered that, too. The patch here was written in 2018, but fell off the table. While I rebased it, some places where transformed to std::optional (which should be used in a few more places instead of nodiscard). > Outside of these "getter" functions there are so many cases where adding [[nodiscard]] make sense too. Are there? I think the attribute should only be used where it really makes sense. > modernize-use-nodiscard I think this will do the exact opposite of what we want: It *ignores* functions that have a mutable ref param. It only adds it to functions that don't really need it in the first place. Happy to take a look at writing a clang-tidy plugin, maybe as a follow-up? > dbwrapper.h I've also seen this one, but left it for a follow-up, because it is not trivial to see if and why (void) would be the correct fix here. I wanted to keep this pull focussed on mostly mechanical changes for now. > getAddressData Thx, done
ajtowns (Migrated from github.com) reviewed 2026-03-05 08:49:34 +00:00
ajtowns (Migrated from github.com) left a comment

Concept ACK

Concept ACK
ajtowns (Migrated from github.com) commented 2026-03-05 08:37:25 +00:00

Shouldn't proxy.m_tor_stream_isolation also be conditional on is_valid ?

Shouldn't `proxy.m_tor_stream_isolation` also be conditional on `is_valid` ?
ajtowns (Migrated from github.com) commented 2026-03-05 08:48:55 +00:00

Perhaps:

if (cache == nullptr || !cache->GetCachedLastHardenedExtPubKey(m_expr_index,xpub) || !xpub.pubkey.IsValid()) {
    // cache miss, or not cache, or need privkey
    ...
}
assert(xpub.pubkey.IsValid());
Perhaps: ```c++ if (cache == nullptr || !cache->GetCachedLastHardenedExtPubKey(m_expr_index,xpub) || !xpub.pubkey.IsValid()) { // cache miss, or not cache, or need privkey ... } assert(xpub.pubkey.IsValid()); ```
ajtowns (Migrated from github.com) commented 2026-03-05 08:44:48 +00:00

I'm uncomfortable with both declaring [[nodiscard] bool GetOp(...) and then discarding the return value in consensus code (or non-test code in general).

The earlier scriptSig.IsPushOnly() should guarantee that GetOp will never return false, so perhaps Assume(scriptSig.GetOp(pc, opcode, data)) would be better here?

I'm uncomfortable with both declaring `[[nodiscard] bool GetOp(...)` and then discarding the return value in consensus code (or non-test code in general). The earlier `scriptSig.IsPushOnly()` should guarantee that `GetOp` will never return false, so perhaps `Assume(scriptSig.GetOp(pc, opcode, data))` would be better here?
maflcko (Migrated from github.com) reviewed 2026-03-05 12:36:20 +00:00
maflcko (Migrated from github.com) commented 2026-03-05 12:36:20 +00:00

Yeah, but I guess std::optional could make more sense. Done in https://github.com/bitcoin/bitcoin/pull/34741 and moved this into draft for now.

edit: now merged

Yeah, but I guess `std::optional` could make more sense. Done in https://github.com/bitcoin/bitcoin/pull/34741 and moved this into draft for now. edit: now merged
maflcko (Migrated from github.com) reviewed 2026-03-13 14:43:32 +00:00
maflcko (Migrated from github.com) commented 2026-03-13 14:43:32 +00:00

thx, done

thx, done
maflcko (Migrated from github.com) reviewed 2026-03-13 14:43:37 +00:00
maflcko (Migrated from github.com) commented 2026-03-13 14:43:37 +00:00

Haven't looked here. This is still in draft and I may take a look on the next rebase.

edit: thx, done

Haven't looked here. This is still in draft and I may take a look on the next rebase. edit: thx, done
maflcko commented 2026-04-03 14:08:26 +00:00 (Migrated from github.com)

Rebased, and taken out of draft, now that all feedback is addressed.

Rebased, and taken out of draft, now that all feedback is addressed.
ryanofsky (Migrated from github.com) approved these changes 2026-04-07 14:53:34 +00:00
ryanofsky (Migrated from github.com) left a comment

Code review fa97a912e836943b33d21e83807fb8784e7abceb. FIrst commit does not seem right to me but otherwise these are nice changes that could prevent bugs.

Code review fa97a912e836943b33d21e83807fb8784e7abceb. FIrst commit does not seem right to me but otherwise these are nice changes that could prevent bugs.
ryanofsky (Migrated from github.com) commented 2026-04-07 14:48:31 +00:00

In commit "refactor: Add nodiscard to GetCachedLastHardenedExtPubKey" (4444e4abc181ccaadeb8788eb4ab90f0a63ab485)

Looks like commit message should be updated. It says "mark the return value as unused in one place" which is not what this doing (it is using the return value as an optimization)

In commit "refactor: Add [[nodiscard]] to GetCachedLastHardenedExtPubKey" (4444e4abc181ccaadeb8788eb4ab90f0a63ab485) Looks like commit message should be updated. It says "mark the return value as unused in one place" which is not what this doing (it is using the return value as an optimization)
ryanofsky (Migrated from github.com) commented 2026-04-07 14:40:03 +00:00

In commit "refactor: Add nodiscard to GetOp/GetScriptOp" (fa9e0570a6e1da609d052e6d2bcdc9744b719c42)

I don't think it makes sense to use Assume here. Logically CountWitnessSigOps could either be intended to tolerate malformed scripts, in which case it should ignore the GetOp return value, or intended not to tolerate them, in which case it should abort or raise an exception. I don't see how it could realistically be intended to tolerate malformed scripts in release builds but not debug builds.

In commit "refactor: Add [[nodiscard]] to GetOp/GetScriptOp" (fa9e0570a6e1da609d052e6d2bcdc9744b719c42) I don't think it makes sense to use Assume here. Logically `CountWitnessSigOps` could either be intended to tolerate malformed scripts, in which case it should ignore the GetOp return value, or intended not to tolerate them, in which case it should abort or raise an exception. I don't see how it could realistically be intended to tolerate malformed scripts in release builds but not debug builds.
maflcko (Migrated from github.com) reviewed 2026-04-07 19:13:48 +00:00
maflcko (Migrated from github.com) commented 2026-04-07 19:13:48 +00:00

This used to be (void), but then I changed it to Assume after a review comment (https://github.com/bitcoin/bitcoin/pull/34520#discussion_r2888547507). Now I changed to Assert, but I guess tidy uses a release build an now contrib/devtools/check-deps.sh fails with:


Error: interpreter.cpp.o depends on check.cpp.o symbol 'assertion_fail(std::source_location const&, std::basic_string_view<char, std::char_traits<char> >)', can suppress with:
    SUPPRESS["interpreter.cpp.o check.cpp.o _Z14assertion_failRKSt15source_locationSt17basic_string_viewIcSt11char_traitsIcEE"]=1
Error: Unexpected dependencies were detected. Check previous output.

Not sure how to fix this. I guess I'd have to move util/check.h to crypto? According to:

doc/design/libraries.md:98:- *libbitcoin_consensus* should only depend on *libbitcoin_crypto*, and all other libraries besides *libbitcoin_crypto* should be allowed to depend on it.
This used to be `(void)`, but then I changed it to `Assume` after a review comment (https://github.com/bitcoin/bitcoin/pull/34520#discussion_r2888547507). Now I changed to `Assert`, but I guess tidy uses a release build an now `contrib/devtools/check-deps.sh` fails with: ``` Error: interpreter.cpp.o depends on check.cpp.o symbol 'assertion_fail(std::source_location const&, std::basic_string_view<char, std::char_traits<char> >)', can suppress with: SUPPRESS["interpreter.cpp.o check.cpp.o _Z14assertion_failRKSt15source_locationSt17basic_string_viewIcSt11char_traitsIcEE"]=1 Error: Unexpected dependencies were detected. Check previous output. ``` Not sure how to fix this. I guess I'd have to move `util/check.h` to `crypto`? According to: ``` doc/design/libraries.md:98:- *libbitcoin_consensus* should only depend on *libbitcoin_crypto*, and all other libraries besides *libbitcoin_crypto* should be allowed to depend on it. ```
ryanofsky (Migrated from github.com) reviewed 2026-04-07 19:58:16 +00:00
ryanofsky (Migrated from github.com) commented 2026-04-07 19:58:16 +00:00

re: https://github.com/bitcoin/bitcoin/pull/34520#discussion_r3047316414

Not sure how to fix this.

Would suggest a plain assert:

bool got_op = scriptSig.GetOp(pc, opcode, data);;
assert(got_op); // Guaranteed by IsPushOnly()

Or maybe it is fine for consensus to depend on util though now it is no longer distributed as a separate library. Moving check to crypto could also be ok. Plain assert seems best to me though.

re: https://github.com/bitcoin/bitcoin/pull/34520#discussion_r3047316414 > Not sure how to fix this. Would suggest a plain assert: ```c++ bool got_op = scriptSig.GetOp(pc, opcode, data);; assert(got_op); // Guaranteed by IsPushOnly() ``` Or maybe it is fine for consensus to depend on util though now it is no longer distributed as a separate library. Moving check to crypto could also be ok. Plain assert seems best to me though.
maflcko (Migrated from github.com) reviewed 2026-04-07 21:01:49 +00:00
maflcko (Migrated from github.com) commented 2026-04-07 21:01:49 +00:00

Ok, I may use assert for now, but it seems better to answer the library design question. Otherwise, it will come up again in the future. There is also kernel_util from https://github.com/bitcoin/bitcoin/pull/28690, so possibly there is no need consensus to depend on all of util, but it may be fine to depend on kernel_util.

Ok, I may use `assert` for now, but it seems better to answer the library design question. Otherwise, it will come up again in the future. There is also `kernel_util` from https://github.com/bitcoin/bitcoin/pull/28690, so possibly there is no need consensus to depend on all of `util`, but it may be fine to depend on `kernel_util`.
ryanofsky (Migrated from github.com) reviewed 2026-04-08 12:57:33 +00:00
ryanofsky (Migrated from github.com) commented 2026-04-08 12:57:33 +00:00

Ok, I may use assert for now, but it seems better to answer the library design question.

Yes, it looks like the underlying problem is that util/check.h depends on some globals like g_detail_test_only_CheckFailuresAreExceptionsNotAborts and g_enable_dynamic_fuzz_determinism which need to live in some library. Otherwise check.h could be a header-only dependency.

I don't think it particularly matters where those globals live. The easiest thing to do which preserves existing dependencies and would not be a bad solution IMO would be to move these globals to the crypto library like hex_base was moved there in #29015, since everything can depend on crypto. Or maybe introduce a small core or globals library to hold these and maybe other things like G_TRANSLATION_FUN. The kernel_util idea from #28690 also seems ok (with some different naming since probably wallet and consensus libraries should not depend on a iibrary with "kernel" in the name)

Another option would to just let the consensus library depend on util. I don't think there would be harm from that if consensus is not distributed separately.

But I don't think it would be good to make library dependency changes in this PR if assert fits well here, which it seems like it does.

> Ok, I may use `assert` for now, but it seems better to answer the library design question. Yes, it looks like the underlying problem is that `util/check.h` depends on some globals like `g_detail_test_only_CheckFailuresAreExceptionsNotAborts` and `g_enable_dynamic_fuzz_determinism` which need to live in some library. Otherwise `check.h` could be a header-only dependency. I don't think it particularly matters where those globals live. The easiest thing to do which preserves existing dependencies and would not be a bad solution IMO would be to move these globals to the `crypto` library like `hex_base` was moved there in #29015, since everything can depend on `crypto`. Or maybe introduce a small core or globals library to hold these and maybe other things like `G_TRANSLATION_FUN`. The kernel_util idea from #28690 also seems ok (with some different naming since probably wallet and consensus libraries should not depend on a iibrary with "kernel" in the name) Another option would to just let the `consensus` library depend on `util`. I don't think there would be harm from that if consensus is not distributed separately. But I don't think it would be good to make library dependency changes in this PR if `assert` fits well here, which it seems like it does.
First-time contributor

🔴 Major · Avoid linking bitcoin_util from bitcoin_consensus

src/script/interpreter.cpp:2168 now uses Assert, which always calls internal_abort_helper and StrFormatFailedCheck from bitcoin_util. bitcoin_consensus does not link bitcoin_util, so check-deps in the tidy CI job and the bare-metal RISC-V consensus link fail. The standard assert avoids both.

Location: src/script/interpreter.cpp:2168 (head).

🔵 Suggestion · Annotate the cursor interface

src/txdb.cpp:240 adds nodiscard only to CCoinsViewDBCursor's overrides. Every caller goes through the unannotated CCoinsViewCursor base (coins.h:283), so the attributes never warn. For example, rpc/blockchain.cpp:3460 discards GetKey's result without a warning. Annotate the base declarations instead.

Location: src/txdb.cpp:240 (head).

🔵 Suggestion · Include the neighboring node output getters

getNodesStats and getBanned (src/interfaces/node.h:129,132) still lack nodiscard, and their Qt callers discard the result. Impact is low: on failure the output is either cleared or left as the caller's fresh empty map, so the GUI just shows empty tables.

Location: src/interfaces/node.h:128 (head).

Review coverage was incomplete.


Reviewed: 1bd568e2c708 · Full review report · Previous reports

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:6f232c871bca65facadc248ad7ecd634f87b0b5f6936bc30593af890589888f1:0cfbbc826fdd30e42f35c9a5b7d389c0902089c94f2400654bb32123e69823f6 --> <!-- ralph-base:6ed5aad06111177c39f9b9f07a52634476380ae1 --> <!-- ralph-head:1bd568e2c70840f606eab1157b35b1f06dab1e29 --> <!-- ralph-case:ae557aa4eca76fcbe51e42f23410c5cb287756cd6eeebee4fdf8a08437223f21 --> **🔴 Major · Avoid linking `bitcoin_util` from `bitcoin_consensus`** src/script/interpreter.cpp:2168 now uses Assert, which always calls internal_abort_helper and StrFormatFailedCheck from bitcoin_util. bitcoin_consensus does not link bitcoin_util, so check-deps in the tidy CI job and the bare-metal RISC-V consensus link fail. The standard assert avoids both. Location: [`src/script/interpreter.cpp:2168`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/1bd568e2c70840f606eab1157b35b1f06dab1e29/src/script/interpreter.cpp#L2168>) (head). **🔵 Suggestion · Annotate the cursor interface** src/txdb.cpp:240 adds [[nodiscard]] only to CCoinsViewDBCursor's overrides. Every caller goes through the unannotated CCoinsViewCursor base (coins.h:283), so the attributes never warn. For example, rpc/blockchain.cpp:3460 discards GetKey's result without a warning. Annotate the base declarations instead. Location: [`src/txdb.cpp:240`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/1bd568e2c70840f606eab1157b35b1f06dab1e29/src/txdb.cpp#L240>) (head). **🔵 Suggestion · Include the neighboring node output getters** getNodesStats and getBanned (src/interfaces/node.h:129,132) still lack [[nodiscard]], and their Qt callers discard the result. Impact is low: on failure the output is either cleared or left as the caller's fresh empty map, so the GUI just shows empty tables. Location: [`src/interfaces/node.h:128`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/1bd568e2c70840f606eab1157b35b1f06dab1e29/src/interfaces/node.h#L128>) (head). Review coverage was incomplete. <!-- Review tier: standard --> --- Reviewed: [`1bd568e2c708`](<https://git.fish.foo/bitcoin/bitcoin/commit/1bd568e2c70840f606eab1157b35b1f06dab1e29>) · [Full review report](<https://review.fish.foo/traces/34520-1bd568e2c70840f606eab1157b35b1f06dab1e29-1735-3.html>) · [Previous reports](<https://review.fish.foo/traces/34520/>)
DrahtBot commented 2026-10-06 00:37:11 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!34520
No description provided.