@@ -1670,8 +1670,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1670
1670
) ;
1671
1671
}
1672
1672
1673
- /// Returns the descriptor for a relevant output (i.e., one that we can spend) within the
1674
- /// transaction if one exists and the transaction has at least [`ANTI_REORG_DELAY`]
1673
+ /// Returns the descriptors for relevant outputs (i.e., those that we can spend) within the
1674
+ /// transaction if they exist and the transaction has at least [`ANTI_REORG_DELAY`]
1675
1675
/// confirmations.
1676
1676
///
1677
1677
/// Descriptors returned by this method are primarily exposed via [`Event::SpendableOutputs`]
@@ -1683,17 +1683,17 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1683
1683
/// transactions starting from the channel's funding or closing transaction that have at least
1684
1684
/// [`ANTI_REORG_DELAY`] confirmations.
1685
1685
///
1686
- /// `tx` is a transaction we'll scan the outputs of. Any transaction can be provided. If an
1687
- /// output which can be spent by us is found, a descriptor is returned.
1686
+ /// `tx` is a transaction we'll scan the outputs of. Any transaction can be provided. If any
1687
+ /// outputs which can be spent by us are found, at least one descriptor is returned.
1688
1688
///
1689
1689
/// `confirmation_height` must be the height of the block in which `tx` was included in.
1690
- pub fn get_spendable_output ( & self , tx : & Transaction , confirmation_height : u32 ) -> Option < SpendableOutputDescriptor > {
1690
+ pub fn get_spendable_outputs ( & self , tx : & Transaction , confirmation_height : u32 ) -> Vec < SpendableOutputDescriptor > {
1691
1691
let inner = self . inner . lock ( ) . unwrap ( ) ;
1692
1692
let current_height = inner. best_block . height ;
1693
1693
if current_height. saturating_sub ( ANTI_REORG_DELAY ) + 1 >= confirmation_height {
1694
- inner. get_spendable_output ( tx)
1694
+ inner. get_spendable_outputs ( tx)
1695
1695
} else {
1696
- None
1696
+ Vec :: new ( )
1697
1697
}
1698
1698
}
1699
1699
}
@@ -3468,7 +3468,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3468
3468
}
3469
3469
self . is_resolving_htlc_output ( & tx, height, & block_hash, & logger) ;
3470
3470
3471
- self . check_tx_and_push_spendable_output ( & tx, height, & block_hash, & logger) ;
3471
+ self . check_tx_and_push_spendable_outputs ( & tx, height, & block_hash, & logger) ;
3472
3472
}
3473
3473
}
3474
3474
@@ -4014,31 +4014,18 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
4014
4014
}
4015
4015
}
4016
4016
4017
- fn get_spendable_output ( & self , tx : & Transaction ) -> Option < SpendableOutputDescriptor > {
4018
- for ( i, outp) in tx. output . iter ( ) . enumerate ( ) { // There is max one spendable output for any channel tx, including ones generated by us
4019
- if i > :: core:: u16:: MAX as usize {
4020
- // While it is possible that an output exists on chain which is greater than the
4021
- // 2^16th output in a given transaction, this is only possible if the output is not
4022
- // in a lightning transaction and was instead placed there by some third party who
4023
- // wishes to give us money for no reason.
4024
- // Namely, any lightning transactions which we pre-sign will never have anywhere
4025
- // near 2^16 outputs both because such transactions must have ~2^16 outputs who's
4026
- // scripts are not longer than one byte in length and because they are inherently
4027
- // non-standard due to their size.
4028
- // Thus, it is completely safe to ignore such outputs, and while it may result in
4029
- // us ignoring non-lightning fund to us, that is only possible if someone fills
4030
- // nearly a full block with garbage just to hit this case.
4031
- continue ;
4032
- }
4017
+ fn get_spendable_outputs ( & self , tx : & Transaction ) -> Vec < SpendableOutputDescriptor > {
4018
+ let mut spendable_outputs = Vec :: new ( ) ;
4019
+ for ( i, outp) in tx. output . iter ( ) . enumerate ( ) {
4033
4020
if outp. script_pubkey == self . destination_script {
4034
- return Some ( SpendableOutputDescriptor :: StaticOutput {
4021
+ spendable_outputs . push ( SpendableOutputDescriptor :: StaticOutput {
4035
4022
outpoint : OutPoint { txid : tx. txid ( ) , index : i as u16 } ,
4036
4023
output : outp. clone ( ) ,
4037
4024
} ) ;
4038
4025
}
4039
4026
if let Some ( ref broadcasted_holder_revokable_script) = self . broadcasted_holder_revokable_script {
4040
4027
if broadcasted_holder_revokable_script. 0 == outp. script_pubkey {
4041
- return Some ( SpendableOutputDescriptor :: DelayedPaymentOutput ( DelayedPaymentOutputDescriptor {
4028
+ spendable_outputs . push ( SpendableOutputDescriptor :: DelayedPaymentOutput ( DelayedPaymentOutputDescriptor {
4042
4029
outpoint : OutPoint { txid : tx. txid ( ) , index : i as u16 } ,
4043
4030
per_commitment_point : broadcasted_holder_revokable_script. 1 ,
4044
4031
to_self_delay : self . on_holder_tx_csv ,
@@ -4050,29 +4037,29 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
4050
4037
}
4051
4038
}
4052
4039
if self . counterparty_payment_script == outp. script_pubkey {
4053
- return Some ( SpendableOutputDescriptor :: StaticPaymentOutput ( StaticPaymentOutputDescriptor {
4040
+ spendable_outputs . push ( SpendableOutputDescriptor :: StaticPaymentOutput ( StaticPaymentOutputDescriptor {
4054
4041
outpoint : OutPoint { txid : tx. txid ( ) , index : i as u16 } ,
4055
4042
output : outp. clone ( ) ,
4056
4043
channel_keys_id : self . channel_keys_id ,
4057
4044
channel_value_satoshis : self . channel_value_satoshis ,
4058
4045
} ) ) ;
4059
4046
}
4060
4047
if self . shutdown_script . as_ref ( ) == Some ( & outp. script_pubkey ) {
4061
- return Some ( SpendableOutputDescriptor :: StaticOutput {
4048
+ spendable_outputs . push ( SpendableOutputDescriptor :: StaticOutput {
4062
4049
outpoint : OutPoint { txid : tx. txid ( ) , index : i as u16 } ,
4063
4050
output : outp. clone ( ) ,
4064
4051
} ) ;
4065
4052
}
4066
4053
}
4067
- None
4054
+ spendable_outputs
4068
4055
}
4069
4056
4070
4057
/// Checks if the confirmed transaction is paying funds back to some address we can assume to
4071
4058
/// own.
4072
- fn check_tx_and_push_spendable_output < L : Deref > (
4059
+ fn check_tx_and_push_spendable_outputs < L : Deref > (
4073
4060
& mut self , tx : & Transaction , height : u32 , block_hash : & BlockHash , logger : & L ,
4074
4061
) where L :: Target : Logger {
4075
- if let Some ( spendable_output) = self . get_spendable_output ( tx) {
4062
+ for spendable_output in self . get_spendable_outputs ( tx) {
4076
4063
let entry = OnchainEventEntry {
4077
4064
txid : tx. txid ( ) ,
4078
4065
transaction : Some ( tx. clone ( ) ) ,
0 commit comments