@@ -1268,6 +1268,14 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
1268
1268
/// The node_id of our counterparty
1269
1269
counterparty_node_id : PublicKey ,
1270
1270
1271
+ /// Controls whether the monitor is allowed to automatically broadcast the latest holder commitment transaction.
1272
+ ///
1273
+ /// This flag is set to `false` when a channel is force-closed with `should_broadcast: false`,
1274
+ /// indicating that broadcasting the latest holder commitment transaction would be unsafe.
1275
+ ///
1276
+ /// Default: `true`.
1277
+ allow_automated_broadcast : bool ,
1278
+
1271
1279
/// Initial counterparty commmitment data needed to recreate the commitment tx
1272
1280
/// in the persistence pipeline for third-party watchtowers. This will only be present on
1273
1281
/// monitors created after 0.0.117.
@@ -1569,6 +1577,7 @@ impl<Signer: EcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
1569
1577
( 27 , self . first_confirmed_funding_txo, required) ,
1570
1578
( 29 , self . initial_counterparty_commitment_tx, option) ,
1571
1579
( 31 , self . funding. channel_parameters, required) ,
1580
+ ( 33 , self . allow_automated_broadcast, required) ,
1572
1581
( 32 , self . pending_funding, optional_vec) ,
1573
1582
} ) ;
1574
1583
@@ -1788,6 +1797,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1788
1797
1789
1798
best_block,
1790
1799
counterparty_node_id : counterparty_node_id,
1800
+ allow_automated_broadcast : true ,
1791
1801
initial_counterparty_commitment_info : None ,
1792
1802
initial_counterparty_commitment_tx : None ,
1793
1803
balances_empty_height : None ,
@@ -2144,7 +2154,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2144
2154
/// may be to contact the other node operator out-of-band to coordinate other options available
2145
2155
/// to you.
2146
2156
#[ rustfmt:: skip]
2147
- pub fn broadcast_latest_holder_commitment_txn < B : Deref , F : Deref , L : Deref > (
2157
+ pub fn force_broadcast_latest_holder_commitment_txn_unsafe < B : Deref , F : Deref , L : Deref > (
2148
2158
& self , broadcaster : & B , fee_estimator : & F , logger : & L
2149
2159
)
2150
2160
where
@@ -3681,6 +3691,32 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3681
3691
Ok ( ( ) )
3682
3692
}
3683
3693
3694
+ fn maybe_broadcast_latest_holder_commitment_txn < B : Deref , F : Deref , L : Deref > (
3695
+ & mut self , broadcaster : & B , fee_estimator : & LowerBoundedFeeEstimator < F > ,
3696
+ logger : & WithChannelMonitor < L > ,
3697
+ ) where
3698
+ B :: Target : BroadcasterInterface ,
3699
+ F :: Target : FeeEstimator ,
3700
+ L :: Target : Logger ,
3701
+ {
3702
+ if !self . allow_automated_broadcast {
3703
+ return ;
3704
+ }
3705
+ let detected_funding_spend = self . funding_spend_confirmed . is_some ( )
3706
+ || self
3707
+ . onchain_events_awaiting_threshold_conf
3708
+ . iter ( )
3709
+ . any ( |event| matches ! ( event. event, OnchainEvent :: FundingSpendConfirmation { .. } ) ) ;
3710
+ if detected_funding_spend {
3711
+ log_trace ! (
3712
+ logger,
3713
+ "Avoiding commitment broadcast, already detected confirmed spend onchain"
3714
+ ) ;
3715
+ return ;
3716
+ }
3717
+ self . queue_latest_holder_commitment_txn_for_broadcast ( broadcaster, fee_estimator, logger) ;
3718
+ }
3719
+
3684
3720
#[ rustfmt:: skip]
3685
3721
fn update_monitor < B : Deref , F : Deref , L : Deref > (
3686
3722
& mut self , updates : & ChannelMonitorUpdate , broadcaster : & B , fee_estimator : & F , logger : & WithChannelMonitor < L >
@@ -3774,28 +3810,14 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3774
3810
ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } => {
3775
3811
log_trace ! ( logger, "Updating ChannelMonitor: channel force closed, should broadcast: {}" , should_broadcast) ;
3776
3812
self . lockdown_from_offchain = true ;
3777
- if * should_broadcast {
3778
- // There's no need to broadcast our commitment transaction if we've seen one
3779
- // confirmed (even with 1 confirmation) as it'll be rejected as
3780
- // duplicate/conflicting.
3781
- let detected_funding_spend = self . funding_spend_confirmed . is_some ( ) ||
3782
- self . onchain_events_awaiting_threshold_conf . iter ( ) . any (
3783
- |event| matches ! ( event. event, OnchainEvent :: FundingSpendConfirmation { .. } ) ) ;
3784
- if detected_funding_spend {
3785
- log_trace ! ( logger, "Avoiding commitment broadcast, already detected confirmed spend onchain" ) ;
3786
- continue ;
3787
- }
3788
- self . queue_latest_holder_commitment_txn_for_broadcast ( broadcaster, & bounded_fee_estimator, logger) ;
3789
- } else if !self . holder_tx_signed {
3790
- log_error ! ( logger, "WARNING: You have a potentially-unsafe holder commitment transaction available to broadcast" ) ;
3791
- log_error ! ( logger, " in channel monitor for channel {}!" , & self . channel_id( ) ) ;
3792
- log_error ! ( logger, " Read the docs for ChannelMonitor::broadcast_latest_holder_commitment_txn to take manual action!" ) ;
3793
- } else {
3813
+ self . allow_automated_broadcast = * should_broadcast;
3814
+ if !* should_broadcast && self . holder_tx_signed {
3794
3815
// If we generated a MonitorEvent::HolderForceClosed, the ChannelManager
3795
3816
// will still give us a ChannelForceClosed event with !should_broadcast, but we
3796
3817
// shouldn't print the scary warning above.
3797
3818
log_info ! ( logger, "Channel off-chain state closed after we broadcasted our latest commitment transaction." ) ;
3798
3819
}
3820
+ self . maybe_broadcast_latest_holder_commitment_txn ( broadcaster, & bounded_fee_estimator, logger) ;
3799
3821
} ,
3800
3822
ChannelMonitorUpdateStep :: ShutdownScript { scriptpubkey } => {
3801
3823
log_trace ! ( logger, "Updating ChannelMonitor with shutdown script" ) ;
@@ -5682,6 +5704,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
5682
5704
let mut first_confirmed_funding_txo = RequiredWrapper ( None ) ;
5683
5705
let mut channel_parameters = None ;
5684
5706
let mut pending_funding = None ;
5707
+ let mut allow_automated_broadcast = None ;
5685
5708
read_tlv_fields ! ( reader, {
5686
5709
( 1 , funding_spend_confirmed, option) ,
5687
5710
( 3 , htlcs_resolved_on_chain, optional_vec) ,
@@ -5700,6 +5723,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
5700
5723
( 29 , initial_counterparty_commitment_tx, option) ,
5701
5724
( 31 , channel_parameters, ( option: ReadableArgs , None ) ) ,
5702
5725
( 32 , pending_funding, optional_vec) ,
5726
+ ( 33 , allow_automated_broadcast, option) ,
5703
5727
} ) ;
5704
5728
if let Some ( payment_preimages_with_info) = payment_preimages_with_info {
5705
5729
if payment_preimages_with_info. len ( ) != payment_preimages. len ( ) {
@@ -5864,6 +5888,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
5864
5888
5865
5889
best_block,
5866
5890
counterparty_node_id : counterparty_node_id. unwrap ( ) ,
5891
+ allow_automated_broadcast : allow_automated_broadcast. unwrap_or ( true ) ,
5867
5892
initial_counterparty_commitment_info,
5868
5893
initial_counterparty_commitment_tx,
5869
5894
balances_empty_height,
0 commit comments