-
Notifications
You must be signed in to change notification settings - Fork 141
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
Remove more recursion from concrete::policy
#606
Remove more recursion from concrete::policy
#606
Conversation
Currently the `is_valid` function recursively calls itself, we can use the `pre_order_iter` to loop over the policy nodes instead and remove the recursion. Note that this whole `is_valid` function is pretty inefficient because we have already iterated the nodes twice already (in `check_timelocks` and `check_duplicate_keys`).
As we have done for other `Policy` functions remove the recursive calls in `is_safe_nonmalleable` and use the `post_order_iter` to process each node accumulating the required results in a vector during iteration.
Currently there are a bunch of places where when matching on the `Policy` enum variants are matched in different order to the enum. During recent work this was maintained to make diffs easier to review however since we just modified a lot of this file lets clean it up while we are here. Move the match arms around so that they are ordered in the same order as the variants are defined in the `Policy` enum. Refactor only, no logic changes.
Looks great! Interesting observation that we're iterating thrice in I think this is fine, because improving this would result in much uglier code... but we should keep this in the back of our minds, and if it's a common pattern maybe we should try to refactor it out somehow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 0452040
Yeah this is where my question the other day about why we call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 0452040
Remove the last of the recursion in functions that process policies. Note there is still recursion in the
from_tree_prob
function that creates the policies.