@@ -2308,23 +2308,16 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23082308
23092309 /// Determines if the disconnected block contained any transactions of interest and updates
23102310 /// appropriately.
2311- #[ rustfmt:: skip]
2312- pub fn block_disconnected < B : Deref , F : Deref , L : Deref > (
2313- & self ,
2314- header : & Header ,
2315- height : u32 ,
2316- broadcaster : B ,
2317- fee_estimator : F ,
2318- logger : & L ,
2311+ pub fn blocks_disconnected < B : Deref , F : Deref , L : Deref > (
2312+ & self , fork_point : BestBlock , broadcaster : B , fee_estimator : F , logger : & L ,
23192313 ) where
23202314 B :: Target : BroadcasterInterface ,
23212315 F :: Target : FeeEstimator ,
23222316 L :: Target : Logger ,
23232317 {
23242318 let mut inner = self . inner . lock ( ) . unwrap ( ) ;
23252319 let logger = WithChannelMonitor :: from_impl ( logger, & * inner, None ) ;
2326- inner. block_disconnected (
2327- header, height, broadcaster, fee_estimator, & logger)
2320+ inner. blocks_disconnected ( fork_point, broadcaster, fee_estimator, & logger)
23282321 }
23292322
23302323 /// Processes transactions confirmed in a block with the given header and height, returning new
@@ -2358,10 +2351,10 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23582351
23592352 /// Processes a transaction that was reorganized out of the chain.
23602353 ///
2361- /// Used instead of [`block_disconnected `] by clients that are notified of transactions rather
2354+ /// Used instead of [`blocks_disconnected `] by clients that are notified of transactions rather
23622355 /// than blocks. See [`chain::Confirm`] for calling expectations.
23632356 ///
2364- /// [`block_disconnected `]: Self::block_disconnected
2357+ /// [`blocks_disconnected `]: Self::blocks_disconnected
23652358 #[ rustfmt:: skip]
23662359 pub fn transaction_unconfirmed < B : Deref , F : Deref , L : Deref > (
23672360 & self ,
@@ -5124,8 +5117,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
51245117 log_trace ! ( logger, "Best block re-orged, replaced with new block {} at height {}" , block_hash, height) ;
51255118 self . onchain_events_awaiting_threshold_conf . retain ( |ref entry| entry. height <= height) ;
51265119 let conf_target = self . closure_conf_target ( ) ;
5127- self . onchain_tx_handler . block_disconnected (
5128- height + 1 , & broadcaster, conf_target, & self . destination_script , fee_estimator, logger,
5120+ self . onchain_tx_handler . blocks_disconnected (
5121+ height, & broadcaster, conf_target, & self . destination_script , fee_estimator, logger,
51295122 ) ;
51305123 Vec :: new ( )
51315124 } else { Vec :: new ( ) }
@@ -5452,12 +5445,12 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
54525445 !unmatured_htlcs. contains( & source) ,
54535446 "An unmature HTLC transaction conflicts with a maturing one; failed to \
54545447 call either transaction_unconfirmed for the conflicting transaction \
5455- or block_disconnected for a block containing it.") ;
5448+ or blocks_disconnected for a block before it.") ;
54565449 debug_assert ! (
54575450 !matured_htlcs. contains( & source) ,
54585451 "A matured HTLC transaction conflicts with a maturing one; failed to \
54595452 call either transaction_unconfirmed for the conflicting transaction \
5460- or block_disconnected for a block containing it.") ;
5453+ or blocks_disconnected for a block before it.") ;
54615454 matured_htlcs. push ( source. clone ( ) ) ;
54625455 }
54635456
@@ -5605,23 +5598,26 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
56055598 }
56065599
56075600 #[ rustfmt:: skip]
5608- fn block_disconnected < B : Deref , F : Deref , L : Deref > (
5609- & mut self , header : & Header , height : u32 , broadcaster : B , fee_estimator : F , logger : & WithChannelMonitor < L >
5601+ fn blocks_disconnected < B : Deref , F : Deref , L : Deref > (
5602+ & mut self , fork_point : BestBlock , broadcaster : B , fee_estimator : F , logger : & WithChannelMonitor < L >
56105603 ) where B :: Target : BroadcasterInterface ,
56115604 F :: Target : FeeEstimator ,
56125605 L :: Target : Logger ,
56135606 {
5614- log_trace ! ( logger, "Block {} at height {} disconnected" , header. block_hash( ) , height) ;
5607+ let new_height = fork_point. height ;
5608+ log_trace ! ( logger, "Block(s) disconnected to height {}" , new_height) ;
5609+ assert ! ( self . best_block. height > fork_point. height,
5610+ "Blocks disconnected must indicate disconnection from the current best height, i.e. the new chain tip must be lower than the previous best height" ) ;
56155611
56165612 //We may discard:
56175613 //- htlc update there as failure-trigger tx (revoked commitment tx, non-revoked commitment tx, HTLC-timeout tx) has been disconnected
56185614 //- maturing spendable output has transaction paying us has been disconnected
5619- self . onchain_events_awaiting_threshold_conf . retain ( |ref entry| entry. height < height ) ;
5615+ self . onchain_events_awaiting_threshold_conf . retain ( |ref entry| entry. height <= new_height ) ;
56205616
56215617 // TODO: Replace with `take_if` once our MSRV is >= 1.80.
56225618 let mut should_broadcast_commitment = false ;
56235619 if let Some ( ( _, conf_height) ) = self . alternative_funding_confirmed . as_ref ( ) {
5624- if * conf_height == height {
5620+ if * conf_height > new_height {
56255621 self . alternative_funding_confirmed . take ( ) ;
56265622 if self . holder_tx_signed || self . funding_spend_seen {
56275623 // Cancel any previous claims that are no longer valid as they stemmed from a
@@ -5637,8 +5633,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
56375633
56385634 let bounded_fee_estimator = LowerBoundedFeeEstimator :: new ( fee_estimator) ;
56395635 let conf_target = self . closure_conf_target ( ) ;
5640- self . onchain_tx_handler . block_disconnected (
5641- height , & broadcaster, conf_target, & self . destination_script , & bounded_fee_estimator, logger
5636+ self . onchain_tx_handler . blocks_disconnected (
5637+ new_height , & broadcaster, conf_target, & self . destination_script , & bounded_fee_estimator, logger
56425638 ) ;
56435639
56445640 // Only attempt to broadcast the new commitment after the `block_disconnected` call above so that
@@ -5647,7 +5643,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
56475643 self . queue_latest_holder_commitment_txn_for_broadcast ( & broadcaster, & bounded_fee_estimator, logger) ;
56485644 }
56495645
5650- self . best_block = BestBlock :: new ( header . prev_blockhash , height - 1 ) ;
5646+ self . best_block = fork_point ;
56515647 }
56525648
56535649 #[ rustfmt:: skip]
@@ -6121,8 +6117,8 @@ where
61216117 self . 0 . block_connected ( header, txdata, height, & * self . 1 , & * self . 2 , & self . 3 ) ;
61226118 }
61236119
6124- fn block_disconnected ( & self , header : & Header , height : u32 ) {
6125- self . 0 . block_disconnected ( header , height , & * self . 1 , & * self . 2 , & self . 3 ) ;
6120+ fn blocks_disconnected ( & self , fork_point : BestBlock ) {
6121+ self . 0 . blocks_disconnected ( fork_point , & * self . 1 , & * self . 2 , & self . 3 ) ;
61266122 }
61276123}
61286124
0 commit comments