From fa2610538f9fd964f57afe000af0264b40c7b2e8 Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Sat, 13 Feb 2021 10:58:26 -0500 Subject: [PATCH] [policy] Remove the `TooManyItemsSelected` error The `TooManyItemsSelected` error has been removed, since it's not technically an error but potentailly more of an "over-constraint" over a tx: for instance, given a `thresh(3,pk(a),pk(b),older(10),older(20))` descriptor one could create a spending tx with the `[0,1,2]` items that would only be spendable after `10` blocks, or a tx with the `[0,2,3]` items that would be spendable after `20`. In this case specifying more items than the threshold would create a tx with the maximum constraint possible, in this case the `20` blocks. This is not necessarily an error, so we should allow it without failing. --- CHANGELOG.md | 1 + src/descriptor/policy.rs | 14 +++----------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b958d62..b683d1cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Policy #### Changed - Removed unneeded `Result<(), PolicyError>` return type for `Satisfaction::finalize()` +- Removed the `TooManyItemsSelected` policy error (see commit message for more details) ## [v0.3.0] - [v0.2.0] diff --git a/src/descriptor/policy.rs b/src/descriptor/policy.rs index 54ba808b..40d8efb3 100644 --- a/src/descriptor/policy.rs +++ b/src/descriptor/policy.rs @@ -47,7 +47,7 @@ //! # Ok::<(), bdk::Error>(()) //! ``` -use std::cmp::{max, Ordering}; +use std::cmp::max; use std::collections::{BTreeMap, HashSet, VecDeque}; use std::fmt; @@ -510,8 +510,6 @@ impl Condition { pub enum PolicyError { /// Not enough items are selected to satisfy a [`SatisfiableItem::Thresh`] NotEnoughItemsSelected(String), - /// Too many items are selected to satisfy a [`SatisfiableItem::Thresh`] - TooManyItemsSelected(String), /// Index out of range for an item to satisfy a [`SatisfiableItem::Thresh`] IndexOutOfRange(usize), /// Can not add to an item that is [`Satisfaction::None`] or [`Satisfaction::Complete`] @@ -668,14 +666,8 @@ impl Policy { // if we have something, make sure we have enough items. note that the user can set // an empty value for this step in case of n-of-n, because `selected` is set to all // the elements above - match selected.len().cmp(threshold) { - Ordering::Less => { - return Err(PolicyError::NotEnoughItemsSelected(self.id.clone())) - } - Ordering::Greater => { - return Err(PolicyError::TooManyItemsSelected(self.id.clone())) - } - Ordering::Equal => (), + if selected.len() < *threshold { + return Err(PolicyError::NotEnoughItemsSelected(self.id.clone())); } // check the selected items, see if there are conflicting requirements