refactor(miniscript): Remove Node::subs mutability
What changed, and why it matters
This is a small internal cleanup in Bitcoin Core's miniscript code. It removes the 'mutable' keyword from a list of child node pointers and adjusts a related pointer type. There is no user-facing behavior change and no security fix.
No security action needed. Treat as a normal code-quality refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors the miniscript Node class by making the ‘subs’ member non-mutable (removing the mutable qualifier) and changing NodeRef from std::unique_ptr
Changed components
src/script/miniscript.hsrc/script/descriptor.cppInspect captured patch +4 / −4
diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp
index 390e7345..8769a262 100644
--- a/src/script/descriptor.cpp
+++ b/src/script/descriptor.cpp
@@ -2566,7 +2566,7 @@ std::vector<std::unique_ptr<DescriptorImpl>> ParseScript(uint32_t& key_exp_index
}
if (!node->IsSane() || node->IsNotSatisfiable()) {
// Try to find the first insane sub for better error reporting.
- auto insane_node = node.get();
+ const decltype(node)::element_type* insane_node = node.get();
if (const auto sub = node->FindInsaneSub()) insane_node = sub;
error = *insane_node->ToString(parser);
if (!insane_node->IsValid()) {
diff --git a/src/script/miniscript.h b/src/script/miniscript.h
index 1c5f7a8c..92925396 100644
--- a/src/script/miniscript.h
+++ b/src/script/miniscript.h
@@ -191,11 +191,11 @@ inline consteval Type operator""_mst(const char* c, size_t l)
using Opcode = std::pair<opcodetype, std::vector<unsigned char>>;
template<typename Key> class Node;
-template<typename Key> using NodeRef = std::unique_ptr<const Node<Key>>;
+template<typename Key> using NodeRef = std::unique_ptr<Node<Key>>;
//! Construct a miniscript node as a unique_ptr.
template<typename Key, typename... Args>
-NodeRef<Key> MakeNodeRef(Args&&... args) { return std::make_unique<const Node<Key>>(std::forward<Args>(args)...); }
+NodeRef<Key> MakeNodeRef(Args&&... args) { return std::make_unique<Node<Key>>(std::forward<Args>(args)...); }
//! Unordered traversal of a miniscript node tree.
template <typename Key, std::invocable<const Node<Key>&> Fn>
@@ -545,7 +545,7 @@ class Node
//! The data bytes in this expression (only for HASH160/HASH256/SHA256/RIPEMD160).
std::vector<unsigned char> data;
//! Subexpressions (for WRAP_*/AND_*/OR_*/ANDOR/THRESH)
- mutable std::vector<NodeRef<Key>> subs;
+ std::vector<NodeRef<Key>> subs;
//! The Script context for this node. Either P2WSH or Tapscript.
MiniscriptContext m_script_ctx;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.