@@ -2327,6 +2327,16 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2327
2327
/// close channel with their commitment transaction after a substantial amount of time. Best
2328
2328
/// may be to contact the other node operator out-of-band to coordinate other options available
2329
2329
/// to you.
2330
+ ///
2331
+ /// Note: For channels using manual funding broadcast (see
2332
+ /// [`crate::ln::channelmanager::ChannelManager::funding_transaction_generated_manual_broadcast`]),
2333
+ /// automatic broadcasts are suppressed until the funding transaction has been observed on-chain.
2334
+ /// Calling this method overrides that suppression and queues the latest holder commitment
2335
+ /// transaction for broadcast even if the funding has not yet been seen on-chain. This may result
2336
+ /// in unconfirmable transactions being broadcast or [`Event::BumpTransaction`] notifications for
2337
+ /// transactions that cannot be confirmed until the funding transaction is visible.
2338
+ ///
2339
+ /// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
2330
2340
pub fn broadcast_latest_holder_commitment_txn < B : Deref , F : Deref , L : Deref > (
2331
2341
& self , broadcaster : & B , fee_estimator : & F , logger : & L ,
2332
2342
) where
@@ -2337,10 +2347,12 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2337
2347
let mut inner = self . inner . lock ( ) . unwrap ( ) ;
2338
2348
let fee_estimator = LowerBoundedFeeEstimator :: new ( & * * fee_estimator) ;
2339
2349
let logger = WithChannelMonitor :: from_impl ( logger, & * inner, None ) ;
2350
+
2340
2351
inner. queue_latest_holder_commitment_txn_for_broadcast (
2341
2352
broadcaster,
2342
2353
& fee_estimator,
2343
2354
& logger,
2355
+ false ,
2344
2356
) ;
2345
2357
}
2346
2358
@@ -3958,8 +3970,15 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3958
3970
}
3959
3971
3960
3972
#[ rustfmt:: skip]
3973
+ /// Note: For channels where the funding transaction is being manually managed (see
3974
+ /// [`crate::ln::channelmanager::ChannelManager::funding_transaction_generated_manual_broadcast`]),
3975
+ /// this method returns without queuing any transactions until the funding transaction has been
3976
+ /// observed on-chain, unless `require_funding_seen` is `false`. This prevents attempting to
3977
+ /// broadcast unconfirmable holder commitment transactions before the funding is visible.
3978
+ /// See also
3979
+ /// [`crate::chain::channelmonitor::ChannelMonitor::broadcast_latest_holder_commitment_txn`].
3961
3980
pub ( crate ) fn queue_latest_holder_commitment_txn_for_broadcast < B : Deref , F : Deref , L : Deref > (
3962
- & mut self , broadcaster : & B , fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & WithChannelMonitor < L >
3981
+ & mut self , broadcaster : & B , fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & WithChannelMonitor < L > , require_funding_seen : bool ,
3963
3982
)
3964
3983
where
3965
3984
B :: Target : BroadcasterInterface ,
@@ -3971,6 +3990,12 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3971
3990
message : "ChannelMonitor-initiated commitment transaction broadcast" . to_owned ( ) ,
3972
3991
} ;
3973
3992
let ( claimable_outpoints, _) = self . generate_claimable_outpoints_and_watch_outputs ( Some ( reason) ) ;
3993
+ // In manual-broadcast mode, if `require_funding_seen` is true and we have not yet observed
3994
+ // the funding transaction on-chain, do not queue any transactions.
3995
+ if require_funding_seen && self . is_manual_broadcast && !self . funding_seen_onchain {
3996
+ log_info ! ( logger, "Not broadcasting holder commitment for manual-broadcast channel before funding appears on-chain" ) ;
3997
+ return ;
3998
+ }
3974
3999
let conf_target = self . closure_conf_target ( ) ;
3975
4000
self . onchain_tx_handler . update_claims_view_from_requests (
3976
4001
claimable_outpoints, self . best_block . height , self . best_block . height , broadcaster,
@@ -4285,7 +4310,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
4285
4310
log_trace ! ( logger, "Avoiding commitment broadcast, already detected confirmed spend onchain" ) ;
4286
4311
continue ;
4287
4312
}
4288
- self . queue_latest_holder_commitment_txn_for_broadcast ( broadcaster, & bounded_fee_estimator, logger) ;
4313
+ self . queue_latest_holder_commitment_txn_for_broadcast ( broadcaster, & bounded_fee_estimator, logger, true ) ;
4289
4314
} else if !self . holder_tx_signed {
4290
4315
log_error ! ( logger, "WARNING: You have a potentially-unsafe holder commitment transaction available to broadcast" ) ;
4291
4316
log_error ! ( logger, " in channel monitor for channel {}!" , & self . channel_id( ) ) ;
@@ -5751,7 +5776,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
5751
5776
// Only attempt to broadcast the new commitment after the `block_disconnected` call above so that
5752
5777
// it doesn't get removed from the set of pending claims.
5753
5778
if should_broadcast_commitment {
5754
- self . queue_latest_holder_commitment_txn_for_broadcast ( & broadcaster, & bounded_fee_estimator, logger) ;
5779
+ self . queue_latest_holder_commitment_txn_for_broadcast ( & broadcaster, & bounded_fee_estimator, logger, true ) ;
5755
5780
}
5756
5781
5757
5782
self . best_block = fork_point;
@@ -5812,7 +5837,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
5812
5837
// Only attempt to broadcast the new commitment after the `transaction_unconfirmed` call above so
5813
5838
// that it doesn't get removed from the set of pending claims.
5814
5839
if should_broadcast_commitment {
5815
- self . queue_latest_holder_commitment_txn_for_broadcast ( & broadcaster, fee_estimator, logger) ;
5840
+ self . queue_latest_holder_commitment_txn_for_broadcast ( & broadcaster, fee_estimator, logger, true ) ;
5816
5841
}
5817
5842
}
5818
5843
@@ -6945,7 +6970,7 @@ mod tests {
6945
6970
let monitor = ChannelMonitor :: new (
6946
6971
Secp256k1 :: new ( ) , keys, Some ( shutdown_script. into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
6947
6972
& channel_parameters, true , 0 , HolderCommitmentTransaction :: dummy ( 0 , funding_outpoint, Vec :: new ( ) ) ,
6948
- best_block, dummy_key, channel_id,
6973
+ best_block, dummy_key, channel_id, false ,
6949
6974
) ;
6950
6975
6951
6976
let nondust_htlcs = preimages_slice_to_htlcs ! ( preimages[ 0 ..10 ] ) ;
@@ -7205,7 +7230,7 @@ mod tests {
7205
7230
let monitor = ChannelMonitor :: new (
7206
7231
Secp256k1 :: new ( ) , keys, Some ( shutdown_script. into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
7207
7232
& channel_parameters, true , 0 , HolderCommitmentTransaction :: dummy ( 0 , funding_outpoint, Vec :: new ( ) ) ,
7208
- best_block, dummy_key, channel_id,
7233
+ best_block, dummy_key, channel_id, false
7209
7234
) ;
7210
7235
7211
7236
let chan_id = monitor. inner . lock ( ) . unwrap ( ) . channel_id ( ) ;
0 commit comments