Skip to content

Commit e3ab0ea

Browse files
committed
Run fmt on validate_update_add_htlc
1 parent d267d32 commit e3ab0ea

File tree

1 file changed

+64
-20
lines changed

1 file changed

+64
-20
lines changed

lightning/src/ln/channel.rs

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4338,7 +4338,6 @@ where
43384338
ret
43394339
}
43404340

4341-
#[rustfmt::skip]
43424341
fn validate_update_add_htlc<F: Deref>(
43434342
&self, funding: &FundingScope, msg: &msgs::UpdateAddHTLC,
43444343
fee_estimator: &LowerBoundedFeeEstimator<F>,
@@ -4347,26 +4346,48 @@ where
43474346
F::Target: FeeEstimator,
43484347
{
43494348
if msg.amount_msat > funding.get_value_satoshis() * 1000 {
4350-
return Err(ChannelError::close("Remote side tried to send more than the total value of the channel".to_owned()));
4349+
return Err(ChannelError::close(
4350+
"Remote side tried to send more than the total value of the channel".to_owned(),
4351+
));
43514352
}
43524353

4353-
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
4354-
&fee_estimator, funding.get_channel_type(),
4355-
);
4356-
// Don't 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)
4354+
let dust_exposure_limiting_feerate =
4355+
self.get_dust_exposure_limiting_feerate(&fee_estimator, funding.get_channel_type());
4356+
// Don't include outbound update_add_htlc's in the holding cell, or those which haven't yet been ACK'ed
4357+
// by the counterparty (ie. LocalAnnounced HTLCs)
43574358
let include_counterparty_unknown_htlcs = false;
43584359
// Don't include the extra fee spike buffer HTLC in calculations
43594360
let fee_spike_buffer_htlc = 0;
4360-
let next_remote_commitment_stats = self.get_next_remote_commitment_stats(funding, Some(HTLCAmountDirection { outbound: false, amount_msat: msg.amount_msat }), include_counterparty_unknown_htlcs, fee_spike_buffer_htlc, self.feerate_per_kw, dust_exposure_limiting_feerate);
4361+
let next_remote_commitment_stats = self.get_next_remote_commitment_stats(
4362+
funding,
4363+
Some(HTLCAmountDirection { outbound: false, amount_msat: msg.amount_msat }),
4364+
include_counterparty_unknown_htlcs,
4365+
fee_spike_buffer_htlc,
4366+
self.feerate_per_kw,
4367+
dust_exposure_limiting_feerate,
4368+
);
43614369

4362-
if next_remote_commitment_stats.inbound_htlcs_count > self.holder_max_accepted_htlcs as usize {
4363-
return Err(ChannelError::close(format!("Remote tried to push more than our max accepted HTLCs ({})", self.holder_max_accepted_htlcs)));
4370+
if next_remote_commitment_stats.inbound_htlcs_count
4371+
> self.holder_max_accepted_htlcs as usize
4372+
{
4373+
return Err(ChannelError::close(format!(
4374+
"Remote tried to push more than our max accepted HTLCs ({})",
4375+
self.holder_max_accepted_htlcs,
4376+
)));
43644377
}
4365-
if next_remote_commitment_stats.inbound_htlcs_value_msat > self.holder_max_htlc_value_in_flight_msat {
4366-
return Err(ChannelError::close(format!("Remote HTLC add would put them over our max HTLC value ({})", self.holder_max_htlc_value_in_flight_msat)));
4378+
if next_remote_commitment_stats.inbound_htlcs_value_msat
4379+
> self.holder_max_htlc_value_in_flight_msat
4380+
{
4381+
return Err(ChannelError::close(format!(
4382+
"Remote HTLC add would put them over our max HTLC value ({})",
4383+
self.holder_max_htlc_value_in_flight_msat,
4384+
)));
43674385
}
43684386

4369-
let remote_balance_before_fee_msat = next_remote_commitment_stats.counterparty_balance_before_fee_msat.ok_or(ChannelError::close("Remote HTLC add would overdraw remaining funds".to_owned()))?;
4387+
let remote_balance_before_fee_msat =
4388+
next_remote_commitment_stats.counterparty_balance_before_fee_msat.ok_or(
4389+
ChannelError::close("Remote HTLC add would overdraw remaining funds".to_owned()),
4390+
)?;
43704391

43714392
// Check that the remote can afford to pay for this HTLC on-chain at the current
43724393
// feerate_per_kw, while maintaining their channel reserve (as required by the spec).
@@ -4384,23 +4405,46 @@ where
43844405
// Channel state once they will not be present in the next received commitment
43854406
// transaction).
43864407
{
4387-
let remote_commit_tx_fee_msat = if funding.is_outbound() { 0 } else {
4408+
let remote_commit_tx_fee_msat = if funding.is_outbound() {
4409+
0
4410+
} else {
43884411
next_remote_commitment_stats.commit_tx_fee_sat * 1000
43894412
};
43904413
if remote_balance_before_fee_msat < remote_commit_tx_fee_msat {
4391-
return Err(ChannelError::close("Remote HTLC add would not leave enough to pay for fees".to_owned()));
4414+
return Err(ChannelError::close(
4415+
"Remote HTLC add would not leave enough to pay for fees".to_owned(),
4416+
));
43924417
};
4393-
if remote_balance_before_fee_msat.saturating_sub(remote_commit_tx_fee_msat) < funding.holder_selected_channel_reserve_satoshis * 1000 {
4394-
return Err(ChannelError::close("Remote HTLC add would put them under remote reserve value".to_owned()));
4418+
if remote_balance_before_fee_msat.saturating_sub(remote_commit_tx_fee_msat)
4419+
< funding.holder_selected_channel_reserve_satoshis * 1000
4420+
{
4421+
return Err(ChannelError::close(
4422+
"Remote HTLC add would put them under remote reserve value".to_owned(),
4423+
));
43954424
}
43964425
}
43974426

43984427
if funding.is_outbound() {
4399-
let next_local_commitment_stats = self.get_next_local_commitment_stats(funding, Some(HTLCAmountDirection { outbound: false, amount_msat: msg.amount_msat }), include_counterparty_unknown_htlcs, fee_spike_buffer_htlc, self.feerate_per_kw, dust_exposure_limiting_feerate);
4400-
let holder_balance_msat = next_local_commitment_stats.holder_balance_before_fee_msat.expect("Adding an inbound HTLC should never exhaust the holder's balance before fees");
4428+
let next_local_commitment_stats = self.get_next_local_commitment_stats(
4429+
funding,
4430+
Some(HTLCAmountDirection { outbound: false, amount_msat: msg.amount_msat }),
4431+
include_counterparty_unknown_htlcs,
4432+
fee_spike_buffer_htlc,
4433+
self.feerate_per_kw,
4434+
dust_exposure_limiting_feerate,
4435+
);
4436+
let holder_balance_msat =
4437+
next_local_commitment_stats.holder_balance_before_fee_msat.expect(
4438+
"Adding an inbound HTLC should never exhaust the holder's balance before fees",
4439+
);
44014440
// Check that they won't violate our local required channel reserve by adding this HTLC.
4402-
if holder_balance_msat < funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 + next_local_commitment_stats.commit_tx_fee_sat * 1000 {
4403-
return Err(ChannelError::close("Cannot accept HTLC that would put our balance under counterparty-announced channel reserve value".to_owned()));
4441+
if holder_balance_msat
4442+
< funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000
4443+
+ next_local_commitment_stats.commit_tx_fee_sat * 1000
4444+
{
4445+
return Err(ChannelError::close(
4446+
"Cannot accept HTLC that would put our balance under counterparty-announced channel reserve value".to_owned()
4447+
));
44044448
}
44054449
}
44064450

0 commit comments

Comments
 (0)