Skip to content

Remove recursion in is_valid #601

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

Conversation

tcharding
Copy link
Member

Just the last 2 patches.

Draft because I can't work out why we do validity checks when parsing a policy string and then also have the Concrete::is_valid function that enforces, Or and And being exactly length 2. Is there some code path that allows creation of an invalid policy that we will then catch with is_valid?

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
The `concrete::PolicyArc` type is identical to `Policy` except that it
uses `Arc` to wrap the nested `Policy` structs.

In preparation for implementing `TreeLike` and removing recursive
functions that process the `Policy` type remove the `PolicyArc` and add
`Arc` wrappers around the nested `Policy` fields.

Note, this patch does a bunch on cloning in the recursive functions.
This will dissapear when they are re-written to use tree iteration.

There are more optimizaitons available by taking `Arc<Policy<Pk>>` as a
parameter to functions in the `compiler` module, left for later.

The unit tests are bit klunky, much mapping of iterators to add `Arc`, I
think this will come out in the wash as we keep working.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
In preparation for removing recursion in the `policy::concrete` module
implement `TreeLike` for `policy::Concrete` (reference, and `Arc`).

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
We are about to start using the `TreeLike` trait everywhere, hence it
will become an easily recognizable pattern. The current single case has
a code comment that is noisy if duplicated many times.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
In preparation for modifying the `translate_unsatisfiable_pk` function
add a basic unit test.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
We just implemented `TreeLike` for `concrete::Policy`, use it to
implement `translate_unsatisfiable_pk`, removing recursive calls
from the function.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
In preparation for modifying the `keys` function add a basic unit test.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
Remove recursive calls and use `TreeLike`'s post order iterator to get
all the keys from a `concrete::Policy`.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
In preparation for modifying the `num_tap_leaves` function add a basic
unit test.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
Remove recursive calls and use `TreeLike`'s post order iterator to get
the total number of tap leaves for a `concrete::Policy`.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
In preparation for modifying the `for_each_key` add an additional unit
test that checks we correctly handle a failing predicate. While we are
at it rename the existing test.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
Remove recursive calls and use `TreeLike`'s post order iterator to
implement `for_each_key` for the `concrete::Policy`.

No additional unit tests required, this code path is already tested.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
In preparation for modifying the `translate_pk` function add a basic
unit test.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
Remove recursive calls and use `TreeLike`'s post order iterator to
implement `translate_pk` for the `concrete::Policy`.

Note, no additional unit tests added for this code path, this is a
familiar code pattern now.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
Add a unit test that attempts to parse a `concrete::Policy` with both
absolute height and time locks.

Done in preparation for patching `check_timelocks_helper`.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
Remove recursive calls and use `TreeLike`'s post order iterator to
implement `check_timelocks_helper` for the `concrete::Policy`.

Note, no additional unit tests added for this code path, this is a
familiar code pattern now.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
Rename the helper function and local variable at its call site to better
describe the functionality.

Refactor only, no logic changes.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
In preparation for modifying the `is_valid` function add a bunch of
basic unit tests.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tcharding Tobin C. Harding
Note that currently the `in_valid` function does a bunch of checks on
or/and/thresh that are also done in `from_tree_prob`.

Create a private function `check_timelocks_within_rang` that checks that
older/after locks are within valid ranges (above 0 and below 2^31).

Note this patch removes a bunch of logic but as can be seen by the
passing unit tests this code is still logically correct.
@apoelstra
Copy link
Member

Yes, you can directly construct these types because they are public enums.

@tcharding
Copy link
Member Author

Superseded by #606

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.

None yet

2 participants