@@ -1144,7 +1144,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1144
1144
1145
1145
/// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all
1146
1146
/// 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
+ {
1148
1152
self . payment_preimages . insert ( payment_hash. clone ( ) , payment_preimage. clone ( ) ) ;
1149
1153
}
1150
1154
@@ -1162,26 +1166,36 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1162
1166
/// itself.
1163
1167
///
1164
1168
/// 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 ,
1168
1173
{
1169
1174
if self . latest_update_id + 1 != updates. update_id {
1170
1175
panic ! ( "Attempted to apply ChannelMonitorUpdates out of order, check the update_id before passing an update to update_monitor!" ) ;
1171
1176
}
1172
1177
for update in updates. updates . iter ( ) {
1173
1178
match update {
1174
1179
ChannelMonitorUpdateStep :: LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs } => {
1180
+ log_trace ! ( logger, "Updating ChannelMonitor with latest holder commitment transaction info" ) ;
1175
1181
if self . lockdown_from_offchain { panic ! ( ) ; }
1176
1182
self . provide_latest_holder_commitment_tx_info ( commitment_tx. clone ( ) , htlc_outputs. clone ( ) ) ?
1177
1183
} ,
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
+ } ,
1180
1188
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
+ } ,
1184
1197
ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } => {
1198
+ log_trace ! ( logger, "Updating ChannelMonitor: channel force closed, should broadcast: {}" , should_broadcast) ;
1185
1199
self . lockdown_from_offchain = true ;
1186
1200
if * should_broadcast {
1187
1201
self . broadcast_latest_holder_commitment_txn ( broadcaster, logger) ;
@@ -2486,16 +2500,18 @@ mod tests {
2486
2500
use ln:: onchaintx:: { OnchainTxHandler , InputDescriptors } ;
2487
2501
use ln:: chan_utils;
2488
2502
use ln:: chan_utils:: { HTLCOutputInCommitment , HolderCommitmentTransaction } ;
2489
- use util:: test_utils:: TestLogger ;
2503
+ use util:: test_utils:: { TestLogger , TestBroadcaster , TestFeeEstimator } ;
2490
2504
use bitcoin:: secp256k1:: key:: { SecretKey , PublicKey } ;
2491
2505
use bitcoin:: secp256k1:: Secp256k1 ;
2492
- use std:: sync:: Arc ;
2506
+ use std:: sync:: { Arc , Mutex } ;
2493
2507
use chain:: keysinterface:: InMemoryChannelKeys ;
2494
2508
2495
2509
#[ test]
2496
2510
fn test_prune_preimages ( ) {
2497
2511
let secp_ctx = Secp256k1 :: new ( ) ;
2498
2512
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 } ) ;
2499
2515
2500
2516
let dummy_key = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
2501
2517
let dummy_tx = Transaction { version : 0 , lock_time : 0 , input : Vec :: new ( ) , output : Vec :: new ( ) } ;
@@ -2571,7 +2587,7 @@ mod tests {
2571
2587
monitor. provide_latest_counterparty_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 17 ..20 ] ) , 281474976710653 , dummy_key, & logger) ;
2572
2588
monitor. provide_latest_counterparty_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 18 ..20 ] ) , 281474976710652 , dummy_key, & logger) ;
2573
2589
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 ) ;
2575
2591
}
2576
2592
2577
2593
// Now provide a secret, pruning preimages 10-15
0 commit comments