@@ -160,19 +160,34 @@ const DEFAULT_LOOKAHEAD: u32 = 25;
160160/// let new_spk_for_user = txout_index.reveal_next_spk(&MyKeychain::MyAppUser{ user_id: 42 });
161161/// ```
162162///
163- /// # Re-assigning descriptors
163+ /// # Non-recommend keychain to descriptor assignments
164164///
165- /// Under the hood, the [`KeychainTxOutIndex`] uses a [`SpkTxOutIndex`] that keeps track of spks,
166- /// indexed by descriptors. Users then assign or unassign keychains to those descriptors. It's
167- /// important to note that descriptors, once added, never get removed from the [`SpkTxOutIndex`];
168- /// this is useful in case a user unassigns a keychain from a descriptor and after some time
169- /// assigns it again.
165+ /// A keychain (`K`) is used to identify a descriptor. However, the following keychain to descriptor
166+ /// arrangements result in behavior that is harder to reason about and is not recommended.
170167///
171- /// Additionally, although a keychain can only be assigned to one descriptor, different keychains
172- /// can be assigned to the same descriptor. When a method returns spks/outpoints that is associated
173- /// with a descriptor, it may be associated with multiple keychain variants. The keychain variant
174- /// with the higher rank will be returned. Rank is determined by the [`Ord`] implementation of the
175- /// keychain type. Earlier keychain variants have higher rank.
168+ /// ## Multiple keychains identifying the same descriptor
169+ ///
170+ /// Although a single keychain variant can only identify a single descriptor, multiple keychain
171+ /// variants can identify the same descriptor.
172+ ///
173+ /// If multiple keychains identify the same descriptor:
174+ /// 1. Methods that take in a keychain (such as [`reveal_next_spk`]) will work normally when any
175+ /// keychain (that identifies that descriptor) is passed in.
176+ /// 2. Methods that return data which associates with a descriptor (such as [`outpoints`],
177+ /// [`txouts`], [`unused_spks`], etc.) the method will return the highest-ranked keychain variant
178+ /// that identifies the descriptor. Rank is determined by the [`Ord`] implementation of the keychain
179+ /// type.
180+ ///
181+ /// This arrangement is not recommended since some methods will return a single keychain variant
182+ /// even though multiple keychain variants identify the same descriptor.
183+ ///
184+ /// ## Reassigning the descriptor of a single keychain
185+ ///
186+ /// Descriptors added to [`KeychainTxOutIndex`] are never removed. However, a keychain that
187+ /// identifies a descriptor can be reassigned to identify a different descriptor. This may result in
188+ /// a situation where a descriptor has no associated keychain(s), and relevant [`TxOut`]s,
189+ /// [`OutPoint`]s and [`Script`]s (of that descriptor) will not be return by [`KeychainTxOutIndex`].
190+ /// Therefore, reassigning the descriptor of a single keychain is not recommended.
176191///
177192/// [`Ord`]: core::cmp::Ord
178193/// [`SpkTxOutIndex`]: crate::spk_txout_index::SpkTxOutIndex
@@ -186,6 +201,9 @@ const DEFAULT_LOOKAHEAD: u32 = 25;
186201/// [`new`]: KeychainTxOutIndex::new
187202/// [`unbounded_spk_iter`]: KeychainTxOutIndex::unbounded_spk_iter
188203/// [`all_unbounded_spk_iters`]: KeychainTxOutIndex::all_unbounded_spk_iters
204+ /// [`outpoints`]: KeychainTxOutIndex::outpoints
205+ /// [`txouts`]: KeychainTxOutIndex::txouts
206+ /// [`unused_spks`]: KeychainTxOutIndex::unused_spks
189207#[ derive( Clone , Debug ) ]
190208pub struct KeychainTxOutIndex < K > {
191209 inner : SpkTxOutIndex < ( DescriptorId , u32 ) > ,
0 commit comments