@@ -1670,25 +1670,25 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
16701670 ) ;
16711671 }
16721672
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`]
16751675 /// confirmations.
16761676 ///
16771677 /// Descriptors returned by this method are primarily exposed via [`Event::SpendableOutputs`]
16781678 /// once they are no longer under reorg risk. This method can serve as a way to retrieve these
16791679 /// descriptors at a later time, either for historical purposes, or to replay any
16801680 /// missed/unhandled descriptors.
16811681 ///
1682- /// `tx` is a transaction we'll scan the outputs of. If an output which can be spent by us is
1683- /// found, a descriptor is returned. `confirmation_height` must be the height of the block in
1684- /// which `tx` was included in.
1685- pub fn get_spendable_output ( & self , tx : & Transaction , confirmation_height : u32 ) -> Option < SpendableOutputDescriptor > {
1682+ /// `tx` is a transaction we'll scan the outputs of. If any outputs which can be spent by us are
1683+ /// found, their descriptors are returned. `confirmation_height` must be the height of the block
1684+ /// in which `tx` was included in.
1685+ pub fn get_spendable_outputs ( & self , tx : & Transaction , confirmation_height : u32 ) -> Vec < SpendableOutputDescriptor > {
16861686 let inner = self . inner . lock ( ) . unwrap ( ) ;
16871687 let current_height = inner. best_block . height ;
16881688 if current_height. saturating_sub ( ANTI_REORG_DELAY ) + 1 >= confirmation_height {
1689- inner. get_spendable_output ( tx)
1689+ inner. get_spendable_outputs ( tx)
16901690 } else {
1691- None
1691+ Vec :: new ( )
16921692 }
16931693 }
16941694}
@@ -3463,7 +3463,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34633463 }
34643464 self . is_resolving_htlc_output ( & tx, height, & block_hash, & logger) ;
34653465
3466- self . check_tx_and_push_spendable_output ( & tx, height, & block_hash, & logger) ;
3466+ self . check_tx_and_push_spendable_outputs ( & tx, height, & block_hash, & logger) ;
34673467 }
34683468 }
34693469
@@ -4009,31 +4009,18 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
40094009 }
40104010 }
40114011
4012- fn get_spendable_output ( & self , tx : & Transaction ) -> Option < SpendableOutputDescriptor > {
4013- for ( i, outp) in tx. output . iter ( ) . enumerate ( ) { // There is max one spendable output for any channel tx, including ones generated by us
4014- if i > :: core:: u16:: MAX as usize {
4015- // While it is possible that an output exists on chain which is greater than the
4016- // 2^16th output in a given transaction, this is only possible if the output is not
4017- // in a lightning transaction and was instead placed there by some third party who
4018- // wishes to give us money for no reason.
4019- // Namely, any lightning transactions which we pre-sign will never have anywhere
4020- // near 2^16 outputs both because such transactions must have ~2^16 outputs who's
4021- // scripts are not longer than one byte in length and because they are inherently
4022- // non-standard due to their size.
4023- // Thus, it is completely safe to ignore such outputs, and while it may result in
4024- // us ignoring non-lightning fund to us, that is only possible if someone fills
4025- // nearly a full block with garbage just to hit this case.
4026- continue ;
4027- }
4012+ fn get_spendable_outputs ( & self , tx : & Transaction ) -> Vec < SpendableOutputDescriptor > {
4013+ let mut spendable_outputs = Vec :: new ( ) ;
4014+ for ( i, outp) in tx. output . iter ( ) . enumerate ( ) {
40284015 if outp. script_pubkey == self . destination_script {
4029- return Some ( SpendableOutputDescriptor :: StaticOutput {
4016+ spendable_outputs . push ( SpendableOutputDescriptor :: StaticOutput {
40304017 outpoint : OutPoint { txid : tx. txid ( ) , index : i as u16 } ,
40314018 output : outp. clone ( ) ,
40324019 } ) ;
40334020 }
40344021 if let Some ( ref broadcasted_holder_revokable_script) = self . broadcasted_holder_revokable_script {
40354022 if broadcasted_holder_revokable_script. 0 == outp. script_pubkey {
4036- return Some ( SpendableOutputDescriptor :: DelayedPaymentOutput ( DelayedPaymentOutputDescriptor {
4023+ spendable_outputs . push ( SpendableOutputDescriptor :: DelayedPaymentOutput ( DelayedPaymentOutputDescriptor {
40374024 outpoint : OutPoint { txid : tx. txid ( ) , index : i as u16 } ,
40384025 per_commitment_point : broadcasted_holder_revokable_script. 1 ,
40394026 to_self_delay : self . on_holder_tx_csv ,
@@ -4045,29 +4032,29 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
40454032 }
40464033 }
40474034 if self . counterparty_payment_script == outp. script_pubkey {
4048- return Some ( SpendableOutputDescriptor :: StaticPaymentOutput ( StaticPaymentOutputDescriptor {
4035+ spendable_outputs . push ( SpendableOutputDescriptor :: StaticPaymentOutput ( StaticPaymentOutputDescriptor {
40494036 outpoint : OutPoint { txid : tx. txid ( ) , index : i as u16 } ,
40504037 output : outp. clone ( ) ,
40514038 channel_keys_id : self . channel_keys_id ,
40524039 channel_value_satoshis : self . channel_value_satoshis ,
40534040 } ) ) ;
40544041 }
40554042 if self . shutdown_script . as_ref ( ) == Some ( & outp. script_pubkey ) {
4056- return Some ( SpendableOutputDescriptor :: StaticOutput {
4043+ spendable_outputs . push ( SpendableOutputDescriptor :: StaticOutput {
40574044 outpoint : OutPoint { txid : tx. txid ( ) , index : i as u16 } ,
40584045 output : outp. clone ( ) ,
40594046 } ) ;
40604047 }
40614048 }
4062- None
4049+ spendable_outputs
40634050 }
40644051
40654052 /// Checks if the confirmed transaction is paying funds back to some address we can assume to
40664053 /// own.
4067- fn check_tx_and_push_spendable_output < L : Deref > (
4054+ fn check_tx_and_push_spendable_outputs < L : Deref > (
40684055 & mut self , tx : & Transaction , height : u32 , block_hash : & BlockHash , logger : & L ,
40694056 ) where L :: Target : Logger {
4070- if let Some ( spendable_output) = self . get_spendable_output ( tx) {
4057+ for spendable_output in self . get_spendable_outputs ( tx) {
40714058 let entry = OnchainEventEntry {
40724059 txid : tx. txid ( ) ,
40734060 transaction : Some ( tx. clone ( ) ) ,
0 commit comments