@@ -1299,6 +1299,36 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
1299
1299
self . inner . lock ( ) . unwrap ( ) . block_disconnected (
1300
1300
header, height, broadcaster, fee_estimator, logger)
1301
1301
}
1302
+
1303
+ /// Processes transactions from a block with the given header and height, returning new outputs
1304
+ /// to watch. See [`block_connected`] for details.
1305
+ ///
1306
+ /// TODO: Expand docs.
1307
+ pub fn transactions_confirmed < B : Deref , F : Deref , L : Deref > (
1308
+ & self ,
1309
+ header : & BlockHeader ,
1310
+ txdata : & TransactionData ,
1311
+ height : u32 ,
1312
+ broadcaster : B ,
1313
+ fee_estimator : F ,
1314
+ logger : L ,
1315
+ ) -> Vec < ( Txid , Vec < ( u32 , TxOut ) > ) >
1316
+ where
1317
+ B :: Target : BroadcasterInterface ,
1318
+ F :: Target : FeeEstimator ,
1319
+ L :: Target : Logger ,
1320
+ {
1321
+ self . inner . lock ( ) . unwrap ( ) . transactions_confirmed (
1322
+ header, txdata, height, broadcaster, fee_estimator, & logger)
1323
+ }
1324
+
1325
+ /// Updates the monitor with the current best chain tip.
1326
+ ///
1327
+ /// TODO: Expand docs.
1328
+ pub fn update_best_block < L : Deref > ( & mut self , header : & BlockHeader , height : u32 , logger : L )
1329
+ where L :: Target : Logger {
1330
+ self . inner . lock ( ) . unwrap ( ) . update_best_block ( header, height, & logger)
1331
+ }
1302
1332
}
1303
1333
1304
1334
impl < Signer : Sign > ChannelMonitorImpl < Signer > {
@@ -1999,6 +2029,31 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1999
2029
where B :: Target : BroadcasterInterface ,
2000
2030
F :: Target : FeeEstimator ,
2001
2031
L :: Target : Logger ,
2032
+ {
2033
+ self . update_best_block ( header, height, & logger) ;
2034
+ self . transactions_confirmed ( header, txdata, height, broadcaster, fee_estimator, & logger)
2035
+ }
2036
+
2037
+ fn update_best_block < L : Deref > ( & mut self , header : & BlockHeader , height : u32 , logger : & L )
2038
+ where L :: Target : Logger {
2039
+ let block_hash = header. block_hash ( ) ;
2040
+ log_trace ! ( logger, "New best block {} at height {}" , block_hash, height) ;
2041
+ self . last_block_hash = block_hash;
2042
+ }
2043
+
2044
+ fn transactions_confirmed < B : Deref , F : Deref , L : Deref > (
2045
+ & mut self ,
2046
+ header : & BlockHeader ,
2047
+ txdata : & TransactionData ,
2048
+ height : u32 ,
2049
+ broadcaster : B ,
2050
+ fee_estimator : F ,
2051
+ logger : & L ,
2052
+ ) -> Vec < ( Txid , Vec < ( u32 , TxOut ) > ) >
2053
+ where
2054
+ B :: Target : BroadcasterInterface ,
2055
+ F :: Target : FeeEstimator ,
2056
+ L :: Target : Logger ,
2002
2057
{
2003
2058
let txn_matched = self . filter_block ( txdata) ;
2004
2059
for tx in & txn_matched {
@@ -2024,12 +2079,12 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2024
2079
let prevout = & tx. input [ 0 ] . previous_output ;
2025
2080
if prevout. txid == self . funding_info . 0 . txid && prevout. vout == self . funding_info . 0 . index as u32 {
2026
2081
if ( tx. input [ 0 ] . sequence >> 8 * 3 ) as u8 == 0x80 && ( tx. lock_time >> 8 * 3 ) as u8 == 0x20 {
2027
- let ( mut new_outpoints, new_outputs) = self . check_spend_counterparty_transaction ( & tx, height, & logger) ;
2082
+ let ( mut new_outpoints, new_outputs) = self . check_spend_counterparty_transaction ( & tx, height, logger) ;
2028
2083
if !new_outputs. 1 . is_empty ( ) {
2029
2084
watch_outputs. push ( new_outputs) ;
2030
2085
}
2031
2086
if new_outpoints. is_empty ( ) {
2032
- let ( mut new_outpoints, new_outputs) = self . check_spend_holder_transaction ( & tx, height, & logger) ;
2087
+ let ( mut new_outpoints, new_outputs) = self . check_spend_holder_transaction ( & tx, height, logger) ;
2033
2088
if !new_outputs. 1 . is_empty ( ) {
2034
2089
watch_outputs. push ( new_outputs) ;
2035
2090
}
@@ -2039,7 +2094,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2039
2094
}
2040
2095
} else {
2041
2096
if let Some ( & commitment_number) = self . counterparty_commitment_txn_on_chain . get ( & prevout. txid ) {
2042
- let ( mut new_outpoints, new_outputs_option) = self . check_spend_counterparty_htlc ( & tx, commitment_number, height, & logger) ;
2097
+ let ( mut new_outpoints, new_outputs_option) = self . check_spend_counterparty_htlc ( & tx, commitment_number, height, logger) ;
2043
2098
claimable_outpoints. append ( & mut new_outpoints) ;
2044
2099
if let Some ( new_outputs) = new_outputs_option {
2045
2100
watch_outputs. push ( new_outputs) ;
@@ -2050,11 +2105,11 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2050
2105
// While all commitment/HTLC-Success/HTLC-Timeout transactions have one input, HTLCs
2051
2106
// can also be resolved in a few other ways which can have more than one output. Thus,
2052
2107
// we call is_resolving_htlc_output here outside of the tx.input.len() == 1 check.
2053
- self . is_resolving_htlc_output ( & tx, height, & logger) ;
2108
+ self . is_resolving_htlc_output ( & tx, height, logger) ;
2054
2109
2055
- self . is_paying_spendable_output ( & tx, height, & logger) ;
2110
+ self . is_paying_spendable_output ( & tx, height, logger) ;
2056
2111
}
2057
- let should_broadcast = self . would_broadcast_at_height ( height, & logger) ;
2112
+ let should_broadcast = self . would_broadcast_at_height ( height, logger) ;
2058
2113
if should_broadcast {
2059
2114
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 ( ) } } ) ;
2060
2115
}
@@ -2095,8 +2150,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2095
2150
}
2096
2151
}
2097
2152
2098
- self . onchain_tx_handler . update_claims_view ( & txn_matched, claimable_outpoints, Some ( height) , & & * broadcaster, & & * fee_estimator, & & * logger) ;
2099
- self . last_block_hash = block_hash;
2153
+ self . onchain_tx_handler . update_claims_view ( & txn_matched, claimable_outpoints, Some ( height) , & & * broadcaster, & & * fee_estimator, & * logger) ;
2100
2154
2101
2155
// Determine new outputs to watch by comparing against previously known outputs to watch,
2102
2156
// updating the latter in the process.
0 commit comments