@@ -3933,6 +3933,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39333933 #[ rustfmt:: skip]
39343934 fn generate_claimable_outpoints_and_watch_outputs (
39353935 & mut self , generate_monitor_event_with_reason : Option < ClosureReason > ,
3936+ require_funding_seen : bool ,
39363937 ) -> ( Vec < PackageTemplate > , Vec < TransactionOutputs > ) {
39373938 let funding = get_confirmed_funding_scope ! ( self ) ;
39383939 let holder_commitment_tx = & funding. current_holder_commitment_tx ;
@@ -3960,6 +3961,13 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39603961 // in the claim that is queued to OnchainTxHandler. We set holder_tx_signed here to reject
39613962 // new channel updates.
39623963 self . holder_tx_signed = true ;
3964+
3965+ // In manual-broadcast mode, if we have not yet observed the funding transaction on-chain,
3966+ // return empty vectors rather than triggering a broadcast.
3967+ if require_funding_seen && self . is_manual_broadcast && !self . funding_seen_onchain {
3968+ return ( Vec :: new ( ) , Vec :: new ( ) ) ;
3969+ }
3970+
39633971 let mut watch_outputs = Vec :: new ( ) ;
39643972 // In CSV anchor channels, we can't broadcast our HTLC transactions while the commitment transaction is
39653973 // unconfirmed.
@@ -3985,13 +3993,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39853993 }
39863994 claimable_outpoints. append ( & mut new_outpoints) ;
39873995 }
3988- // In manual-broadcast mode, if we have not yet observed the funding transaction on-chain,
3989- // return empty vectors.
3990- if self . is_manual_broadcast && !self . funding_seen_onchain {
3991- return ( Vec :: new ( ) , Vec :: new ( ) ) ;
3992- } else {
3993- ( claimable_outpoints, watch_outputs)
3994- }
3996+ ( claimable_outpoints, watch_outputs)
39953997 }
39963998
39973999 #[ rustfmt:: skip]
@@ -4004,7 +4006,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
40044006 ///
40054007 /// [`ChannelMonitor::broadcast_latest_holder_commitment_txn`]: crate::chain::channelmonitor::ChannelMonitor::broadcast_latest_holder_commitment_txn
40064008 pub ( crate ) fn queue_latest_holder_commitment_txn_for_broadcast < B : Deref , F : Deref , L : Deref > (
4007- & mut self , broadcaster : & B , fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & WithChannelMonitor < L > , require_funding_seen : bool ,
4009+ & mut self , broadcaster : & B , fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & WithChannelMonitor < L > ,
4010+ require_funding_seen : bool ,
40084011 )
40094012 where
40104013 B :: Target : BroadcasterInterface ,
@@ -4015,7 +4018,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
40154018 broadcasted_latest_txn : Some ( true ) ,
40164019 message : "ChannelMonitor-initiated commitment transaction broadcast" . to_owned ( ) ,
40174020 } ;
4018- let ( claimable_outpoints, _) = self . generate_claimable_outpoints_and_watch_outputs ( Some ( reason) ) ;
4021+ let ( claimable_outpoints, _) =
4022+ self . generate_claimable_outpoints_and_watch_outputs ( Some ( reason) , require_funding_seen) ;
40194023 // In manual-broadcast mode, if `require_funding_seen` is true and we have not yet observed
40204024 // the funding transaction on-chain, do not queue any transactions.
40214025 if require_funding_seen && self . is_manual_broadcast && !self . funding_seen_onchain {
@@ -5618,7 +5622,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
56185622
56195623 if should_broadcast_commitment {
56205624 let ( mut claimables, mut outputs) =
5621- self . generate_claimable_outpoints_and_watch_outputs ( None ) ;
5625+ self . generate_claimable_outpoints_and_watch_outputs ( None , false ) ;
56225626 claimable_outpoints. append ( & mut claimables) ;
56235627 watch_outputs. append ( & mut outputs) ;
56245628 }
@@ -5660,9 +5664,13 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
56605664 if let Some ( payment_hash) = should_broadcast {
56615665 let reason = ClosureReason :: HTLCsTimedOut { payment_hash : Some ( payment_hash) } ;
56625666 let ( mut new_outpoints, mut new_outputs) =
5663- self . generate_claimable_outpoints_and_watch_outputs ( Some ( reason) ) ;
5664- claimable_outpoints. append ( & mut new_outpoints) ;
5665- watch_outputs. append ( & mut new_outputs) ;
5667+ self . generate_claimable_outpoints_and_watch_outputs ( Some ( reason) , false ) ;
5668+ if !self . is_manual_broadcast || self . funding_seen_onchain {
5669+ claimable_outpoints. append ( & mut new_outpoints) ;
5670+ watch_outputs. append ( & mut new_outputs) ;
5671+ } else {
5672+ log_info ! ( logger, "Not broadcasting holder commitment for manual-broadcast channel before funding appears on-chain" ) ;
5673+ }
56665674 }
56675675 }
56685676
@@ -5969,7 +5977,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
59695977 /// Filters a block's `txdata` for transactions spending watched outputs or for any child
59705978 /// transactions thereof.
59715979 #[ rustfmt:: skip]
5972- fn filter_block < ' a > ( & mut self , txdata : & TransactionData < ' a > ) -> Vec < & ' a Transaction > {
5980+ fn filter_block < ' a > ( & self , txdata : & TransactionData < ' a > ) -> Vec < & ' a Transaction > {
59735981 let mut matched_txn = new_hash_set ( ) ;
59745982 txdata. iter ( ) . filter ( |& & ( _, tx) | {
59755983 let mut matches = self . spends_watched_output ( tx) ;
0 commit comments