@@ -422,22 +422,18 @@ pub(super) struct Channel<Signer: Sign> {
422422 monitor_pending_forwards : Vec < ( PendingHTLCInfo , u64 ) > ,
423423 monitor_pending_failures : Vec < ( HTLCSource , PaymentHash , HTLCFailReason ) > ,
424424
425- // pending_update_fee is filled when sending and receiving update_fee
426- // For outbound channel, feerate_per_kw is updated with the value from
427- // pending_update_fee when revoke_and_ack is received
425+ // pending_update_fee is filled when sending and receiving update_fee.
428426 //
429- // For inbound channel, feerate_per_kw is updated when it receives
430- // commitment_signed and revoke_and_ack is generated
431- // The pending value is kept when another pair of update_fee and commitment_signed
432- // is received during AwaitingRemoteRevoke and relieved when the expected
433- // revoke_and_ack is received and new commitment_signed is generated to be
434- // sent to the funder. Otherwise, the pending value is removed when receiving
435- // commitment_signed.
427+ // Because it follows the same commitment flow as HTLCs, `FeeUpdateState` is either `Outbound`
428+ // or matches a subset of the `InboundHTLCOutput` variants. It is then updated/used when
429+ // generating new commitment transactions with exactly the same criteria as inbound/outbound
430+ // HTLCs with similar state.
436431 pending_update_fee : Option < ( u32 , FeeUpdateState ) > ,
437- // update_fee() during ChannelState::AwaitingRemoteRevoke is hold in
438- // holdina_cell_update_fee then moved to pending_udpate_fee when revoke_and_ack
439- // is received. holding_cell_update_fee is updated when there are additional
440- // update_fee() during ChannelState::AwaitingRemoteRevoke.
432+ // If a `send_update_fee()` call is made with ChannelState::AwaitingRemoteRevoke set, we place
433+ // it here instead of `pending_update_fee` in the same way as we place outbound HTLC updates in
434+ // `holding_cell_htlc_updates` instead of `pending_outbound_htlcs`. It is released into
435+ // `pending_update_fee` with the same criteria as outbound HTLC updates but can be updated by
436+ // further `send_update_fee` calls, dropping the previous holding cell update entirely.
441437 holding_cell_update_fee : Option < u32 > ,
442438 next_holder_htlc_id : u64 ,
443439 next_counterparty_htlc_id : u64 ,
@@ -3876,6 +3872,8 @@ impl<Signer: Sign> Channel<Signer> {
38763872 // more dust balance if the feerate increases when we have several HTLCs pending
38773873 // which are near the dust limit.
38783874 let mut feerate_per_kw = self . feerate_per_kw ;
3875+ // If there's a pending update fee, use it to ensure we aren't under-estimating
3876+ // potential feerate updates coming soon.
38793877 if let Some ( ( feerate, _) ) = self . pending_update_fee {
38803878 feerate_per_kw = cmp:: max ( feerate_per_kw, feerate) ;
38813879 }
@@ -5124,9 +5122,10 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
51245122 if self . is_outbound ( ) {
51255123 self . pending_update_fee . map ( |( a, _) | a) . write ( writer) ?;
51265124 } else if let Some ( ( feerate, FeeUpdateState :: AwaitingRemoteRevokeToAnnounce ) ) = self . pending_update_fee {
5127- // As for inbound HTLCs, if the update was only announced and never committed, drop it.
51285125 Some ( feerate) . write ( writer) ?;
51295126 } else {
5127+ // As for inbound HTLCs, if the update was only announced and never committed in a
5128+ // commitment_signed, drop it.
51305129 None :: < u32 > . write ( writer) ?;
51315130 }
51325131 self . holding_cell_update_fee . write ( writer) ?;
0 commit comments