@@ -1306,12 +1306,15 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
1306
1306
header, height, broadcaster, fee_estimator, logger)
1307
1307
}
1308
1308
1309
- /// Processes transactions from a block with the given header and height, returning new outputs
1310
- /// to watch. See [`block_connected`] for details.
1309
+ /// Processes transactions confirmed in a block with the given header and height, returning new
1310
+ /// outputs to watch. See [`block_connected`] for details.
1311
1311
///
1312
- /// TODO: Expand docs.
1312
+ /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
1313
+ /// blocks. May be called before or after [`update_best_block`] for transactions in the
1314
+ /// corresponding block. See [`update_best_block`] for further calling expectations.
1313
1315
///
1314
1316
/// [`block_connected`]: Self::block_connected
1317
+ /// [`update_best_block`]: Self::update_best_block
1315
1318
pub fn transactions_confirmed < B : Deref , F : Deref , L : Deref > (
1316
1319
& self ,
1317
1320
header : & BlockHeader ,
@@ -1329,6 +1332,35 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
1329
1332
self . inner . lock ( ) . unwrap ( ) . transactions_confirmed (
1330
1333
header, txdata, height, broadcaster, fee_estimator, logger)
1331
1334
}
1335
+
1336
+ /// Updates the monitor with the current best chain tip, returning new outputs to watch. See
1337
+ /// [`block_connected`] for details.
1338
+ ///
1339
+ /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
1340
+ /// blocks. May be called before or after [`transactions_confirmed`] for the corresponding
1341
+ /// block.
1342
+ ///
1343
+ /// Must be called after new blocks become available for the most recent block. Intermediary
1344
+ /// blocks, however, may be safely skipped.
1345
+ ///
1346
+ /// [`block_connected`]: Self::block_connected
1347
+ /// [`transactions_confirmed`]: Self::transactions_confirmed
1348
+ pub fn update_best_block < B : Deref , F : Deref , L : Deref > (
1349
+ & self ,
1350
+ header : & BlockHeader ,
1351
+ height : u32 ,
1352
+ broadcaster : B ,
1353
+ fee_estimator : F ,
1354
+ logger : L ,
1355
+ ) -> Vec < ( Txid , Vec < ( u32 , TxOut ) > ) >
1356
+ where
1357
+ B :: Target : BroadcasterInterface ,
1358
+ F :: Target : FeeEstimator ,
1359
+ L :: Target : Logger ,
1360
+ {
1361
+ self . inner . lock ( ) . unwrap ( ) . update_best_block (
1362
+ header, height, broadcaster, fee_estimator, logger)
1363
+ }
1332
1364
}
1333
1365
1334
1366
impl < Signer : Sign > ChannelMonitorImpl < Signer > {
@@ -2030,10 +2062,33 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2030
2062
F :: Target : FeeEstimator ,
2031
2063
L :: Target : Logger ,
2032
2064
{
2033
- self . best_block = BestBlock :: new ( header. block_hash ( ) , height) ;
2065
+ let block_hash = header. block_hash ( ) ;
2066
+ log_trace ! ( logger, "New best block {} at height {}" , block_hash, height) ;
2067
+ self . best_block = BestBlock :: new ( block_hash, height) ;
2068
+
2034
2069
self . transactions_confirmed ( header, txdata, height, broadcaster, fee_estimator, logger)
2035
2070
}
2036
2071
2072
+ fn update_best_block < B : Deref , F : Deref , L : Deref > (
2073
+ & mut self ,
2074
+ header : & BlockHeader ,
2075
+ height : u32 ,
2076
+ broadcaster : B ,
2077
+ fee_estimator : F ,
2078
+ logger : L ,
2079
+ ) -> Vec < ( Txid , Vec < ( u32 , TxOut ) > ) >
2080
+ where
2081
+ B :: Target : BroadcasterInterface ,
2082
+ F :: Target : FeeEstimator ,
2083
+ L :: Target : Logger ,
2084
+ {
2085
+ let block_hash = header. block_hash ( ) ;
2086
+ log_trace ! ( logger, "New best block {} at height {}" , block_hash, height) ;
2087
+ self . best_block = BestBlock :: new ( block_hash, height) ;
2088
+
2089
+ self . block_confirmed ( height, vec ! [ ] , vec ! [ ] , vec ! [ ] , broadcaster, fee_estimator, logger)
2090
+ }
2091
+
2037
2092
fn transactions_confirmed < B : Deref , F : Deref , L : Deref > (
2038
2093
& mut self ,
2039
2094
header : & BlockHeader ,
@@ -2102,11 +2157,28 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2102
2157
2103
2158
self . is_paying_spendable_output ( & tx, height, & logger) ;
2104
2159
}
2160
+
2161
+ self . block_confirmed ( height, txn_matched, watch_outputs, claimable_outpoints, broadcaster, fee_estimator, logger)
2162
+ }
2163
+
2164
+ fn block_confirmed < B : Deref , F : Deref , L : Deref > (
2165
+ & mut self ,
2166
+ height : u32 ,
2167
+ txn_matched : Vec < & Transaction > ,
2168
+ mut watch_outputs : Vec < ( Txid , Vec < ( u32 , TxOut ) > ) > ,
2169
+ mut claimable_outpoints : Vec < ClaimRequest > ,
2170
+ broadcaster : B ,
2171
+ fee_estimator : F ,
2172
+ logger : L ,
2173
+ ) -> Vec < ( Txid , Vec < ( u32 , TxOut ) > ) >
2174
+ where
2175
+ B :: Target : BroadcasterInterface ,
2176
+ F :: Target : FeeEstimator ,
2177
+ L :: Target : Logger ,
2178
+ {
2105
2179
let should_broadcast = self . would_broadcast_at_height ( height, & logger) ;
2106
2180
if should_broadcast {
2107
2181
claimable_outpoints. push ( ClaimRequest { absolute_timelock : height, aggregable : false , outpoint : BitcoinOutPoint { txid : self . funding_info . 0 . txid . clone ( ) , vout : self . funding_info . 0 . index as u32 } , witness_data : InputMaterial :: Funding { funding_redeemscript : self . funding_redeemscript . clone ( ) } } ) ;
2108
- }
2109
- if should_broadcast {
2110
2182
self . pending_monitor_events . push ( MonitorEvent :: CommitmentTxBroadcasted ( self . funding_info . 0 ) ) ;
2111
2183
let commitment_tx = self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) ;
2112
2184
self . holder_tx_signed = true ;
0 commit comments