From: Steve Myers Date: Sat, 15 Apr 2023 03:46:02 +0000 (-0500) Subject: Merge bitcoindevkit/bdk#932: Fix policy condition calculation X-Git-Tag: v1.0.0-alpha.1~20 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/enum.EncodeError.html?a=commitdiff_plain;h=5e026cfd03143f497d8607c2b4ff0e3ec1757453;p=bdk Merge bitcoindevkit/bdk#932: Fix policy condition calculation ebd6103e6597e0a66470541d2fcd25709ea77866 Fix policy condition calculation (Alekos Filini) Pull request description: ### Description When constructing the `Condition` struct we recursively call `get_condition` on all the items in a threshold and short-circuit if there's an error somewhere (for example, because the policy-path hasn't been provided for a specific threshold). This can cause issues when the user doesn't care about a subtree, because we still try to call `get_condition` on all the items and fail if something is missing, even if the specific subtree isn't selected and won't be used later on. This commit changes the logic so that we first filter only the `selected` items, and then unwrap the error using the question mark. If errors happened somewhere else they will be ignored, as they should. ### Notes to the reviewers I think it makes sense to backport this to `0.27`: even though it's not a critical issue (and there's a workaround[^1] for the bug) it may be a while before the new `1.0` is released. I wouldn't do a release just for this, but I would just leave it there and maybe in a few weeks if there are other fixes to be backported to pre-1.0 they could all be released. ### Changelog notice - Fixed a bug in the policy condition calculation ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### New Features: * [ ] I've added tests for the new feature * [ ] I've added docs for the new feature #### Bugfixes: * [ ] This pull request breaks the existing API * [x] I've added tests to reproduce the issue which are now passing * [ ] I'm linking the issue being fixed by this PR [^1]: The workaround is to simply set the items in the policy tree even if they won't be used. For example, if the item causing troubles is a `thresh(1, ...)` just set `[0]` in the policy path for that id. ACKs for top commit: notmandatory: ACK ebd6103e6597e0a66470541d2fcd25709ea77866 Tree-SHA512: 1e0c6140e47ead3a518656cab660932b40f9e67425ce144f072267c30fd5cae5923ba943d9682af050c8f314756c522260abb68b104b9eeaae597319612984db --- 5e026cfd03143f497d8607c2b4ff0e3ec1757453