@@ -2256,11 +2256,12 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2256
2256
/// may be to contact the other node operator out-of-band to coordinate other options available
2257
2257
/// to you.
2258
2258
///
2259
- /// Note: For channels where the funding transaction is being manually managed (see
2260
- /// [`crate::ln::channelmanager::ChannelManager::funding_transaction_generated_manual_broadcast`]), this call will be
2261
- /// ignored until the funding transaction has been observed on-chain.
2262
- /// This prevents unconfirmable commitment transactions from being broadcast before funding is
2263
- /// visible.
2259
+ /// Note: For channels using manual funding broadcast (see
2260
+ /// [`crate::ln::channelmanager::ChannelManager::funding_transaction_generated_manual_broadcast`]),
2261
+ /// automatic broadcasts are suppressed until the funding transaction has been observed on-chain.
2262
+ /// Calling this method overrides that suppression and queues the latest holder commitment
2263
+ /// transaction for broadcast even if the funding has not yet been seen on-chain. This is unsafe
2264
+ /// and may result in unconfirmable transactions.
2264
2265
#[ rustfmt:: skip]
2265
2266
pub fn broadcast_latest_holder_commitment_txn < B : Deref , F : Deref , L : Deref > (
2266
2267
& self , broadcaster : & B , fee_estimator : & F , logger : & L
@@ -2273,7 +2274,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2273
2274
let mut inner = self . inner . lock ( ) . unwrap ( ) ;
2274
2275
let fee_estimator = LowerBoundedFeeEstimator :: new ( & * * fee_estimator) ;
2275
2276
let logger = WithChannelMonitor :: from_impl ( logger, & * inner, None ) ;
2276
- inner. queue_latest_holder_commitment_txn_for_broadcast ( broadcaster, & fee_estimator, & logger) ;
2277
+ inner. queue_latest_holder_commitment_txn_for_broadcast ( broadcaster, & fee_estimator, & logger, false ) ;
2277
2278
}
2278
2279
2279
2280
/// Unsafe test-only version of `broadcast_latest_holder_commitment_txn` used by our test framework
@@ -3918,15 +3919,24 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3918
3919
}
3919
3920
3920
3921
#[ rustfmt:: skip]
3922
+ /// Note: For channels where the funding transaction is being manually managed (see
3923
+ /// [`crate::ln::channelmanager::ChannelManager::funding_transaction_generated_manual_broadcast`]),
3924
+ /// this method returns without queuing any transactions until the funding transaction has been
3925
+ /// observed on-chain, unless `require_funding_seen` is `false`. This prevents attempting to
3926
+ /// broadcast unconfirmable holder commitment transactions before the funding is visible.
3927
+ /// See also
3928
+ /// [`crate::chain::channelmonitor::ChannelMonitor::broadcast_latest_holder_commitment_txn`].
3921
3929
pub ( crate ) fn queue_latest_holder_commitment_txn_for_broadcast < B : Deref , F : Deref , L : Deref > (
3922
- & mut self , broadcaster : & B , fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & WithChannelMonitor < L >
3930
+ & mut self , broadcaster : & B , fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & WithChannelMonitor < L > , require_funding_seen : bool ,
3923
3931
)
3924
3932
where
3925
3933
B :: Target : BroadcasterInterface ,
3926
3934
F :: Target : FeeEstimator ,
3927
3935
L :: Target : Logger ,
3928
3936
{
3929
- if self . is_manual_broadcast && !self . funding_seen_onchain {
3937
+ // In manual-broadcast mode, if `require_funding_seen` is true and we have not yet observed
3938
+ // the funding transaction on-chain, do not queue any transactions.
3939
+ if require_funding_seen && self . is_manual_broadcast && !self . funding_seen_onchain {
3930
3940
log_info ! ( logger, "Not broadcasting holder commitment for manual-broadcast channel before funding appears on-chain" ) ;
3931
3941
return ;
3932
3942
}
@@ -4248,7 +4258,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
4248
4258
log_trace ! ( logger, "Avoiding commitment broadcast, already detected confirmed spend onchain" ) ;
4249
4259
continue ;
4250
4260
}
4251
- self . queue_latest_holder_commitment_txn_for_broadcast ( broadcaster, & bounded_fee_estimator, logger) ;
4261
+ self . queue_latest_holder_commitment_txn_for_broadcast ( broadcaster, & bounded_fee_estimator, logger, true ) ;
4252
4262
} else if !self . holder_tx_signed {
4253
4263
log_error ! ( logger, "WARNING: You have a potentially-unsafe holder commitment transaction available to broadcast" ) ;
4254
4264
log_error ! ( logger, " in channel monitor for channel {}!" , & self . channel_id( ) ) ;
@@ -5414,11 +5424,11 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
5414
5424
5415
5425
if should_broadcast_commitment {
5416
5426
// Avoid broadcasting in manual-broadcast mode until funding is seen on-chain.
5417
- if !self . is_manual_broadcast || self . funding_seen_onchain {
5418
- let ( mut claimables, mut outputs) =
5419
- self . generate_claimable_outpoints_and_watch_outputs ( None ) ;
5420
- claimable_outpoints. append ( & mut claimables) ;
5421
- watch_outputs. append ( & mut outputs) ;
5427
+ if !self . is_manual_broadcast || self . funding_seen_onchain {
5428
+ let ( mut claimables, mut outputs) =
5429
+ self . generate_claimable_outpoints_and_watch_outputs ( None ) ;
5430
+ claimable_outpoints. append ( & mut claimables) ;
5431
+ watch_outputs. append ( & mut outputs) ;
5422
5432
}
5423
5433
}
5424
5434
@@ -5456,9 +5466,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
5456
5466
let should_broadcast = self . should_broadcast_holder_commitment_txn ( logger) ;
5457
5467
if let Some ( payment_hash) = should_broadcast {
5458
5468
let reason = ClosureReason :: HTLCsTimedOut { payment_hash : Some ( payment_hash) } ;
5459
- if self . is_manual_broadcast && !self . funding_seen_onchain {
5460
- let _ = self . generate_claimable_outpoints_and_watch_outputs ( Some ( reason) ) ;
5461
- } else {
5469
+ if !self . is_manual_broadcast || self . funding_seen_onchain {
5462
5470
let ( mut new_outpoints, mut new_outputs) =
5463
5471
self . generate_claimable_outpoints_and_watch_outputs ( Some ( reason) ) ;
5464
5472
claimable_outpoints. append ( & mut new_outpoints) ;
@@ -5690,7 +5698,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
5690
5698
// Only attempt to broadcast the new commitment after the `block_disconnected` call above so that
5691
5699
// it doesn't get removed from the set of pending claims.
5692
5700
if should_broadcast_commitment {
5693
- self . queue_latest_holder_commitment_txn_for_broadcast ( & broadcaster, & bounded_fee_estimator, logger) ;
5701
+ self . queue_latest_holder_commitment_txn_for_broadcast ( & broadcaster, & bounded_fee_estimator, logger, true ) ;
5694
5702
}
5695
5703
5696
5704
self . best_block = fork_point;
@@ -5725,12 +5733,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
5725
5733
}
5726
5734
5727
5735
debug_assert ! ( !self . onchain_events_awaiting_threshold_conf. iter( ) . any( |ref entry| entry. txid == * txid) ) ;
5728
- if * txid == self . funding . funding_txid ( ) ||
5729
- self . pending_funding . iter ( ) . any ( |f| f. funding_txid ( ) == * txid)
5730
- {
5731
- log_trace ! ( logger, "transaction_unconfirmed removed observed funding. resetting funding_seen_onchain" ) ;
5732
- self . funding_seen_onchain = false ;
5733
- }
5734
5736
5735
5737
// TODO: Replace with `take_if` once our MSRV is >= 1.80.
5736
5738
let mut should_broadcast_commitment = false ;
@@ -5757,7 +5759,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
5757
5759
// Only attempt to broadcast the new commitment after the `transaction_unconfirmed` call above so
5758
5760
// that it doesn't get removed from the set of pending claims.
5759
5761
if should_broadcast_commitment {
5760
- self . queue_latest_holder_commitment_txn_for_broadcast ( & broadcaster, fee_estimator, logger) ;
5762
+ self . queue_latest_holder_commitment_txn_for_broadcast ( & broadcaster, fee_estimator, logger, true ) ;
5761
5763
}
5762
5764
}
5763
5765
@@ -6556,7 +6558,8 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
6556
6558
} ,
6557
6559
pending_funding : pending_funding. unwrap_or ( vec ! [ ] ) ,
6558
6560
is_manual_broadcast : is_manual_broadcast. unwrap_or ( false ) ,
6559
- funding_seen_onchain : funding_seen_onchain. unwrap_or ( false ) ,
6561
+ // Assume "seen" when absent to prevent gating holder broadcasts after upgrade.
6562
+ funding_seen_onchain : funding_seen_onchain. unwrap_or ( true ) ,
6560
6563
6561
6564
latest_update_id,
6562
6565
commitment_transaction_number_obscure_factor,
0 commit comments