Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Threshold type in concrete policy and in Terminal::multi/multi_a #674

Merged
merged 3 commits into from
Apr 6, 2024

Conversation

apoelstra
Copy link
Member

Some more large but mostly-mechanical diffs. This is able to eliminate a bunch of error paths, though the actual error variants can't be removed until we also convert Terminal::thresh in the next PR(s). At that point we will start to see the real benefits of this type because fallible functions will become fallible and massive amounts of compiler error-checking can just go away entirely.

Also removes the allocation in SortedMulti::constructor_check that was pointed out in #660.

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

Sans the map_err thing, ACK 1345fb2

let ms = Miniscript::from_ast(term)?;
// This would check all the consensus rules for p2sh/p2wsh and
// even tapscript in future
Ctx::check_local_validity(&ms).map_err(From::from)
Ctx::check_local_validity(&ms).map_err(Error::from)?;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Ctx::check_local_validity(&ms).map_err(Error::from)?;
Ctx::check_local_validity(&ms)?;

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I could drop it here. In future though I want to move away from using from and explicitly write variants (e.g. map_err(Error::ScriptContext) or whatever).

But agreed that .map_err(Error::from)? is the worst of both worlds and I should drop it.

keys.len() - 1,
keys.iter().map(|pubkey| Arc::new(Concrete::Key(*pubkey))),
)
.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice there's a few unwraps() in this PR. Just curious if there's a reason to do this instead of returning an Error type.

Copy link
Member

Choose a reason for hiding this comment

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

These are tests. unwraps are common in test and that is how we test most things.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, I had meant to place this comment on the generate_combination() changes. Heh yeah, I get using unwrap on the tests though.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that was one occurrence which was a safe unwrap because of miniscript invariants around Threshold. We could add a expect with a message with the reasoning, but there was a short comment the commit message explaining that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added an expect. There was also a debug_assert which would have triggered before the unwrap did, but better to be explicit.

sanket1729
sanket1729 previously approved these changes Apr 5, 2024
Copy link
Member

@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.

ACK 1345fb2

keys.len() - 1,
keys.iter().map(|pubkey| Arc::new(Concrete::Key(*pubkey))),
)
.unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

These are tests. unwraps are common in test and that is how we test most things.

This one is a pretty big diff but hopefully the unit tests provide some
assurance. One maybe-subtle change is that the debug_assert in
`generate_combinations` was incorrect -- it checked that k <= n, but the
logic depended on k < n. I fixed the debug_assert and nothing broke.
@apoelstra
Copy link
Member Author

Rebased to fix the map_err thing and also repaced the unwrap in generate_combinations with an expect that makes the reasoning explicit.

Copy link
Member

@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.

ACK 79d3f7e

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 79d3f7e

@apoelstra apoelstra merged commit 9eb4375 into rust-bitcoin:master Apr 6, 2024
16 checks passed
@apoelstra apoelstra deleted the 2024-04--threshold-2 branch April 6, 2024 13:35
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.

4 participants