@@ -1331,6 +1331,29 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
1331
1331
header, txdata, height, broadcaster, fee_estimator, logger)
1332
1332
}
1333
1333
1334
+ /// Processes a transaction that was reorganized out of the chain.
1335
+ ///
1336
+ /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
1337
+ /// than blocks. May be called before or after [`update_best_block`] for transactions in the
1338
+ /// corresponding block. See [`update_best_block`] for further calling expectations.
1339
+ ///
1340
+ /// [`block_disconnected`]: Self::block_disconnected
1341
+ /// [`update_best_block`]: Self::update_best_block
1342
+ pub fn transaction_unconfirmed < B : Deref , F : Deref , L : Deref > (
1343
+ & self ,
1344
+ txid : & Txid ,
1345
+ broadcaster : B ,
1346
+ fee_estimator : F ,
1347
+ logger : L ,
1348
+ ) where
1349
+ B :: Target : BroadcasterInterface ,
1350
+ F :: Target : FeeEstimator ,
1351
+ L :: Target : Logger ,
1352
+ {
1353
+ self . inner . lock ( ) . unwrap ( ) . transaction_unconfirmed (
1354
+ txid, broadcaster, fee_estimator, logger) ;
1355
+ }
1356
+
1334
1357
/// Updates the monitor with the current best chain tip, returning new outputs to watch. See
1335
1358
/// [`block_connected`] for details.
1336
1359
///
@@ -1339,10 +1362,13 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
1339
1362
/// block.
1340
1363
///
1341
1364
/// Must be called after new blocks become available for the most recent block. Intermediary
1342
- /// blocks, however, may be safely skipped.
1365
+ /// blocks, however, may be safely skipped. In the event of a chain re-organization, this only
1366
+ /// needs to be called for the most recent block assuming `transaction_unconfirmed` is called
1367
+ /// for any affected transactions.
1343
1368
///
1344
1369
/// [`block_connected`]: Self::block_connected
1345
1370
/// [`transactions_confirmed`]: Self::transactions_confirmed
1371
+ /// [`transaction_unconfirmed`]: Self::transaction_unconfirmed
1346
1372
pub fn update_best_block < B : Deref , F : Deref , L : Deref > (
1347
1373
& self ,
1348
1374
header : & BlockHeader ,
@@ -2229,13 +2255,13 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2229
2255
debug_assert ! (
2230
2256
unmatured_htlcs. iter( ) . find( |& htlc| htlc == & htlc_update. 0 ) . is_none( ) ,
2231
2257
"An unmature HTLC transaction conflicts with a maturing one; failed to \
2232
- call block_disconnected for a block containing the conflicting \
2233
- transaction .") ;
2258
+ call either transaction_unconfirmed for the conflicting transaction \
2259
+ or block_disconnected for a block containing it .") ;
2234
2260
debug_assert ! (
2235
2261
matured_htlcs. iter( ) . find( |& htlc| htlc == & htlc_update. 0 ) . is_none( ) ,
2236
2262
"A matured HTLC transaction conflicts with a maturing one; failed to \
2237
- call block_disconnected for a block containing the conflicting \
2238
- transaction .") ;
2263
+ call either transaction_unconfirmed for the conflicting transaction \
2264
+ or block_disconnected for a block containing it .") ;
2239
2265
matured_htlcs. push ( htlc_update. 0 . clone ( ) ) ;
2240
2266
}
2241
2267
@@ -2297,6 +2323,21 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2297
2323
self . best_block = BestBlock :: new ( header. prev_blockhash , height - 1 ) ;
2298
2324
}
2299
2325
2326
+ fn transaction_unconfirmed < B : Deref , F : Deref , L : Deref > (
2327
+ & mut self ,
2328
+ txid : & Txid ,
2329
+ broadcaster : B ,
2330
+ fee_estimator : F ,
2331
+ logger : L ,
2332
+ ) where
2333
+ B :: Target : BroadcasterInterface ,
2334
+ F :: Target : FeeEstimator ,
2335
+ L :: Target : Logger ,
2336
+ {
2337
+ self . onchain_events_waiting_threshold_conf . retain ( |ref entry| entry. txid != * txid) ;
2338
+ self . onchain_tx_handler . transaction_unconfirmed ( txid, broadcaster, fee_estimator, logger) ;
2339
+ }
2340
+
2300
2341
/// Filters a block's `txdata` for transactions spending watched outputs or for any child
2301
2342
/// transactions thereof.
2302
2343
fn filter_block < ' a > ( & self , txdata : & TransactionData < ' a > ) -> Vec < & ' a Transaction > {
0 commit comments