Skip to content

Conversation

darosior
Copy link
Contributor

@darosior darosior commented May 20, 2021

As per #39 and discussions on IRC this removes the exclusion of k = 1 and k = subs.size() for thresh.

This is the opposite of rust-bitcoin/rust-miniscript#242 (adapting the Rust implementation to the C++ one) after sanket1729 's feedback.

Fixes #39

Copy link
Contributor

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 7b93186 .

@darosior darosior force-pushed the thresh_lax_bounds branch from 7b93186 to 71a52e0 Compare June 4, 2021 14:59
@darosior darosior force-pushed the thresh_lax_bounds branch from 71a52e0 to b3329b9 Compare June 4, 2021 20:54
compiler.cpp Outdated
strats.push_back(MakeStrat(store, Strat::Type::THRESH, subs, node.k, (double)node.k / subs.size()));
}
if (node.k == 1 || node.k == node.sub.size()) {
} else if ((node.k == 1 && node.sub.size() < 10) || node.k == node.sub.size()) {
Copy link
Owner

@sipa sipa Jun 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this limit 10 coming from?

EDIT: I see, it is avoiding inefficiencies. Does this not result in worse results in some cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, but at least it results at some point :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I'd prefer to fix that in other ways (e.g. have a simpler or/and strategy that doesn't consider all probabilities).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm ok so i think it was a bit clumsy for me to try to solve this in this PR since it gets outside the scope and was a hack for the specific thresh case but a decent solution would also encompass the existing nested-or()s case.

How about leaving this as a follow-up? This PR does not make the existing situation worse (but still opens up a new situation where this can be encountered..).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sure - I just noticed too late this PR was changing more than what I had expected it to do.

compiler.cpp Outdated
while (subs.size() > 1) {
auto rep = MakeStrat(store, node.k == 1 ? Strat::Type::OR : Strat::Type::AND, Vector(*(subs.rbegin() + 1), subs.back()), 1.0 / subs.size());
subs.pop_back();
subs.pop_back();
subs.push_back(MakeStrat(store, Strat::Type::CACHE, Vector(rep)));
}
strats.push_back(subs[0]);
} else {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a reason for this sequence of if/then/elses. Just use all applicable strategies. The compiler will use the best one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. The first else if was an oversight, but the else part i'm not sure. I figured that it would put unnecessary burden on the compiler to add the thresh strategy if:

  • The policy is just a (smallish) multisig
  • The policy can be represented as nested or()s or and()s
    as these would always be more efficient than the raw addition of all sub-policies. But maybe my intuition is wrong for the latter?

Anyways, amended :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be right, but the code is more obviously going to find the optimal one if it just tries everything.

darosior added 3 commits June 14, 2021 13:04
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
@darosior darosior force-pushed the thresh_lax_bounds branch from b3329b9 to 38b046f Compare June 14, 2021 11:43
@sipa
Copy link
Owner

sipa commented Jun 15, 2021

utACK 38b046f

@sipa sipa merged commit 1e6edd8 into sipa:master Jun 15, 2021
@darosior darosior deleted the thresh_lax_bounds branch June 15, 2021 16:52
@darosior darosior mentioned this pull request Jul 25, 2021
sipa added a commit that referenced this pull request Sep 28, 2021
3c9a837 test: inclusive bounds for thresh()'s threshold (Antoine Poinsot)

Pull request description:

  #55 didn't come with any test. This fixes it.

  Based on #58 to benefit from the update and avoid needless conflicts.

ACKs for top commit:
  sipa:
    ACK 3c9a837

Tree-SHA512: 38d5a271271c665267d50750b563c4312ccda497f42a6a4bf6750542232880a8839ad68cd0348cb3158b236a51c3439ebee1ee278c0c0a66195acc7606c35a5d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow k = 1 and k = n for thresh.
3 participants