You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve prediction of commitment stats in validate_update_add_htlc
`ChannelContext::get_pending_htlc_stats` predicts that the set of HTLCs
on the next commitment will be all the HTLCs in
`ChannelContext.pending_inbound_htlcs`, and
`ChannelContext.pending_outbound_htlcs`, as well as all the outbound
HTLC adds in the holding cell.
This is an overestimate:
* Outbound HTLC removals which have been ACK'ed by the counterparty will
certainly not be present in any *next* commitment, even though they
remain in `pending_outbound_htlcs`.
* Outbound HTLCs in the `RemoteRemoved` state, will not be present in
the next *local* commitment.
* Outbound HTLCs in the `LocalAnnounced` state have no guarantee that
they were received by the counterparty before she sent the
`update_fee`.
* Outbound `update_add_htlc`'s in the holding cell are certainly not
known by the counterparty, and we will reevaluate their addition to
the channel when freeing the holding cell.
* Inbound HTLCs in the `LocalRemoved` state will not be present in the
next *remote* commitment.
`ChannelContext::next_local_commit_tx_fee_msat` over-counts outbound
HTLCs in the `LocalAnnounced` and `RemoteRemoved` states, as well as
outbound `update_add_htlc`'s in the holding cell.
`ChannelContext::next_remote_commit_tx_fee_msat` over-counts inbound
HTLCs in the `LocalRemoved` state, as well as outbound HTLCs in the
`LocalAnnounced` state.
This commit stops using these functions in favor of the newly added
`ChannelContext::get_next_{local, remote}_commitment_stats` methods, and
fixes the issues described above.
As a side-effect, this commit makes consistent the set of HTLCs used to
calculate dust exposure, transaction fees, and balances in
`validate_update_add_htlc`.
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
4281
4277
&fee_estimator, funding.get_channel_type(),
4282
4278
);
4283
-
let htlc_stats = self.get_pending_htlc_stats(funding, None, dust_exposure_limiting_feerate);
4284
-
if htlc_stats.pending_inbound_htlcs + 1 > self.holder_max_accepted_htlcs as usize {
4279
+
// Do not include outbound update_add_htlc's in the holding cell, or those which haven't yet been ACK'ed by the counterparty (ie. LocalAnnounced HTLCs)
4280
+
let do_not_include_counterparty_unknown_htlcs = false;
if next_remote_commitment_stats.inbound_htlcs_count > self.holder_max_accepted_htlcs as usize {
4285
4284
return Err(ChannelError::close(format!("Remote tried to push more than our max accepted HTLCs ({})", self.holder_max_accepted_htlcs)));
4286
4285
}
4287
-
if htlc_stats.pending_inbound_htlcs_value_msat + msg.amount_msat > self.holder_max_htlc_value_in_flight_msat {
4286
+
if next_remote_commitment_stats.inbound_htlcs_value_msat > self.holder_max_htlc_value_in_flight_msat {
4288
4287
return Err(ChannelError::close(format!("Remote HTLC add would put them over our max HTLC value ({})", self.holder_max_htlc_value_in_flight_msat)));
4289
4288
}
4290
4289
4291
-
// Check holder_selected_channel_reserve_satoshis (we're getting paid, so they have to at least meet
4290
+
let remote_balance_before_fee_msat = next_remote_commitment_stats.counterparty_balance_msat.ok_or(ChannelError::close("Remote HTLC add would overdraw remaining funds".to_owned()))?;
4291
+
4292
+
// Check that the remote can afford to pay for this HTLC on-chain at the current
4293
+
// feerate_per_kw, while maintaining their channel reserve (as required by the spec).
4294
+
//
4295
+
// We check holder_selected_channel_reserve_satoshis (we're getting paid, so they have to at least meet
4292
4296
// the reserve_satoshis we told them to always have as direct payment so that they lose
4293
4297
// something if we punish them for broadcasting an old state).
4294
4298
// Note that we don't really care about having a small/no to_remote output in our local
@@ -4300,50 +4304,22 @@ where
4300
4304
// violate the reserve value if we do not do this (as we forget inbound HTLCs from the
4301
4305
// Channel state once they will not be present in the next received commitment
4302
4306
// transaction).
4303
-
let (local_balance_before_fee_msat, remote_balance_before_fee_msat) = {
4304
-
let removed_outbound_total_msat: u64 = self.pending_outbound_htlcs
0 commit comments