@@ -1159,7 +1159,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1159
1159
1160
1160
/// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all
1161
1161
/// 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
+ {
1163
1167
self . payment_preimages . insert ( payment_hash. clone ( ) , payment_preimage. clone ( ) ) ;
1164
1168
}
1165
1169
@@ -1177,9 +1181,10 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1177
1181
/// itself.
1178
1182
///
1179
1183
/// 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 ,
1183
1188
{
1184
1189
// ChannelMonitor updates may be applied after force close if we receive a
1185
1190
// preimage for a broadcasted commitment transaction HTLC output that we'd
@@ -1197,16 +1202,24 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1197
1202
for update in updates. updates . iter ( ) {
1198
1203
match update {
1199
1204
ChannelMonitorUpdateStep :: LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs } => {
1205
+ log_trace ! ( logger, "Updating ChannelMonitor with latest holder commitment transaction info" ) ;
1200
1206
if self . lockdown_from_offchain { panic ! ( ) ; }
1201
1207
self . provide_latest_holder_commitment_tx_info ( commitment_tx. clone ( ) , htlc_outputs. clone ( ) ) ?
1202
1208
} ,
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
+ } ,
1209
1221
ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } => {
1222
+ log_trace ! ( logger, "Updating ChannelMonitor: channel force closed, should broadcast: {}" , should_broadcast) ;
1210
1223
self . lockdown_from_offchain = true ;
1211
1224
if * should_broadcast {
1212
1225
self . broadcast_latest_holder_commitment_txn ( broadcaster, logger) ;
@@ -2511,16 +2524,18 @@ mod tests {
2511
2524
use ln:: onchaintx:: { OnchainTxHandler , InputDescriptors } ;
2512
2525
use ln:: chan_utils;
2513
2526
use ln:: chan_utils:: { HTLCOutputInCommitment , HolderCommitmentTransaction } ;
2514
- use util:: test_utils:: TestLogger ;
2527
+ use util:: test_utils:: { TestLogger , TestBroadcaster , TestFeeEstimator } ;
2515
2528
use bitcoin:: secp256k1:: key:: { SecretKey , PublicKey } ;
2516
2529
use bitcoin:: secp256k1:: Secp256k1 ;
2517
- use std:: sync:: Arc ;
2530
+ use std:: sync:: { Arc , Mutex } ;
2518
2531
use chain:: keysinterface:: InMemoryChannelKeys ;
2519
2532
2520
2533
#[ test]
2521
2534
fn test_prune_preimages ( ) {
2522
2535
let secp_ctx = Secp256k1 :: new ( ) ;
2523
2536
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 } ) ;
2524
2539
2525
2540
let dummy_key = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
2526
2541
let dummy_tx = Transaction { version : 0 , lock_time : 0 , input : Vec :: new ( ) , output : Vec :: new ( ) } ;
@@ -2596,7 +2611,7 @@ mod tests {
2596
2611
monitor. provide_latest_counterparty_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 17 ..20 ] ) , 281474976710653 , dummy_key, & logger) ;
2597
2612
monitor. provide_latest_counterparty_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 18 ..20 ] ) , 281474976710652 , dummy_key, & logger) ;
2598
2613
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 ) ;
2600
2615
}
2601
2616
2602
2617
// Now provide a secret, pruning preimages 10-15
0 commit comments