@@ -3251,7 +3251,7 @@ impl<Signer: Sign> Channel<Signer> {
3251
3251
return Ok ( ( None , htlcs_to_fail) ) ;
3252
3252
}
3253
3253
let update_fee = if let Some ( feerate) = self . holding_cell_update_fee . take ( ) {
3254
- self . send_update_fee ( feerate, logger)
3254
+ self . send_update_fee ( feerate, false , logger)
3255
3255
} else {
3256
3256
None
3257
3257
} ;
@@ -3551,12 +3551,22 @@ impl<Signer: Sign> Channel<Signer> {
3551
3551
}
3552
3552
}
3553
3553
3554
+ /// Queues up an outbound update fee by placing it in the holding cell. You should call
3555
+ /// [`Self::maybe_free_holding_cell_htlcs`] in order to actually generate and send the
3556
+ /// commitment update.
3557
+ pub fn queue_update_fee < L : Deref > ( & mut self , feerate_per_kw : u32 , logger : & L ) where L :: Target : Logger {
3558
+ let msg_opt = self . send_update_fee ( feerate_per_kw, true , logger) ;
3559
+ assert ! ( msg_opt. is_none( ) , "We forced holding cell?" ) ;
3560
+ }
3561
+
3554
3562
/// Adds a pending update to this channel. See the doc for send_htlc for
3555
3563
/// further details on the optionness of the return value.
3556
3564
/// If our balance is too low to cover the cost of the next commitment transaction at the
3557
3565
/// new feerate, the update is cancelled.
3558
- /// You MUST call send_commitment prior to any other calls on this Channel
3559
- fn send_update_fee < L : Deref > ( & mut self , feerate_per_kw : u32 , logger : & L ) -> Option < msgs:: UpdateFee > where L :: Target : Logger {
3566
+ ///
3567
+ /// You MUST call [`Self::send_commitment_no_state_update`] prior to any other calls on this
3568
+ /// [`Channel`] if `force_holding_cell` is false.
3569
+ fn send_update_fee < L : Deref > ( & mut self , feerate_per_kw : u32 , mut force_holding_cell : bool , logger : & L ) -> Option < msgs:: UpdateFee > where L :: Target : Logger {
3560
3570
if !self . is_outbound ( ) {
3561
3571
panic ! ( "Cannot send fee from inbound channel" ) ;
3562
3572
}
@@ -3593,6 +3603,10 @@ impl<Signer: Sign> Channel<Signer> {
3593
3603
}
3594
3604
3595
3605
if ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 | ChannelState :: MonitorUpdateInProgress as u32 ) ) != 0 {
3606
+ force_holding_cell = true ;
3607
+ }
3608
+
3609
+ if force_holding_cell {
3596
3610
self . holding_cell_update_fee = Some ( feerate_per_kw) ;
3597
3611
return None ;
3598
3612
}
@@ -3606,16 +3620,6 @@ impl<Signer: Sign> Channel<Signer> {
3606
3620
} )
3607
3621
}
3608
3622
3609
- pub fn send_update_fee_and_commit < L : Deref > ( & mut self , feerate_per_kw : u32 , logger : & L ) -> Result < Option < ( msgs:: UpdateFee , msgs:: CommitmentSigned , ChannelMonitorUpdate ) > , ChannelError > where L :: Target : Logger {
3610
- match self . send_update_fee ( feerate_per_kw, logger) {
3611
- Some ( update_fee) => {
3612
- let ( commitment_signed, monitor_update) = self . send_commitment_no_status_check ( logger) ?;
3613
- Ok ( Some ( ( update_fee, commitment_signed, monitor_update) ) )
3614
- } ,
3615
- None => Ok ( None )
3616
- }
3617
- }
3618
-
3619
3623
/// Removes any uncommitted inbound HTLCs and resets the state of uncommitted outbound HTLC
3620
3624
/// updates, to be used on peer disconnection. After this, update_*_htlc messages need to be
3621
3625
/// resent.
@@ -5502,7 +5506,7 @@ impl<Signer: Sign> Channel<Signer> {
5502
5506
}
5503
5507
5504
5508
/// Adds a pending outbound HTLC to this channel, note that you probably want
5505
- /// send_htlc_and_commit instead cause you'll want both messages at once.
5509
+ /// [`Self:: send_htlc_and_commit`] instead cause you'll want both messages at once.
5506
5510
///
5507
5511
/// This returns an optional UpdateAddHTLC as we may be in a state where we cannot add HTLCs on
5508
5512
/// the wire:
@@ -5513,10 +5517,10 @@ impl<Signer: Sign> Channel<Signer> {
5513
5517
/// we may not yet have sent the previous commitment update messages and will need to
5514
5518
/// regenerate them.
5515
5519
///
5516
- /// You MUST call send_commitment prior to calling any other methods on this Channel if
5517
- /// `force_holding_cell` is false.
5520
+ /// You MUST call [`Self::send_commitment_no_state_update`] prior to calling any other methods
5521
+ /// on this [`Channel`] if `force_holding_cell` is false.
5518
5522
///
5519
- /// If an Err is returned, it's a ChannelError::Ignore!
5523
+ /// ` Err`s will only be [` ChannelError::Ignore`].
5520
5524
fn send_htlc < L : Deref > ( & mut self , amount_msat : u64 , payment_hash : PaymentHash , cltv_expiry : u32 , source : HTLCSource ,
5521
5525
onion_routing_packet : msgs:: OnionPacket , mut force_holding_cell : bool , logger : & L )
5522
5526
-> Result < Option < msgs:: UpdateAddHTLC > , ChannelError > where L :: Target : Logger {
@@ -5652,41 +5656,6 @@ impl<Signer: Sign> Channel<Signer> {
5652
5656
Ok ( Some ( res) )
5653
5657
}
5654
5658
5655
- /// Creates a signed commitment transaction to send to the remote peer.
5656
- /// Always returns a ChannelError::Close if an immediately-preceding (read: the
5657
- /// last call to this Channel) send_htlc returned Ok(Some(_)) and there is an Err.
5658
- /// May panic if called except immediately after a successful, Ok(Some(_))-returning send_htlc.
5659
- pub fn send_commitment < L : Deref > ( & mut self , logger : & L ) -> Result < ( msgs:: CommitmentSigned , ChannelMonitorUpdate ) , ChannelError > where L :: Target : Logger {
5660
- if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
5661
- panic ! ( "Cannot create commitment tx until channel is fully established" ) ;
5662
- }
5663
- if ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) ) == ( ChannelState :: AwaitingRemoteRevoke as u32 ) {
5664
- panic ! ( "Cannot create commitment tx until remote revokes their previous commitment" ) ;
5665
- }
5666
- if ( self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) ) == ( ChannelState :: PeerDisconnected as u32 ) {
5667
- panic ! ( "Cannot create commitment tx while disconnected, as send_htlc will have returned an Err so a send_commitment precondition has been violated" ) ;
5668
- }
5669
- if ( self . channel_state & ( ChannelState :: MonitorUpdateInProgress as u32 ) ) == ( ChannelState :: MonitorUpdateInProgress as u32 ) {
5670
- panic ! ( "Cannot create commitment tx while awaiting monitor update unfreeze, as send_htlc will have returned an Err so a send_commitment precondition has been violated" ) ;
5671
- }
5672
- let mut have_updates = self . is_outbound ( ) && self . pending_update_fee . is_some ( ) ;
5673
- for htlc in self . pending_outbound_htlcs . iter ( ) {
5674
- if let OutboundHTLCState :: LocalAnnounced ( _) = htlc. state {
5675
- have_updates = true ;
5676
- }
5677
- if have_updates { break ; }
5678
- }
5679
- for htlc in self . pending_inbound_htlcs . iter ( ) {
5680
- if let InboundHTLCState :: LocalRemoved ( _) = htlc. state {
5681
- have_updates = true ;
5682
- }
5683
- if have_updates { break ; }
5684
- }
5685
- if !have_updates {
5686
- panic ! ( "Cannot create commitment tx until we have some updates to send" ) ;
5687
- }
5688
- self . send_commitment_no_status_check ( logger)
5689
- }
5690
5659
/// Only fails in case of bad keys
5691
5660
fn send_commitment_no_status_check < L : Deref > ( & mut self , logger : & L ) -> Result < ( msgs:: CommitmentSigned , ChannelMonitorUpdate ) , ChannelError > where L :: Target : Logger {
5692
5661
log_trace ! ( logger, "Updating HTLC state for a newly-sent commitment_signed..." ) ;
@@ -5809,8 +5778,9 @@ impl<Signer: Sign> Channel<Signer> {
5809
5778
5810
5779
/// Adds a pending outbound HTLC to this channel, and creates a signed commitment transaction
5811
5780
/// to send to the remote peer in one go.
5812
- /// Shorthand for calling send_htlc() followed by send_commitment(), see docs on those for
5813
- /// more info.
5781
+ ///
5782
+ /// Shorthand for calling [`Self::send_htlc`] followed by a commitment update, see docs on
5783
+ /// [`Self::send_htlc`] and [`Self::send_commitment_no_state_update`] for more info.
5814
5784
pub fn send_htlc_and_commit < L : Deref > ( & mut self , amount_msat : u64 , payment_hash : PaymentHash , cltv_expiry : u32 , source : HTLCSource , onion_routing_packet : msgs:: OnionPacket , logger : & L ) -> Result < Option < ( msgs:: UpdateAddHTLC , msgs:: CommitmentSigned , ChannelMonitorUpdate ) > , ChannelError > where L :: Target : Logger {
5815
5785
match self . send_htlc ( amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, false , logger) ? {
5816
5786
Some ( update_add_htlc) => {
0 commit comments