@@ -3008,23 +3008,26 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
30083008 ( payment_preimage. clone ( ) , payment_info. clone ( ) . into_iter ( ) . collect ( ) )
30093009 } ) ;
30103010
3011- let confirmed_spend_txid = self . funding_spend_confirmed . or_else ( || {
3012- self . onchain_events_awaiting_threshold_conf . iter ( ) . find_map ( |event| match event. event {
3013- OnchainEvent :: FundingSpendConfirmation { .. } => Some ( event. txid ) ,
3014- _ => None ,
3015- } )
3016- } ) ;
3017- let confirmed_spend_txid = if let Some ( txid) = confirmed_spend_txid {
3018- txid
3019- } else {
3020- return ;
3021- } ;
3011+ let confirmed_spend_info = self . funding_spend_confirmed
3012+ . map ( |txid| ( txid, None ) )
3013+ . or_else ( || {
3014+ self . onchain_events_awaiting_threshold_conf . iter ( ) . find_map ( |event| match event. event {
3015+ OnchainEvent :: FundingSpendConfirmation { .. } => Some ( ( event. txid , Some ( event. height ) ) ) ,
3016+ _ => None ,
3017+ } )
3018+ } ) ;
3019+ let ( confirmed_spend_txid, confirmed_spend_height) =
3020+ if let Some ( ( txid, height) ) = confirmed_spend_info {
3021+ ( txid, height)
3022+ } else {
3023+ return ;
3024+ } ;
30223025
30233026 // If the channel is force closed, try to claim the output from this preimage.
30243027 // First check if a counterparty commitment transaction has been broadcasted:
30253028 macro_rules! claim_htlcs {
30263029 ( $commitment_number: expr, $txid: expr, $htlcs: expr) => {
3027- let ( htlc_claim_reqs, _) = self . get_counterparty_output_claim_info( $commitment_number, $txid, None , $htlcs) ;
3030+ let ( htlc_claim_reqs, _) = self . get_counterparty_output_claim_info( $commitment_number, $txid, None , $htlcs, confirmed_spend_height ) ;
30283031 let conf_target = self . closure_conf_target( ) ;
30293032 self . onchain_tx_handler. update_claims_view_from_requests( htlc_claim_reqs, self . best_block. height, self . best_block. height, broadcaster, conf_target, fee_estimator, logger) ;
30303033 }
@@ -3542,7 +3545,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
35423545 // First, process non-htlc outputs (to_holder & to_counterparty)
35433546 for ( idx, outp) in tx. output . iter ( ) . enumerate ( ) {
35443547 if outp. script_pubkey == revokeable_p2wsh {
3545- let revk_outp = RevokedOutput :: build ( per_commitment_point, self . counterparty_commitment_params . counterparty_delayed_payment_base_key , self . counterparty_commitment_params . counterparty_htlc_base_key , per_commitment_key, outp. value , self . counterparty_commitment_params . on_counterparty_tx_csv , self . onchain_tx_handler . channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) ) ;
3548+ let revk_outp = RevokedOutput :: build ( per_commitment_point, self . counterparty_commitment_params . counterparty_delayed_payment_base_key , self . counterparty_commitment_params . counterparty_htlc_base_key , per_commitment_key, outp. value , self . counterparty_commitment_params . on_counterparty_tx_csv , self . onchain_tx_handler . channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) , height ) ;
35463549 let justice_package = PackageTemplate :: build_package (
35473550 commitment_txid, idx as u32 ,
35483551 PackageSolvingData :: RevokedOutput ( revk_outp) ,
@@ -3563,7 +3566,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
35633566 // per_commitment_data is corrupt or our commitment signing key leaked!
35643567 return ( claimable_outpoints, to_counterparty_output_info) ;
35653568 }
3566- 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 ) ;
3569+ 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 , height ) ;
35673570 let counterparty_spendable_height = if htlc. offered {
35683571 htlc. cltv_expiry
35693572 } else {
@@ -3617,7 +3620,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
36173620 ( htlc, htlc_source. as_ref( ) . map( |htlc_source| htlc_source. as_ref( ) ) )
36183621 ) , logger) ;
36193622 let ( htlc_claim_reqs, counterparty_output_info) =
3620- self . get_counterparty_output_claim_info ( commitment_number, commitment_txid, Some ( tx) , per_commitment_option) ;
3623+ self . get_counterparty_output_claim_info ( commitment_number, commitment_txid, Some ( tx) , per_commitment_option, Some ( height ) ) ;
36213624 to_counterparty_output_info = counterparty_output_info;
36223625 for req in htlc_claim_reqs {
36233626 claimable_outpoints. push ( req) ;
@@ -3628,7 +3631,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
36283631 }
36293632
36303633 /// Returns the HTLC claim package templates and the counterparty output info
3631- fn get_counterparty_output_claim_info ( & self , commitment_number : u64 , commitment_txid : Txid , tx : Option < & Transaction > , per_commitment_option : Option < & Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > > )
3634+ fn get_counterparty_output_claim_info ( & self , commitment_number : u64 , commitment_txid : Txid , tx : Option < & Transaction > , per_commitment_option : Option < & Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > > , confirmation_height : Option < u32 > )
36323635 -> ( Vec < PackageTemplate > , CommitmentTxCounterpartyOutputInfo ) {
36333636 let mut claimable_outpoints = Vec :: new ( ) ;
36343637 let mut to_counterparty_output_info: CommitmentTxCounterpartyOutputInfo = None ;
@@ -3688,13 +3691,15 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
36883691 CounterpartyOfferedHTLCOutput :: build ( * per_commitment_point,
36893692 self . counterparty_commitment_params . counterparty_delayed_payment_base_key ,
36903693 self . counterparty_commitment_params . counterparty_htlc_base_key ,
3691- preimage. unwrap ( ) , htlc. clone ( ) , self . onchain_tx_handler . channel_type_features ( ) . clone ( ) ) )
3694+ preimage. unwrap ( ) , htlc. clone ( ) , self . onchain_tx_handler . channel_type_features ( ) . clone ( ) ,
3695+ confirmation_height) )
36923696 } else {
36933697 PackageSolvingData :: CounterpartyReceivedHTLCOutput (
36943698 CounterpartyReceivedHTLCOutput :: build ( * per_commitment_point,
36953699 self . counterparty_commitment_params . counterparty_delayed_payment_base_key ,
36963700 self . counterparty_commitment_params . counterparty_htlc_base_key ,
3697- htlc. clone ( ) , self . onchain_tx_handler . channel_type_features ( ) . clone ( ) ) )
3701+ htlc. clone ( ) , self . onchain_tx_handler . channel_type_features ( ) . clone ( ) ,
3702+ confirmation_height) )
36983703 } ;
36993704 let counterparty_package = PackageTemplate :: build_package ( commitment_txid, transaction_output_index, counterparty_htlc_outp, htlc. cltv_expiry ) ;
37003705 claimable_outpoints. push ( counterparty_package) ;
@@ -3736,7 +3741,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
37363741 per_commitment_point, self . counterparty_commitment_params . counterparty_delayed_payment_base_key ,
37373742 self . counterparty_commitment_params . counterparty_htlc_base_key , per_commitment_key,
37383743 tx. output [ idx] . value , self . counterparty_commitment_params . on_counterparty_tx_csv ,
3739- false
3744+ false , height ,
37403745 ) ;
37413746 let justice_package = PackageTemplate :: build_package (
37423747 htlc_txid, idx as u32 , PackageSolvingData :: RevokedOutput ( revk_outp) ,
@@ -3765,7 +3770,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
37653770 if let Some ( transaction_output_index) = htlc. transaction_output_index {
37663771 let ( htlc_output, counterparty_spendable_height) = if htlc. offered {
37673772 let htlc_output = HolderHTLCOutput :: build_offered (
3768- htlc. amount_msat , htlc. cltv_expiry , self . onchain_tx_handler . channel_type_features ( ) . clone ( )
3773+ htlc. amount_msat , htlc. cltv_expiry , self . onchain_tx_handler . channel_type_features ( ) . clone ( ) , conf_height
37693774 ) ;
37703775 ( htlc_output, conf_height)
37713776 } else {
@@ -3776,7 +3781,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
37763781 continue ;
37773782 } ;
37783783 let htlc_output = HolderHTLCOutput :: build_accepted (
3779- payment_preimage, htlc. amount_msat , self . onchain_tx_handler . channel_type_features ( ) . clone ( )
3784+ payment_preimage, htlc. amount_msat , self . onchain_tx_handler . channel_type_features ( ) . clone ( ) , conf_height
37803785 ) ;
37813786 ( htlc_output, htlc. cltv_expiry )
37823787 } ;
0 commit comments