@@ -2339,8 +2339,16 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
23392339 F :: Target : FeeEstimator ,
23402340 L :: Target : Logger ,
23412341 {
2342- log_info ! ( logger, "Applying update to monitor {}, bringing update_id from {} to {} with {} changes." ,
2343- log_funding_info!( self ) , self . latest_update_id, updates. update_id, updates. updates. len( ) ) ;
2342+ if self . latest_update_id == CLOSED_CHANNEL_UPDATE_ID && updates. update_id == CLOSED_CHANNEL_UPDATE_ID {
2343+ log_info ! ( logger, "Applying post-force-closed update to monitor {} with {} change(s)." ,
2344+ log_funding_info!( self ) , updates. updates. len( ) ) ;
2345+ } else if updates. update_id == CLOSED_CHANNEL_UPDATE_ID {
2346+ log_info ! ( logger, "Applying force close update to monitor {} with {} change(s)." ,
2347+ log_funding_info!( self ) , updates. updates. len( ) ) ;
2348+ } else {
2349+ log_info ! ( logger, "Applying update to monitor {}, bringing update_id from {} to {} with {} change(s)." ,
2350+ log_funding_info!( self ) , self . latest_update_id, updates. update_id, updates. updates. len( ) ) ;
2351+ }
23442352 // ChannelMonitor updates may be applied after force close if we receive a preimage for a
23452353 // broadcasted commitment transaction HTLC output that we'd like to claim on-chain. If this
23462354 // is the case, we no longer have guaranteed access to the monitor's update ID, so we use a
@@ -2407,6 +2415,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
24072415 _ => false ,
24082416 } ) . is_some ( ) ;
24092417 if detected_funding_spend {
2418+ log_trace ! ( logger, "Avoiding commitment broadcast, already detected confirmed spend onchain" ) ;
24102419 continue ;
24112420 }
24122421 self . broadcast_latest_holder_commitment_txn ( broadcaster, logger) ;
@@ -2457,7 +2466,9 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
24572466
24582467 self . latest_update_id = updates. update_id ;
24592468
2460- if ret. is_ok ( ) && self . funding_spend_seen {
2469+ // Refuse updates after we've detected a spend onchain, but only if we haven't processed a
2470+ // force closed monitor update yet.
2471+ if ret. is_ok ( ) && self . funding_spend_seen && self . latest_update_id != CLOSED_CHANNEL_UPDATE_ID {
24612472 log_error ! ( logger, "Refusing Channel Monitor Update as counterparty attempted to update commitment after funding was spent" ) ;
24622473 Err ( ( ) )
24632474 } else { ret }
0 commit comments