@@ -1672,6 +1672,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1672
1672
1673
1673
/// Returns the descriptors for relevant outputs (i.e., those that we can spend) within the
1674
1674
/// transaction if they exist and the transaction has at least [`ANTI_REORG_DELAY`]
1675
+ /// confirmations. For [`SpendableOutputDescriptor::DelayedPaymentOutput`] descriptors to be
1676
+ /// returned, the transaction must have at least `max(ANTI_REORG_DELAY, to_self_delay)`
1675
1677
/// confirmations.
1676
1678
///
1677
1679
/// Descriptors returned by this method are primarily exposed via [`Event::SpendableOutputs`]
@@ -1680,8 +1682,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1680
1682
/// missed/unhandled descriptors. For the purpose of gathering historical records, if the
1681
1683
/// channel close has fully resolved (i.e., [`ChannelMonitor::get_claimable_balances`] returns
1682
1684
/// an empty set), you can retrieve all spendable outputs by providing all descendant spending
1683
- /// transactions starting from the channel's funding or closing transaction that have at least
1684
- /// [`ANTI_REORG_DELAY`] confirmations.
1685
+ /// transactions starting from the channel's funding transaction and going down three levels.
1685
1686
///
1686
1687
/// `tx` is a transaction we'll scan the outputs of. Any transaction can be provided. If any
1687
1688
/// outputs which can be spent by us are found, at least one descriptor is returned.
@@ -1690,11 +1691,16 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1690
1691
pub fn get_spendable_outputs ( & self , tx : & Transaction , confirmation_height : u32 ) -> Vec < SpendableOutputDescriptor > {
1691
1692
let inner = self . inner . lock ( ) . unwrap ( ) ;
1692
1693
let current_height = inner. best_block . height ;
1693
- if current_height. saturating_sub ( ANTI_REORG_DELAY ) + 1 >= confirmation_height {
1694
- inner. get_spendable_outputs ( tx)
1695
- } else {
1696
- Vec :: new ( )
1697
- }
1694
+ let mut spendable_outputs = inner. get_spendable_outputs ( tx) ;
1695
+ spendable_outputs. retain ( |descriptor| {
1696
+ let mut conf_threshold = current_height. saturating_sub ( ANTI_REORG_DELAY ) + 1 ;
1697
+ if let SpendableOutputDescriptor :: DelayedPaymentOutput ( descriptor) = descriptor {
1698
+ conf_threshold = cmp:: min ( conf_threshold,
1699
+ current_height. saturating_sub ( descriptor. to_self_delay as u32 ) + 1 ) ;
1700
+ }
1701
+ conf_threshold >= confirmation_height
1702
+ } ) ;
1703
+ spendable_outputs
1698
1704
}
1699
1705
}
1700
1706
0 commit comments