Merge bitcoin/bitcoin#34499: miniscript: Use valid script in test, etc (#31713 follow-ups)

39e3295c71 test(miniscript): Check for depth rather than script size (Hodlinator)
5af5e87646 test(miniscript): Make tested script valid (Hodlinator)
fd7c494c6b doc(miniscript): Explain why we operate on vectors (Hodlinator)
da51b5e4d2 refactor(miniscript): Move keys to avoid copy (Hodlinator)

Pull request description:

  * Add missing move https://github.com/bitcoin/bitcoin/pull/31713#discussion_r2722771821
  * Document reason behind moving entire `vector`s https://github.com/bitcoin/bitcoin/pull/31713#discussion_r2722932391
  * Make miniscript valid and improve test name https://github.com/bitcoin/bitcoin/pull/31713#discussion_r2722121348
  * Check for miniscript node depth rather than script size https://github.com/bitcoin/bitcoin/pull/31713#discussion_r2722062298

ACKs for top commit:
  l0rinc:
    ACK 39e3295c71
  sedited:
    ACK 39e3295c71
  darosior:
    Github light ACK 39e3295c71. Code looks correct to me. I don't understand why i'm co-author of the last commit, since i did not author any code in there. 🤷

Tree-SHA512: 88c240183d7ebe93e3a1d3d65969b435775190f15d2845b58dbd16938553bb6490ab57400544f90a5a3f9a73245dce769ffc4868ae6fb7513f7db46743bfb9e1
This commit is contained in:
merge-script
2026-03-19 18:48:24 +01:00
2 changed files with 25 additions and 7 deletions

View File

@@ -552,6 +552,9 @@ public:
// Destroy the subexpressions iteratively after moving out their
// subexpressions to avoid a stack-overflow due to recursive calls to
// the subs' destructors.
// We move vectors in order to only update array-pointers inside them
// rather than moving individual Node instances which would involve
// moving/copying each Node field.
std::vector<std::vector<Node>> queue;
queue.push_back(std::move(subs));
do {
@@ -607,7 +610,7 @@ private:
// This is kept private as no valid fragment has all of these arguments.
// Only used by Clone()
Node(internal::NoDupCheck, MiniscriptContext script_ctx, enum Fragment nt, std::vector<Node> sub, std::vector<Key> key, std::vector<unsigned char> arg, uint32_t val)
: fragment(nt), k(val), keys(key), data(std::move(arg)), subs(std::move(sub)), m_script_ctx{script_ctx}, ops(CalcOps()), ss(CalcStackSize()), ws(CalcWitnessSize()), typ(CalcType()), scriptlen(CalcScriptLen()) {}
: fragment(nt), k(val), keys(std::move(key)), data(std::move(arg)), subs(std::move(sub)), m_script_ctx{script_ctx}, ops(CalcOps()), ss(CalcStackSize()), ws(CalcWitnessSize()), typ(CalcType()), scriptlen(CalcScriptLen()) {}
//! Compute the length of the script for this miniscript (including children).
size_t CalcScriptLen() const