@@ -1144,7 +1144,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11441144
11451145 /// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all
11461146 /// commitment_tx_infos which contain the payment hash have been revoked.
1147- pub ( crate ) fn provide_payment_preimage ( & mut self , payment_hash : & PaymentHash , payment_preimage : & PaymentPreimage ) {
1147+ pub ( crate ) fn provide_payment_preimage < B : Deref , F : Deref , L : Deref > ( & mut self , payment_hash : & PaymentHash , payment_preimage : & PaymentPreimage , broadcaster : & B , fee_estimator : & F , logger : & L )
1148+ where B :: Target : BroadcasterInterface ,
1149+ F :: Target : FeeEstimator ,
1150+ L :: Target : Logger ,
1151+ {
11481152 self . payment_preimages . insert ( payment_hash. clone ( ) , payment_preimage. clone ( ) ) ;
11491153 }
11501154
@@ -1162,26 +1166,36 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11621166 /// itself.
11631167 ///
11641168 /// panics if the given update is not the next update by update_id.
1165- pub fn update_monitor < B : Deref , L : Deref > ( & mut self , updates : & ChannelMonitorUpdate , broadcaster : & B , logger : & L ) -> Result < ( ) , MonitorUpdateError >
1166- where B :: Target : BroadcasterInterface ,
1167- L :: Target : Logger ,
1169+ pub fn update_monitor < B : Deref , F : Deref , L : Deref > ( & mut self , updates : & ChannelMonitorUpdate , broadcaster : & B , fee_estimator : & F , logger : & L ) -> Result < ( ) , MonitorUpdateError >
1170+ where B :: Target : BroadcasterInterface ,
1171+ F :: Target : FeeEstimator ,
1172+ L :: Target : Logger ,
11681173 {
11691174 if self . latest_update_id + 1 != updates. update_id {
11701175 panic ! ( "Attempted to apply ChannelMonitorUpdates out of order, check the update_id before passing an update to update_monitor!" ) ;
11711176 }
11721177 for update in updates. updates . iter ( ) {
11731178 match update {
11741179 ChannelMonitorUpdateStep :: LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs } => {
1180+ log_trace ! ( logger, "Updating ChannelMonitor with latest holder commitment transaction info" ) ;
11751181 if self . lockdown_from_offchain { panic ! ( ) ; }
11761182 self . provide_latest_holder_commitment_tx_info ( commitment_tx. clone ( ) , htlc_outputs. clone ( ) ) ?
11771183 } ,
1178- ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point } =>
1179- self . provide_latest_counterparty_commitment_tx_info ( & unsigned_commitment_tx, htlc_outputs. clone ( ) , * commitment_number, * their_revocation_point, logger) ,
1184+ ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point } => {
1185+ log_trace ! ( logger, "Updating ChannelMonitor with latest counterparty commitment transaction info" ) ;
1186+ self . provide_latest_counterparty_commitment_tx_info ( & unsigned_commitment_tx, htlc_outputs. clone ( ) , * commitment_number, * their_revocation_point, logger)
1187+ } ,
11801188 ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage } =>
1181- self . provide_payment_preimage ( & PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 [ ..] ) . into_inner ( ) ) , & payment_preimage) ,
1182- ChannelMonitorUpdateStep :: CommitmentSecret { idx, secret } =>
1183- self . provide_secret ( * idx, * secret) ?,
1189+ {
1190+ log_trace ! ( logger, "Updating ChannelMonitor with payment preimage" ) ;
1191+ self . provide_payment_preimage ( & PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 [ ..] ) . into_inner ( ) ) , & payment_preimage, broadcaster, fee_estimator, logger)
1192+ } ,
1193+ ChannelMonitorUpdateStep :: CommitmentSecret { idx, secret } => {
1194+ log_trace ! ( logger, "Updating ChannelMonitor with commitment secret" ) ;
1195+ self . provide_secret ( * idx, * secret) ?
1196+ } ,
11841197 ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } => {
1198+ log_trace ! ( logger, "Updating ChannelMonitor: channel force closed, should broadcast: {}" , should_broadcast) ;
11851199 self . lockdown_from_offchain = true ;
11861200 if * should_broadcast {
11871201 self . broadcast_latest_holder_commitment_txn ( broadcaster, logger) ;
@@ -2486,16 +2500,18 @@ mod tests {
24862500 use ln:: onchaintx:: { OnchainTxHandler , InputDescriptors } ;
24872501 use ln:: chan_utils;
24882502 use ln:: chan_utils:: { HTLCOutputInCommitment , HolderCommitmentTransaction } ;
2489- use util:: test_utils:: TestLogger ;
2503+ use util:: test_utils:: { TestLogger , TestBroadcaster , TestFeeEstimator } ;
24902504 use bitcoin:: secp256k1:: key:: { SecretKey , PublicKey } ;
24912505 use bitcoin:: secp256k1:: Secp256k1 ;
2492- use std:: sync:: Arc ;
2506+ use std:: sync:: { Arc , Mutex } ;
24932507 use chain:: keysinterface:: InMemoryChannelKeys ;
24942508
24952509 #[ test]
24962510 fn test_prune_preimages ( ) {
24972511 let secp_ctx = Secp256k1 :: new ( ) ;
24982512 let logger = Arc :: new ( TestLogger :: new ( ) ) ;
2513+ let broadcaster = Arc :: new ( TestBroadcaster { txn_broadcasted : Mutex :: new ( Vec :: new ( ) ) } ) ;
2514+ let fee_estimator = Arc :: new ( TestFeeEstimator { sat_per_kw : 253 } ) ;
24992515
25002516 let dummy_key = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
25012517 let dummy_tx = Transaction { version : 0 , lock_time : 0 , input : Vec :: new ( ) , output : Vec :: new ( ) } ;
@@ -2571,7 +2587,7 @@ mod tests {
25712587 monitor. provide_latest_counterparty_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 17 ..20 ] ) , 281474976710653 , dummy_key, & logger) ;
25722588 monitor. provide_latest_counterparty_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 18 ..20 ] ) , 281474976710652 , dummy_key, & logger) ;
25732589 for & ( ref preimage, ref hash) in preimages. iter ( ) {
2574- monitor. provide_payment_preimage ( hash, preimage) ;
2590+ monitor. provide_payment_preimage ( hash, preimage, & broadcaster , & fee_estimator , & logger ) ;
25752591 }
25762592
25772593 // Now provide a secret, pruning preimages 10-15
0 commit comments