@@ -2308,23 +2308,16 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2308
2308
2309
2309
/// Determines if the disconnected block contained any transactions of interest and updates
2310
2310
/// 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 ,
2319
2313
) where
2320
2314
B :: Target : BroadcasterInterface ,
2321
2315
F :: Target : FeeEstimator ,
2322
2316
L :: Target : Logger ,
2323
2317
{
2324
2318
let mut inner = self . inner . lock ( ) . unwrap ( ) ;
2325
2319
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)
2328
2321
}
2329
2322
2330
2323
/// Processes transactions confirmed in a block with the given header and height, returning new
@@ -2358,10 +2351,10 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2358
2351
2359
2352
/// Processes a transaction that was reorganized out of the chain.
2360
2353
///
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
2362
2355
/// than blocks. See [`chain::Confirm`] for calling expectations.
2363
2356
///
2364
- /// [`block_disconnected `]: Self::block_disconnected
2357
+ /// [`blocks_disconnected `]: Self::blocks_disconnected
2365
2358
#[ rustfmt:: skip]
2366
2359
pub fn transaction_unconfirmed < B : Deref , F : Deref , L : Deref > (
2367
2360
& self ,
@@ -5124,8 +5117,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
5124
5117
log_trace ! ( logger, "Best block re-orged, replaced with new block {} at height {}" , block_hash, height) ;
5125
5118
self . onchain_events_awaiting_threshold_conf . retain ( |ref entry| entry. height <= height) ;
5126
5119
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,
5129
5122
) ;
5130
5123
Vec :: new ( )
5131
5124
} else { Vec :: new ( ) }
@@ -5452,12 +5445,12 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
5452
5445
!unmatured_htlcs. contains( & source) ,
5453
5446
"An unmature HTLC transaction conflicts with a maturing one; failed to \
5454
5447
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.") ;
5456
5449
debug_assert ! (
5457
5450
!matured_htlcs. contains( & source) ,
5458
5451
"A matured HTLC transaction conflicts with a maturing one; failed to \
5459
5452
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.") ;
5461
5454
matured_htlcs. push ( source. clone ( ) ) ;
5462
5455
}
5463
5456
@@ -5605,23 +5598,26 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
5605
5598
}
5606
5599
5607
5600
#[ 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 >
5610
5603
) where B :: Target : BroadcasterInterface ,
5611
5604
F :: Target : FeeEstimator ,
5612
5605
L :: Target : Logger ,
5613
5606
{
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" ) ;
5615
5611
5616
5612
//We may discard:
5617
5613
//- htlc update there as failure-trigger tx (revoked commitment tx, non-revoked commitment tx, HTLC-timeout tx) has been disconnected
5618
5614
//- 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 ) ;
5620
5616
5621
5617
// TODO: Replace with `take_if` once our MSRV is >= 1.80.
5622
5618
let mut should_broadcast_commitment = false ;
5623
5619
if let Some ( ( _, conf_height) ) = self . alternative_funding_confirmed . as_ref ( ) {
5624
- if * conf_height == height {
5620
+ if * conf_height > new_height {
5625
5621
self . alternative_funding_confirmed . take ( ) ;
5626
5622
if self . holder_tx_signed || self . funding_spend_seen {
5627
5623
// Cancel any previous claims that are no longer valid as they stemmed from a
@@ -5637,8 +5633,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
5637
5633
5638
5634
let bounded_fee_estimator = LowerBoundedFeeEstimator :: new ( fee_estimator) ;
5639
5635
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
5642
5638
) ;
5643
5639
5644
5640
// Only attempt to broadcast the new commitment after the `block_disconnected` call above so that
@@ -5647,7 +5643,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
5647
5643
self . queue_latest_holder_commitment_txn_for_broadcast ( & broadcaster, & bounded_fee_estimator, logger) ;
5648
5644
}
5649
5645
5650
- self . best_block = BestBlock :: new ( header . prev_blockhash , height - 1 ) ;
5646
+ self . best_block = fork_point ;
5651
5647
}
5652
5648
5653
5649
#[ rustfmt:: skip]
@@ -6121,8 +6117,8 @@ where
6121
6117
self . 0 . block_connected ( header, txdata, height, & * self . 1 , & * self . 2 , & self . 3 ) ;
6122
6118
}
6123
6119
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 ) ;
6126
6122
}
6127
6123
}
6128
6124
0 commit comments