@@ -3232,16 +3232,14 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3232
3232
/// height > height + CLTV_SHARED_CLAIM_BUFFER. In any case, will install monitoring for
3233
3233
/// HTLC-Success/HTLC-Timeout transactions.
3234
3234
///
3235
- /// Returns packages to claim the revoked output(s), as well as additional outputs to watch and
3236
- /// general information about the output that is to the counterparty in the commitment
3237
- /// transaction.
3235
+ /// Returns packages to claim the revoked output(s) and general information about the output that
3236
+ /// is to the counterparty in the commitment transaction.
3238
3237
fn check_spend_counterparty_transaction < L : Deref > ( & mut self , tx : & Transaction , height : u32 , block_hash : & BlockHash , logger : & L )
3239
- -> ( Vec < PackageTemplate > , TransactionOutputs , CommitmentTxCounterpartyOutputInfo )
3238
+ -> ( Vec < PackageTemplate > , CommitmentTxCounterpartyOutputInfo )
3240
3239
where L :: Target : Logger {
3241
3240
// Most secp and related errors trying to create keys means we have no hope of constructing
3242
3241
// a spend transaction...so we return no transactions to broadcast
3243
3242
let mut claimable_outpoints = Vec :: new ( ) ;
3244
- let mut watch_outputs = Vec :: new ( ) ;
3245
3243
let mut to_counterparty_output_info = None ;
3246
3244
3247
3245
let commitment_txid = tx. txid ( ) ; //TODO: This is gonna be a performance bottleneck for watchtowers!
@@ -3251,7 +3249,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3251
3249
( $thing : expr ) => {
3252
3250
match $thing {
3253
3251
Ok ( a) => a,
3254
- Err ( _) => return ( claimable_outpoints, ( commitment_txid , watch_outputs ) , to_counterparty_output_info)
3252
+ Err ( _) => return ( claimable_outpoints, to_counterparty_output_info)
3255
3253
}
3256
3254
} ;
3257
3255
}
@@ -3285,8 +3283,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3285
3283
if transaction_output_index as usize >= tx. output . len ( ) ||
3286
3284
tx. output [ transaction_output_index as usize ] . value != htlc. amount_msat / 1000 {
3287
3285
// per_commitment_data is corrupt or our commitment signing key leaked!
3288
- return ( claimable_outpoints, ( commitment_txid, watch_outputs) ,
3289
- to_counterparty_output_info) ;
3286
+ return ( claimable_outpoints, to_counterparty_output_info) ;
3290
3287
}
3291
3288
let revk_htlc_outp = RevokedHTLCOutput :: build ( per_commitment_point, self . counterparty_commitment_params . counterparty_delayed_payment_base_key , self . counterparty_commitment_params . counterparty_htlc_base_key , per_commitment_key, htlc. amount_msat / 1000 , htlc. clone ( ) , & self . onchain_tx_handler . channel_transaction_parameters . channel_type_features ) ;
3292
3289
let justice_package = PackageTemplate :: build_package ( commitment_txid, transaction_output_index, PackageSolvingData :: RevokedHTLCOutput ( revk_htlc_outp) , htlc. cltv_expiry , height) ;
@@ -3299,9 +3296,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3299
3296
if !claimable_outpoints. is_empty ( ) || per_commitment_option. is_some ( ) { // ie we're confident this is actually ours
3300
3297
// We're definitely a counterparty commitment transaction!
3301
3298
log_error ! ( logger, "Got broadcast of revoked counterparty commitment transaction, going to generate general spend tx with {} inputs" , claimable_outpoints. len( ) ) ;
3302
- for ( idx, outp) in tx. output . iter ( ) . enumerate ( ) {
3303
- watch_outputs. push ( ( idx as u32 , outp. clone ( ) ) ) ;
3304
- }
3305
3299
self . counterparty_commitment_txn_on_chain . insert ( commitment_txid, commitment_number) ;
3306
3300
3307
3301
if let Some ( per_commitment_claimable_data) = per_commitment_option {
@@ -3327,9 +3321,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3327
3321
// already processed the block, resulting in the counterparty_commitment_txn_on_chain entry
3328
3322
// not being generated by the above conditional. Thus, to be safe, we go ahead and
3329
3323
// insert it here.
3330
- for ( idx, outp) in tx. output . iter ( ) . enumerate ( ) {
3331
- watch_outputs. push ( ( idx as u32 , outp. clone ( ) ) ) ;
3332
- }
3333
3324
self . counterparty_commitment_txn_on_chain . insert ( commitment_txid, commitment_number) ;
3334
3325
3335
3326
log_info ! ( logger, "Got broadcast of non-revoked counterparty commitment transaction {}" , commitment_txid) ;
@@ -3345,7 +3336,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3345
3336
}
3346
3337
3347
3338
}
3348
- ( claimable_outpoints, ( commitment_txid , watch_outputs ) , to_counterparty_output_info)
3339
+ ( claimable_outpoints, to_counterparty_output_info)
3349
3340
}
3350
3341
3351
3342
/// Returns the HTLC claim package templates and the counterparty output info
@@ -3777,24 +3768,25 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3777
3768
self . funding_spend_seen = true ;
3778
3769
let mut commitment_tx_to_counterparty_output = None ;
3779
3770
if ( tx. input [ 0 ] . sequence . 0 >> 8 * 3 ) as u8 == 0x80 && ( tx. lock_time . to_consensus_u32 ( ) >> 8 * 3 ) as u8 == 0x20 {
3780
- let ( mut new_outpoints, new_outputs, counterparty_output_idx_sats) =
3781
- self . check_spend_counterparty_transaction ( & tx, height, & block_hash, & logger) ;
3782
- commitment_tx_to_counterparty_output = counterparty_output_idx_sats;
3783
- if !new_outputs. 1 . is_empty ( ) {
3784
- watch_outputs. push ( new_outputs) ;
3785
- }
3786
- claimable_outpoints. append ( & mut new_outpoints) ;
3787
- if new_outpoints. is_empty ( ) {
3788
- if let Some ( ( mut new_outpoints, new_outputs) ) = self . check_spend_holder_transaction ( & tx, height, & block_hash, & logger) {
3789
- #[ cfg( not( fuzzing) ) ]
3790
- debug_assert ! ( commitment_tx_to_counterparty_output. is_none( ) ,
3791
- "A commitment transaction matched as both a counterparty and local commitment tx?" ) ;
3792
- if !new_outputs. 1 . is_empty ( ) {
3793
- watch_outputs. push ( new_outputs) ;
3794
- }
3795
- claimable_outpoints. append ( & mut new_outpoints) ;
3796
- balance_spendable_csv = Some ( self . on_holder_tx_csv ) ;
3771
+ if let Some ( ( mut new_outpoints, new_outputs) ) = self . check_spend_holder_transaction ( & tx, height, & block_hash, & logger) {
3772
+ if !new_outputs. 1 . is_empty ( ) {
3773
+ watch_outputs. push ( new_outputs) ;
3774
+ }
3775
+
3776
+ claimable_outpoints. append ( & mut new_outpoints) ;
3777
+ balance_spendable_csv = Some ( self . on_holder_tx_csv ) ;
3778
+ } else {
3779
+ let mut new_watch_outputs = Vec :: new ( ) ;
3780
+ for ( idx, outp) in tx. output . iter ( ) . enumerate ( ) {
3781
+ new_watch_outputs. push ( ( idx as u32 , outp. clone ( ) ) ) ;
3797
3782
}
3783
+ watch_outputs. push ( ( txid, new_watch_outputs) ) ;
3784
+
3785
+ let ( mut new_outpoints, counterparty_output_idx_sats) =
3786
+ self . check_spend_counterparty_transaction ( & tx, height, & block_hash, & logger) ;
3787
+ commitment_tx_to_counterparty_output = counterparty_output_idx_sats;
3788
+
3789
+ claimable_outpoints. append ( & mut new_outpoints) ;
3798
3790
}
3799
3791
}
3800
3792
self . onchain_events_awaiting_threshold_conf . push ( OnchainEventEntry {
0 commit comments