@@ -1162,7 +1162,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11621162
11631163 /// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all
11641164 /// commitment_tx_infos which contain the payment hash have been revoked.
1165- pub ( crate ) fn provide_payment_preimage ( & mut self , payment_hash : & PaymentHash , payment_preimage : & PaymentPreimage ) {
1165+ 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 )
1166+ where B :: Target : BroadcasterInterface ,
1167+ F :: Target : FeeEstimator ,
1168+ L :: Target : Logger ,
1169+ {
11661170 self . payment_preimages . insert ( payment_hash. clone ( ) , payment_preimage. clone ( ) ) ;
11671171 }
11681172
@@ -1180,9 +1184,10 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11801184 /// itself.
11811185 ///
11821186 /// panics if the given update is not the next update by update_id.
1183- pub fn update_monitor < B : Deref , L : Deref > ( & mut self , updates : & ChannelMonitorUpdate , broadcaster : & B , logger : & L ) -> Result < ( ) , MonitorUpdateError >
1184- where B :: Target : BroadcasterInterface ,
1185- L :: Target : Logger ,
1187+ pub fn update_monitor < B : Deref , F : Deref , L : Deref > ( & mut self , updates : & ChannelMonitorUpdate , broadcaster : & B , fee_estimator : & F , logger : & L ) -> Result < ( ) , MonitorUpdateError >
1188+ where B :: Target : BroadcasterInterface ,
1189+ F :: Target : FeeEstimator ,
1190+ L :: Target : Logger ,
11861191 {
11871192 // ChannelMonitor updates may be applied after force close if we receive a
11881193 // preimage for a broadcasted commitment transaction HTLC output that we'd
@@ -1201,16 +1206,24 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
12011206 for update in updates. updates . iter ( ) {
12021207 match update {
12031208 ChannelMonitorUpdateStep :: LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs } => {
1209+ log_trace ! ( logger, "Updating ChannelMonitor with latest holder commitment transaction info" ) ;
12041210 if self . lockdown_from_offchain { panic ! ( ) ; }
12051211 self . provide_latest_holder_commitment_tx_info ( commitment_tx. clone ( ) , htlc_outputs. clone ( ) ) ?
12061212 } ,
1207- ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point } =>
1208- self . provide_latest_counterparty_commitment_tx_info ( & unsigned_commitment_tx, htlc_outputs. clone ( ) , * commitment_number, * their_revocation_point, logger) ,
1209- ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage } =>
1210- self . provide_payment_preimage ( & PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 [ ..] ) . into_inner ( ) ) , & payment_preimage) ,
1211- ChannelMonitorUpdateStep :: CommitmentSecret { idx, secret } =>
1212- self . provide_secret ( * idx, * secret) ?,
1213+ ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point } => {
1214+ log_trace ! ( logger, "Updating ChannelMonitor with latest counterparty commitment transaction info" ) ;
1215+ self . provide_latest_counterparty_commitment_tx_info ( & unsigned_commitment_tx, htlc_outputs. clone ( ) , * commitment_number, * their_revocation_point, logger)
1216+ } ,
1217+ ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage } => {
1218+ log_trace ! ( logger, "Updating ChannelMonitor with payment preimage" ) ;
1219+ self . provide_payment_preimage ( & PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 [ ..] ) . into_inner ( ) ) , & payment_preimage, broadcaster, fee_estimator, logger)
1220+ } ,
1221+ ChannelMonitorUpdateStep :: CommitmentSecret { idx, secret } => {
1222+ log_trace ! ( logger, "Updating ChannelMonitor with commitment secret" ) ;
1223+ self . provide_secret ( * idx, * secret) ?
1224+ } ,
12131225 ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } => {
1226+ log_trace ! ( logger, "Updating ChannelMonitor: channel force closed, should broadcast: {}" , should_broadcast) ;
12141227 self . lockdown_from_offchain = true ;
12151228 if * should_broadcast {
12161229 self . broadcast_latest_holder_commitment_txn ( broadcaster, logger) ;
@@ -2515,16 +2528,18 @@ mod tests {
25152528 use ln:: onchaintx:: { OnchainTxHandler , InputDescriptors } ;
25162529 use ln:: chan_utils;
25172530 use ln:: chan_utils:: { HTLCOutputInCommitment , HolderCommitmentTransaction } ;
2518- use util:: test_utils:: TestLogger ;
2531+ use util:: test_utils:: { TestLogger , TestBroadcaster , TestFeeEstimator } ;
25192532 use bitcoin:: secp256k1:: key:: { SecretKey , PublicKey } ;
25202533 use bitcoin:: secp256k1:: Secp256k1 ;
2521- use std:: sync:: Arc ;
2534+ use std:: sync:: { Arc , Mutex } ;
25222535 use chain:: keysinterface:: InMemoryChannelKeys ;
25232536
25242537 #[ test]
25252538 fn test_prune_preimages ( ) {
25262539 let secp_ctx = Secp256k1 :: new ( ) ;
25272540 let logger = Arc :: new ( TestLogger :: new ( ) ) ;
2541+ let broadcaster = Arc :: new ( TestBroadcaster { txn_broadcasted : Mutex :: new ( Vec :: new ( ) ) } ) ;
2542+ let fee_estimator = Arc :: new ( TestFeeEstimator { sat_per_kw : 253 } ) ;
25282543
25292544 let dummy_key = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
25302545 let dummy_tx = Transaction { version : 0 , lock_time : 0 , input : Vec :: new ( ) , output : Vec :: new ( ) } ;
@@ -2600,7 +2615,7 @@ mod tests {
26002615 monitor. provide_latest_counterparty_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 17 ..20 ] ) , 281474976710653 , dummy_key, & logger) ;
26012616 monitor. provide_latest_counterparty_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 18 ..20 ] ) , 281474976710652 , dummy_key, & logger) ;
26022617 for & ( ref preimage, ref hash) in preimages. iter ( ) {
2603- monitor. provide_payment_preimage ( hash, preimage) ;
2618+ monitor. provide_payment_preimage ( hash, preimage, & broadcaster , & fee_estimator , & logger ) ;
26042619 }
26052620
26062621 // Now provide a secret, pruning preimages 10-15
0 commit comments