@@ -1396,8 +1396,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1396
1396
/// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
1397
1397
/// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
1398
1398
/// have been registered.
1399
- pub fn load_outputs_to_watch < F : Deref , L : Deref > ( & self , filter : & F , logger : & L )
1400
- where
1399
+ pub fn load_outputs_to_watch < F : Deref , L : Deref > ( & self , filter : & F , logger : & L )
1400
+ where
1401
1401
F :: Target : chain:: Filter , L :: Target : Logger ,
1402
1402
{
1403
1403
let lock = self . inner . lock ( ) . unwrap ( ) ;
@@ -1542,28 +1542,30 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1542
1542
self . inner . lock ( ) . unwrap ( ) . counterparty_node_id
1543
1543
}
1544
1544
1545
- /// Used by [`ChannelManager`] deserialization to broadcast the latest holder state if its copy
1546
- /// of the channel state was out-of-date.
1547
- ///
1548
- /// You may also use this to broadcast the latest local commitment transaction, either because
1545
+ /// You may use this to broadcast the latest local commitment transaction, either because
1549
1546
/// a monitor update failed or because we've fallen behind (i.e. we've received proof that our
1550
1547
/// counterparty side knows a revocation secret we gave them that they shouldn't know).
1551
1548
///
1552
- /// Broadcasting these transactions in the second case is UNSAFE, as they allow counterparty
1549
+ /// Broadcasting these transactions in this manner is UNSAFE, as they allow counterparty
1553
1550
/// side to punish you. Nevertheless you may want to broadcast them if counterparty doesn't
1554
1551
/// close channel with their commitment transaction after a substantial amount of time. Best
1555
1552
/// may be to contact the other node operator out-of-band to coordinate other options available
1556
1553
/// to you.
1557
- ///
1558
- /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1559
- pub fn get_latest_holder_commitment_txn < L : Deref > ( & self , logger : & L ) -> Vec < Transaction >
1560
- where L :: Target : Logger {
1554
+ pub fn broadcast_latest_holder_commitment_txn < B : Deref , F : Deref , L : Deref > (
1555
+ & self , broadcaster : & B , fee_estimator : & F , logger : & L
1556
+ )
1557
+ where
1558
+ B :: Target : BroadcasterInterface ,
1559
+ F :: Target : FeeEstimator ,
1560
+ L :: Target : Logger
1561
+ {
1561
1562
let mut inner = self . inner . lock ( ) . unwrap ( ) ;
1563
+ let fee_estimator = LowerBoundedFeeEstimator :: new ( & * * fee_estimator) ;
1562
1564
let logger = WithChannelMonitor :: from_impl ( logger, & * inner) ;
1563
- inner. get_latest_holder_commitment_txn ( & logger)
1565
+ inner. queue_latest_holder_commitment_txn_for_broadcast ( broadcaster , & fee_estimator , & logger) ;
1564
1566
}
1565
1567
1566
- /// Unsafe test-only version of get_latest_holder_commitment_txn used by our test framework
1568
+ /// Unsafe test-only version of `broadcast_latest_holder_commitment_txn` used by our test framework
1567
1569
/// to bypass HolderCommitmentTransaction state update lockdown after signature and generate
1568
1570
/// revoked commitment transaction.
1569
1571
#[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
@@ -2835,7 +2837,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2835
2837
} else if !self . holder_tx_signed {
2836
2838
log_error ! ( logger, "WARNING: You have a potentially-unsafe holder commitment transaction available to broadcast" ) ;
2837
2839
log_error ! ( logger, " in channel monitor for channel {}!" , & self . funding_info. 0 . to_channel_id( ) ) ;
2838
- log_error ! ( logger, " Read the docs for ChannelMonitor::get_latest_holder_commitment_txn and take manual action!" ) ;
2840
+ log_error ! ( logger, " Read the docs for ChannelMonitor::broadcast_latest_holder_commitment_txn and take manual action!" ) ;
2839
2841
} else {
2840
2842
// If we generated a MonitorEvent::HolderForceClosed, the ChannelManager
2841
2843
// will still give us a ChannelForceClosed event with !should_broadcast, but we
@@ -3460,45 +3462,6 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3460
3462
}
3461
3463
}
3462
3464
3463
- fn get_latest_holder_commitment_txn < L : Deref > (
3464
- & mut self , logger : & WithChannelMonitor < L > ,
3465
- ) -> Vec < Transaction > where L :: Target : Logger {
3466
- log_debug ! ( logger, "Getting signed latest holder commitment transaction!" ) ;
3467
- self . holder_tx_signed = true ;
3468
- let commitment_tx = self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) ;
3469
- let txid = commitment_tx. txid ( ) ;
3470
- let mut holder_transactions = vec ! [ commitment_tx] ;
3471
- // When anchor outputs are present, the HTLC transactions are only valid once the commitment
3472
- // transaction confirms.
3473
- if self . onchain_tx_handler . channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
3474
- return holder_transactions;
3475
- }
3476
- for htlc in self . current_holder_commitment_tx . htlc_outputs . iter ( ) {
3477
- if let Some ( vout) = htlc. 0 . transaction_output_index {
3478
- let preimage = if !htlc. 0 . offered {
3479
- if let Some ( preimage) = self . payment_preimages . get ( & htlc. 0 . payment_hash ) { Some ( preimage. clone ( ) ) } else {
3480
- // We can't build an HTLC-Success transaction without the preimage
3481
- continue ;
3482
- }
3483
- } else if htlc. 0 . cltv_expiry > self . best_block . height ( ) + 1 {
3484
- // Don't broadcast HTLC-Timeout transactions immediately as they don't meet the
3485
- // current locktime requirements on-chain. We will broadcast them in
3486
- // `block_confirmed` when `should_broadcast_holder_commitment_txn` returns true.
3487
- // Note that we add + 1 as transactions are broadcastable when they can be
3488
- // confirmed in the next block.
3489
- continue ;
3490
- } else { None } ;
3491
- if let Some ( htlc_tx) = self . onchain_tx_handler . get_fully_signed_htlc_tx (
3492
- & :: bitcoin:: OutPoint { txid, vout } , & preimage) {
3493
- holder_transactions. push ( htlc_tx) ;
3494
- }
3495
- }
3496
- }
3497
- // We throw away the generated waiting_first_conf data as we aren't (yet) confirmed and we don't actually know what the caller wants to do.
3498
- // The data will be re-generated and tracked in check_spend_holder_transaction if we get a confirmation.
3499
- holder_transactions
3500
- }
3501
-
3502
3465
#[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
3503
3466
/// Note that this includes possibly-locktimed-in-the-future transactions!
3504
3467
fn unsafe_get_latest_holder_commitment_txn < L : Deref > (
0 commit comments