@@ -1670,25 +1670,25 @@ 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`]
1678
1678
/// once they are no longer under reorg risk. This method can serve as a way to retrieve these
1679
1679
/// descriptors at a later time, either for historical purposes, or to replay any
1680
1680
/// missed/unhandled descriptors.
1681
1681
///
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 > {
1686
1686
let inner = self . inner . lock ( ) . unwrap ( ) ;
1687
1687
let current_height = inner. best_block . height ;
1688
1688
if current_height. saturating_sub ( ANTI_REORG_DELAY ) + 1 >= confirmation_height {
1689
- inner. get_spendable_output ( tx)
1689
+ inner. get_spendable_outputs ( tx)
1690
1690
} else {
1691
- None
1691
+ Vec :: new ( )
1692
1692
}
1693
1693
}
1694
1694
}
@@ -3463,7 +3463,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3463
3463
}
3464
3464
self . is_resolving_htlc_output ( & tx, height, & block_hash, & logger) ;
3465
3465
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) ;
3467
3467
}
3468
3468
}
3469
3469
@@ -4009,31 +4009,18 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
4009
4009
}
4010
4010
}
4011
4011
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 ( ) {
4028
4015
if outp. script_pubkey == self . destination_script {
4029
- return Some ( SpendableOutputDescriptor :: StaticOutput {
4016
+ spendable_outputs . push ( SpendableOutputDescriptor :: StaticOutput {
4030
4017
outpoint : OutPoint { txid : tx. txid ( ) , index : i as u16 } ,
4031
4018
output : outp. clone ( ) ,
4032
4019
} ) ;
4033
4020
}
4034
4021
if let Some ( ref broadcasted_holder_revokable_script) = self . broadcasted_holder_revokable_script {
4035
4022
if broadcasted_holder_revokable_script. 0 == outp. script_pubkey {
4036
- return Some ( SpendableOutputDescriptor :: DelayedPaymentOutput ( DelayedPaymentOutputDescriptor {
4023
+ spendable_outputs . push ( SpendableOutputDescriptor :: DelayedPaymentOutput ( DelayedPaymentOutputDescriptor {
4037
4024
outpoint : OutPoint { txid : tx. txid ( ) , index : i as u16 } ,
4038
4025
per_commitment_point : broadcasted_holder_revokable_script. 1 ,
4039
4026
to_self_delay : self . on_holder_tx_csv ,
@@ -4045,29 +4032,29 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
4045
4032
}
4046
4033
}
4047
4034
if self . counterparty_payment_script == outp. script_pubkey {
4048
- return Some ( SpendableOutputDescriptor :: StaticPaymentOutput ( StaticPaymentOutputDescriptor {
4035
+ spendable_outputs . push ( SpendableOutputDescriptor :: StaticPaymentOutput ( StaticPaymentOutputDescriptor {
4049
4036
outpoint : OutPoint { txid : tx. txid ( ) , index : i as u16 } ,
4050
4037
output : outp. clone ( ) ,
4051
4038
channel_keys_id : self . channel_keys_id ,
4052
4039
channel_value_satoshis : self . channel_value_satoshis ,
4053
4040
} ) ) ;
4054
4041
}
4055
4042
if self . shutdown_script . as_ref ( ) == Some ( & outp. script_pubkey ) {
4056
- return Some ( SpendableOutputDescriptor :: StaticOutput {
4043
+ spendable_outputs . push ( SpendableOutputDescriptor :: StaticOutput {
4057
4044
outpoint : OutPoint { txid : tx. txid ( ) , index : i as u16 } ,
4058
4045
output : outp. clone ( ) ,
4059
4046
} ) ;
4060
4047
}
4061
4048
}
4062
- None
4049
+ spendable_outputs
4063
4050
}
4064
4051
4065
4052
/// Checks if the confirmed transaction is paying funds back to some address we can assume to
4066
4053
/// own.
4067
- fn check_tx_and_push_spendable_output < L : Deref > (
4054
+ fn check_tx_and_push_spendable_outputs < L : Deref > (
4068
4055
& mut self , tx : & Transaction , height : u32 , block_hash : & BlockHash , logger : & L ,
4069
4056
) 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) {
4071
4058
let entry = OnchainEventEntry {
4072
4059
txid : tx. txid ( ) ,
4073
4060
transaction : Some ( tx. clone ( ) ) ,
0 commit comments