@@ -1159,7 +1159,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11591159
11601160 /// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all
11611161 /// commitment_tx_infos which contain the payment hash have been revoked.
1162- pub ( crate ) fn provide_payment_preimage ( & mut self , payment_hash : & PaymentHash , payment_preimage : & PaymentPreimage ) {
1162+ 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 )
1163+ where B :: Target : BroadcasterInterface ,
1164+ F :: Target : FeeEstimator ,
1165+ L :: Target : Logger ,
1166+ {
11631167 self . payment_preimages . insert ( payment_hash. clone ( ) , payment_preimage. clone ( ) ) ;
11641168 }
11651169
@@ -1177,9 +1181,10 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11771181 /// itself.
11781182 ///
11791183 /// panics if the given update is not the next update by update_id.
1180- pub fn update_monitor < B : Deref , L : Deref > ( & mut self , updates : & ChannelMonitorUpdate , broadcaster : & B , logger : & L ) -> Result < ( ) , MonitorUpdateError >
1181- where B :: Target : BroadcasterInterface ,
1182- L :: Target : Logger ,
1184+ pub fn update_monitor < B : Deref , F : Deref , L : Deref > ( & mut self , updates : & ChannelMonitorUpdate , broadcaster : & B , fee_estimator : & F , logger : & L ) -> Result < ( ) , MonitorUpdateError >
1185+ where B :: Target : BroadcasterInterface ,
1186+ F :: Target : FeeEstimator ,
1187+ L :: Target : Logger ,
11831188 {
11841189 // ChannelMonitor updates may be applied after force close if we receive a
11851190 // preimage for a broadcasted commitment transaction HTLC output that we'd
@@ -1197,16 +1202,24 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11971202 for update in updates. updates . iter ( ) {
11981203 match update {
11991204 ChannelMonitorUpdateStep :: LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs } => {
1205+ log_trace ! ( logger, "Updating ChannelMonitor with latest holder commitment transaction info" ) ;
12001206 if self . lockdown_from_offchain { panic ! ( ) ; }
12011207 self . provide_latest_holder_commitment_tx_info ( commitment_tx. clone ( ) , htlc_outputs. clone ( ) ) ?
12021208 } ,
1203- ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point } =>
1204- self . provide_latest_counterparty_commitment_tx_info ( & unsigned_commitment_tx, htlc_outputs. clone ( ) , * commitment_number, * their_revocation_point, logger) ,
1205- ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage } =>
1206- self . provide_payment_preimage ( & PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 [ ..] ) . into_inner ( ) ) , & payment_preimage) ,
1207- ChannelMonitorUpdateStep :: CommitmentSecret { idx, secret } =>
1208- self . provide_secret ( * idx, * secret) ?,
1209+ ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point } => {
1210+ log_trace ! ( logger, "Updating ChannelMonitor with latest counterparty commitment transaction info" ) ;
1211+ self . provide_latest_counterparty_commitment_tx_info ( & unsigned_commitment_tx, htlc_outputs. clone ( ) , * commitment_number, * their_revocation_point, logger)
1212+ } ,
1213+ ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage } => {
1214+ log_trace ! ( logger, "Updating ChannelMonitor with payment preimage" ) ;
1215+ self . provide_payment_preimage ( & PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 [ ..] ) . into_inner ( ) ) , & payment_preimage, broadcaster, fee_estimator, logger)
1216+ } ,
1217+ ChannelMonitorUpdateStep :: CommitmentSecret { idx, secret } => {
1218+ log_trace ! ( logger, "Updating ChannelMonitor with commitment secret" ) ;
1219+ self . provide_secret ( * idx, * secret) ?
1220+ } ,
12091221 ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } => {
1222+ log_trace ! ( logger, "Updating ChannelMonitor: channel force closed, should broadcast: {}" , should_broadcast) ;
12101223 self . lockdown_from_offchain = true ;
12111224 if * should_broadcast {
12121225 self . broadcast_latest_holder_commitment_txn ( broadcaster, logger) ;
@@ -2511,16 +2524,18 @@ mod tests {
25112524 use ln:: onchaintx:: { OnchainTxHandler , InputDescriptors } ;
25122525 use ln:: chan_utils;
25132526 use ln:: chan_utils:: { HTLCOutputInCommitment , HolderCommitmentTransaction } ;
2514- use util:: test_utils:: TestLogger ;
2527+ use util:: test_utils:: { TestLogger , TestBroadcaster , TestFeeEstimator } ;
25152528 use bitcoin:: secp256k1:: key:: { SecretKey , PublicKey } ;
25162529 use bitcoin:: secp256k1:: Secp256k1 ;
2517- use std:: sync:: Arc ;
2530+ use std:: sync:: { Arc , Mutex } ;
25182531 use chain:: keysinterface:: InMemoryChannelKeys ;
25192532
25202533 #[ test]
25212534 fn test_prune_preimages ( ) {
25222535 let secp_ctx = Secp256k1 :: new ( ) ;
25232536 let logger = Arc :: new ( TestLogger :: new ( ) ) ;
2537+ let broadcaster = Arc :: new ( TestBroadcaster { txn_broadcasted : Mutex :: new ( Vec :: new ( ) ) } ) ;
2538+ let fee_estimator = Arc :: new ( TestFeeEstimator { sat_per_kw : 253 } ) ;
25242539
25252540 let dummy_key = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
25262541 let dummy_tx = Transaction { version : 0 , lock_time : 0 , input : Vec :: new ( ) , output : Vec :: new ( ) } ;
@@ -2596,7 +2611,7 @@ mod tests {
25962611 monitor. provide_latest_counterparty_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 17 ..20 ] ) , 281474976710653 , dummy_key, & logger) ;
25972612 monitor. provide_latest_counterparty_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 18 ..20 ] ) , 281474976710652 , dummy_key, & logger) ;
25982613 for & ( ref preimage, ref hash) in preimages. iter ( ) {
2599- monitor. provide_payment_preimage ( hash, preimage) ;
2614+ monitor. provide_payment_preimage ( hash, preimage, & broadcaster , & fee_estimator , & logger ) ;
26002615 }
26012616
26022617 // Now provide a secret, pruning preimages 10-15
0 commit comments