@@ -1162,7 +1162,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1162
1162
1163
1163
/// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all
1164
1164
/// 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
+ {
1166
1170
self . payment_preimages . insert ( payment_hash. clone ( ) , payment_preimage. clone ( ) ) ;
1167
1171
}
1168
1172
@@ -1180,9 +1184,10 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1180
1184
/// itself.
1181
1185
///
1182
1186
/// 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 ,
1186
1191
{
1187
1192
// ChannelMonitor updates may be applied after force close if we receive a
1188
1193
// preimage for a broadcasted commitment transaction HTLC output that we'd
@@ -1201,16 +1206,24 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1201
1206
for update in updates. updates . iter ( ) {
1202
1207
match update {
1203
1208
ChannelMonitorUpdateStep :: LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs } => {
1209
+ log_trace ! ( logger, "Updating ChannelMonitor with latest holder commitment transaction info" ) ;
1204
1210
if self . lockdown_from_offchain { panic ! ( ) ; }
1205
1211
self . provide_latest_holder_commitment_tx_info ( commitment_tx. clone ( ) , htlc_outputs. clone ( ) ) ?
1206
1212
} ,
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
+ } ,
1213
1225
ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } => {
1226
+ log_trace ! ( logger, "Updating ChannelMonitor: channel force closed, should broadcast: {}" , should_broadcast) ;
1214
1227
self . lockdown_from_offchain = true ;
1215
1228
if * should_broadcast {
1216
1229
self . broadcast_latest_holder_commitment_txn ( broadcaster, logger) ;
@@ -2515,16 +2528,18 @@ mod tests {
2515
2528
use ln:: onchaintx:: { OnchainTxHandler , InputDescriptors } ;
2516
2529
use ln:: chan_utils;
2517
2530
use ln:: chan_utils:: { HTLCOutputInCommitment , HolderCommitmentTransaction } ;
2518
- use util:: test_utils:: TestLogger ;
2531
+ use util:: test_utils:: { TestLogger , TestBroadcaster , TestFeeEstimator } ;
2519
2532
use bitcoin:: secp256k1:: key:: { SecretKey , PublicKey } ;
2520
2533
use bitcoin:: secp256k1:: Secp256k1 ;
2521
- use std:: sync:: Arc ;
2534
+ use std:: sync:: { Arc , Mutex } ;
2522
2535
use chain:: keysinterface:: InMemoryChannelKeys ;
2523
2536
2524
2537
#[ test]
2525
2538
fn test_prune_preimages ( ) {
2526
2539
let secp_ctx = Secp256k1 :: new ( ) ;
2527
2540
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 } ) ;
2528
2543
2529
2544
let dummy_key = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
2530
2545
let dummy_tx = Transaction { version : 0 , lock_time : 0 , input : Vec :: new ( ) , output : Vec :: new ( ) } ;
@@ -2600,7 +2615,7 @@ mod tests {
2600
2615
monitor. provide_latest_counterparty_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 17 ..20 ] ) , 281474976710653 , dummy_key, & logger) ;
2601
2616
monitor. provide_latest_counterparty_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 18 ..20 ] ) , 281474976710652 , dummy_key, & logger) ;
2602
2617
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 ) ;
2604
2619
}
2605
2620
2606
2621
// Now provide a secret, pruning preimages 10-15
0 commit comments