@@ -3251,7 +3251,7 @@ impl<Signer: Sign> Channel<Signer> {
32513251 return Ok ( ( None , htlcs_to_fail) ) ;
32523252 }
32533253 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)
32553255 } else {
32563256 None
32573257 } ;
@@ -3551,12 +3551,22 @@ impl<Signer: Sign> Channel<Signer> {
35513551 }
35523552 }
35533553
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+
35543562 /// Adds a pending update to this channel. See the doc for send_htlc for
35553563 /// further details on the optionness of the return value.
35563564 /// If our balance is too low to cover the cost of the next commitment transaction at the
35573565 /// 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 {
35603570 if !self . is_outbound ( ) {
35613571 panic ! ( "Cannot send fee from inbound channel" ) ;
35623572 }
@@ -3593,6 +3603,10 @@ impl<Signer: Sign> Channel<Signer> {
35933603 }
35943604
35953605 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 {
35963610 self . holding_cell_update_fee = Some ( feerate_per_kw) ;
35973611 return None ;
35983612 }
@@ -3606,16 +3620,6 @@ impl<Signer: Sign> Channel<Signer> {
36063620 } )
36073621 }
36083622
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-
36193623 /// Removes any uncommitted inbound HTLCs and resets the state of uncommitted outbound HTLC
36203624 /// updates, to be used on peer disconnection. After this, update_*_htlc messages need to be
36213625 /// resent.
@@ -5502,7 +5506,7 @@ impl<Signer: Sign> Channel<Signer> {
55025506 }
55035507
55045508 /// 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.
55065510 ///
55075511 /// This returns an optional UpdateAddHTLC as we may be in a state where we cannot add HTLCs on
55085512 /// the wire:
@@ -5513,10 +5517,10 @@ impl<Signer: Sign> Channel<Signer> {
55135517 /// we may not yet have sent the previous commitment update messages and will need to
55145518 /// regenerate them.
55155519 ///
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.
55185522 ///
5519- /// If an Err is returned, it's a ChannelError::Ignore!
5523+ /// ` Err`s will only be [` ChannelError::Ignore`].
55205524 fn send_htlc < L : Deref > ( & mut self , amount_msat : u64 , payment_hash : PaymentHash , cltv_expiry : u32 , source : HTLCSource ,
55215525 onion_routing_packet : msgs:: OnionPacket , mut force_holding_cell : bool , logger : & L )
55225526 -> Result < Option < msgs:: UpdateAddHTLC > , ChannelError > where L :: Target : Logger {
@@ -5652,41 +5656,6 @@ impl<Signer: Sign> Channel<Signer> {
56525656 Ok ( Some ( res) )
56535657 }
56545658
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- }
56905659 /// Only fails in case of bad keys
56915660 fn send_commitment_no_status_check < L : Deref > ( & mut self , logger : & L ) -> Result < ( msgs:: CommitmentSigned , ChannelMonitorUpdate ) , ChannelError > where L :: Target : Logger {
56925661 log_trace ! ( logger, "Updating HTLC state for a newly-sent commitment_signed..." ) ;
@@ -5809,8 +5778,9 @@ impl<Signer: Sign> Channel<Signer> {
58095778
58105779 /// Adds a pending outbound HTLC to this channel, and creates a signed commitment transaction
58115780 /// 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.
58145784 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 {
58155785 match self . send_htlc ( amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, false , logger) ? {
58165786 Some ( update_add_htlc) => {
0 commit comments