Conversation
58b6a91 to
46d79a0
Compare
|
Still got a bug, will try again later. |
46d79a0 to
cd170ac
Compare
| if let Ok(thresh) = Threshold::new(k, policies) { | ||
| ret.push((prob / policy_thresh.n() as f64, Arc::new(Policy::Thresh(thresh)))); | ||
| } |
There was a problem hiding this comment.
This looks like a change in logic but if you check the single callsite for generate_combination you can see that this will not result in a logic change.
There was a problem hiding this comment.
The original code effectively used new_unchecked. If this really always results in a valid threshold (not immediately obvious from the code but I assume we would've noticed if this were wrong :)) I think we should use an expect() rather than an if let Ok(..) without any other branch.
There was a problem hiding this comment.
Can do, I might re-visit the call site too and see if there is any way to make it obvious that we can't hit the expect.
cd170ac to
b86fbcc
Compare
|
In b86fbcc: ACK reducing Then as far as the new You have a comment somewhere about casting the u32 I'm also unsure if we want to use this same type for multisigs, where we have a 20-key limit in pre-Taproot outputs. This would be easier if Rust had type-level integers..which I think it does now but not in our MSRV? |
|
Thanks for the review man.
Fair, I can agree with that reasoning.
I'm not quite following the constructor idea since presumably we'd have to do checks on the
For (2), AFAICT a translation always uses the same n and k so is always valid. Perhaps there is a better way to express this in the function name. For (1) perhaps it would be better to gate a function on
Ah of course, I went looking for the same
Perhaps both of these things suggest that the |
My thinking was that the current code only requires that both values are nonnegative, which is guaranteed by the
Then we should implement a |
Nice! |
274b736 to
c5f7903
Compare
|
Not worth looking at again yet, I've made a mess. Will come back. |
c5f7903 to
d81faa3
Compare
The `Policy` variant names should mirror the serialization of themselves, all do except for `Policy::Threshold`. Shorten the variant to `Thresh`.
We have various enums in the codebase that include a `Thresh` variant, we have to explicitly check that invariants are maintained all over the place because these enums are public (eg, `policy::Concrete`). Add a `Threshold<T>` type that abstracts over a threshold and maintains the following invariants: - v.len() > 0 - k > 0 - k <= v.len()
d81faa3 to
4d2d430
Compare
Use the `Threshold` type in `policy::concrete::Policy::Thresh` to help maintain invariants on n and k.
4d2d430 to
6468604
Compare
|
This is cleaned up, leaving as draft until I manage to use |
|
Replaced by #660 |
|
Heh, oops, I actually forgot about this PR. But FWIW with my approach (which heavily uses I also avoided thinking much about casting the threshold value around. |
|
Yeah the map stuff is great. |
Draft because I think we should use the new
Thresholdtype insematic::Policyas well before we consider this for merge, last weeks effort at that got me into a mess.Creates the new type
crate::threshold::Thresholdthat is an (k, n)-threshold and enforces the invariantsUse it in
policy::concrete::Policy.