@@ -422,22 +422,18 @@ pub(super) struct Channel<Signer: Sign> {
422
422
monitor_pending_forwards : Vec < ( PendingHTLCInfo , u64 ) > ,
423
423
monitor_pending_failures : Vec < ( HTLCSource , PaymentHash , HTLCFailReason ) > ,
424
424
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.
428
426
//
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.
436
431
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.
441
437
holding_cell_update_fee : Option < u32 > ,
442
438
next_holder_htlc_id : u64 ,
443
439
next_counterparty_htlc_id : u64 ,
@@ -3876,6 +3872,8 @@ impl<Signer: Sign> Channel<Signer> {
3876
3872
// more dust balance if the feerate increases when we have several HTLCs pending
3877
3873
// which are near the dust limit.
3878
3874
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.
3879
3877
if let Some ( ( feerate, _) ) = self . pending_update_fee {
3880
3878
feerate_per_kw = cmp:: max ( feerate_per_kw, feerate) ;
3881
3879
}
@@ -5124,9 +5122,10 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
5124
5122
if self . is_outbound ( ) {
5125
5123
self . pending_update_fee . map ( |( a, _) | a) . write ( writer) ?;
5126
5124
} 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.
5128
5125
Some ( feerate) . write ( writer) ?;
5129
5126
} else {
5127
+ // As for inbound HTLCs, if the update was only announced and never committed in a
5128
+ // commitment_signed, drop it.
5130
5129
None :: < u32 > . write ( writer) ?;
5131
5130
}
5132
5131
self . holding_cell_update_fee . write ( writer) ?;
0 commit comments