Skip to content

Commit 4ed2d1a

Browse files
committed
Rustfmt touch ups
1 parent ac77c3e commit 4ed2d1a

File tree

2 files changed

+41
-65
lines changed

2 files changed

+41
-65
lines changed

lightning/src/ln/channel.rs

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6195,10 +6195,9 @@ where
61956195
let mut htlc_value_msat = 0;
61966196
for (idx, htlc) in self.context.pending_inbound_htlcs.iter().enumerate() {
61976197
if htlc.htlc_id == htlc_id_arg {
6198-
debug_assert_eq!(
6199-
htlc.payment_hash,
6200-
PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).to_byte_array())
6201-
);
6198+
let expected_hash =
6199+
PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).to_byte_array());
6200+
debug_assert_eq!(htlc.payment_hash, expected_hash);
62026201
log_debug!(
62036202
logger,
62046203
"Claiming inbound HTLC id {} with payment hash {} with preimage {}",
@@ -6352,10 +6351,8 @@ where
63526351
self.context.latest_monitor_update_id = monitor_update.update_id;
63536352
monitor_update.updates.append(&mut additional_update.updates);
63546353
} else {
6355-
let new_mon_id = self
6356-
.context
6357-
.blocked_monitor_updates
6358-
.get(0)
6354+
let blocked_upd = self.context.blocked_monitor_updates.get(0);
6355+
let new_mon_id = blocked_upd
63596356
.map(|upd| upd.update.update_id)
63606357
.unwrap_or(monitor_update.update_id);
63616358
monitor_update.update_id = new_mon_id;
@@ -6687,11 +6684,9 @@ where
66876684
));
66886685
}
66896686

6690-
self.mark_outbound_htlc_removed(
6691-
msg.htlc_id,
6692-
OutboundHTLCOutcome::Success(msg.payment_preimage),
6693-
)
6694-
.map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat))
6687+
let outcome = OutboundHTLCOutcome::Success(msg.payment_preimage);
6688+
self.mark_outbound_htlc_removed(msg.htlc_id, outcome)
6689+
.map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat))
66956690
}
66966691

66976692
#[rustfmt::skip]
@@ -7262,10 +7257,10 @@ where
72627257
// `ChannelMonitorUpdate` to the user, making this one redundant, however
72637258
// there's no harm in including the extra `ChannelMonitorUpdateStep` here.
72647259
// We do not bother to track and include `payment_info` here, however.
7260+
let fulfill =
7261+
self.get_update_fulfill_htlc(htlc_id, *payment_preimage, None, logger);
72657262
let mut additional_monitor_update =
7266-
if let UpdateFulfillFetch::NewClaim { monitor_update, .. } = self
7267-
.get_update_fulfill_htlc(htlc_id, *payment_preimage, None, logger)
7268-
{
7263+
if let UpdateFulfillFetch::NewClaim { monitor_update, .. } = fulfill {
72697264
monitor_update
72707265
} else {
72717266
unreachable!()
@@ -12429,12 +12424,8 @@ where
1242912424

1243012425
// Write out the old serialization for shutdown_pubkey for backwards compatibility, if
1243112426
// deserialized from that format.
12432-
match self
12433-
.context
12434-
.shutdown_scriptpubkey
12435-
.as_ref()
12436-
.and_then(|script| script.as_legacy_pubkey())
12437-
{
12427+
let shutdown_scriptpubkey = self.context.shutdown_scriptpubkey.as_ref();
12428+
match shutdown_scriptpubkey.and_then(|script| script.as_legacy_pubkey()) {
1243812429
Some(shutdown_pubkey) => shutdown_pubkey.write(writer)?,
1243912430
None => [0u8; PUBLIC_KEY_SIZE].write(writer)?,
1244012431
}
@@ -12713,11 +12704,11 @@ where
1271312704
// the default, and when `holder_max_htlc_value_in_flight_msat` is configured to be set to
1271412705
// a different percentage of the channel value then 10%, which older versions of LDK used
1271512706
// to set it to before the percentage was made configurable.
12707+
let legacy_reserve_satoshis = get_legacy_default_holder_selected_channel_reserve_satoshis(
12708+
self.funding.get_value_satoshis(),
12709+
);
1271612710
let serialized_holder_selected_reserve =
12717-
if self.funding.holder_selected_channel_reserve_satoshis
12718-
!= get_legacy_default_holder_selected_channel_reserve_satoshis(
12719-
self.funding.get_value_satoshis(),
12720-
) {
12711+
if self.funding.holder_selected_channel_reserve_satoshis != legacy_reserve_satoshis {
1272112712
Some(self.funding.holder_selected_channel_reserve_satoshis)
1272212713
} else {
1272312714
None
@@ -12726,12 +12717,12 @@ where
1272612717
let mut old_max_in_flight_percent_config = UserConfig::default().channel_handshake_config;
1272712718
old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel =
1272812719
MAX_IN_FLIGHT_PERCENT_LEGACY;
12720+
let max_in_flight_msat = get_holder_max_htlc_value_in_flight_msat(
12721+
self.funding.get_value_satoshis(),
12722+
&old_max_in_flight_percent_config,
12723+
);
1272912724
let serialized_holder_htlc_max_in_flight =
12730-
if self.context.holder_max_htlc_value_in_flight_msat
12731-
!= get_holder_max_htlc_value_in_flight_msat(
12732-
self.funding.get_value_satoshis(),
12733-
&old_max_in_flight_percent_config,
12734-
) {
12725+
if self.context.holder_max_htlc_value_in_flight_msat != max_in_flight_msat {
1273512726
Some(self.context.holder_max_htlc_value_in_flight_msat)
1273612727
} else {
1273712728
None
@@ -14228,16 +14219,17 @@ mod tests {
1422814219
&logger,
1422914220
)
1423014221
.unwrap();
14222+
let open_channel_msg = &outbound_chan
14223+
.get_open_channel(ChainHash::using_genesis_block(network), &&logger)
14224+
.unwrap();
1423114225
let mut inbound_chan = InboundV1Channel::<&TestKeysInterface>::new(
1423214226
&feeest,
1423314227
&&keys_provider,
1423414228
&&keys_provider,
1423514229
node_b_node_id,
1423614230
&channelmanager::provided_channel_type_features(&config),
1423714231
&features,
14238-
&outbound_chan
14239-
.get_open_channel(ChainHash::using_genesis_block(network), &&logger)
14240-
.unwrap(),
14232+
open_channel_msg,
1424114233
7,
1424214234
&config,
1424314235
0,

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15042,13 +15042,9 @@ where
1504215042
}
1504315043

1504415044
for short_channel_id in channel.context.historical_scids() {
15045-
short_to_chan_info.insert(
15046-
*short_channel_id,
15047-
(
15048-
channel.context.get_counterparty_node_id(),
15049-
channel.context.channel_id(),
15050-
),
15051-
);
15045+
let cp_id = channel.context.get_counterparty_node_id();
15046+
let chan_id = channel.context.channel_id();
15047+
short_to_chan_info.insert(*short_channel_id, (cp_id, chan_id));
1505215048
}
1505315049

1505415050
per_peer_state
@@ -15877,10 +15873,8 @@ where
1587715873
.into_iter()
1587815874
.zip(onion_fields.into_iter().zip(claimable_htlcs_list.into_iter()))
1587915875
{
15880-
let existing_payment = claimable_payments.insert(
15881-
payment_hash,
15882-
ClaimablePayment { purpose, htlcs, onion_fields: onion },
15883-
);
15876+
let claimable = ClaimablePayment { purpose, htlcs, onion_fields: onion };
15877+
let existing_payment = claimable_payments.insert(payment_hash, claimable);
1588415878
if existing_payment.is_some() {
1588515879
return Err(DecodeError::InvalidValue);
1588615880
}
@@ -15889,10 +15883,8 @@ where
1588915883
for (purpose, (payment_hash, htlcs)) in
1589015884
purposes.into_iter().zip(claimable_htlcs_list.into_iter())
1589115885
{
15892-
let existing_payment = claimable_payments.insert(
15893-
payment_hash,
15894-
ClaimablePayment { purpose, htlcs, onion_fields: None },
15895-
);
15886+
let claimable = ClaimablePayment { purpose, htlcs, onion_fields: None };
15887+
let existing_payment = claimable_payments.insert(payment_hash, claimable);
1589615888
if existing_payment.is_some() {
1589715889
return Err(DecodeError::InvalidValue);
1589815890
}
@@ -16013,13 +16005,9 @@ where
1601316005
return Err(DecodeError::InvalidValue);
1601416006
}
1601516007
if funded_chan.context.is_usable() {
16016-
if short_to_chan_info
16017-
.insert(
16018-
funded_chan.context.outbound_scid_alias(),
16019-
(funded_chan.context.get_counterparty_node_id(), *chan_id),
16020-
)
16021-
.is_some()
16022-
{
16008+
let alias = funded_chan.context.outbound_scid_alias();
16009+
let cp_id = funded_chan.context.get_counterparty_node_id();
16010+
if short_to_chan_info.insert(alias, (cp_id, *chan_id)).is_some() {
1602316011
// Note that in rare cases its possible to hit this while reading an older
1602416012
// channel if we just happened to pick a colliding outbound alias above.
1602516013
log_error!(
@@ -16408,21 +16396,17 @@ where
1640816396
let mut pending_events = channel_manager.pending_events.lock().unwrap();
1640916397
let payment_id =
1641016398
payment.inbound_payment_id(&inbound_payment_id_secret.unwrap());
16399+
let htlcs = payment.htlcs.iter().map(events::ClaimedHTLC::from).collect();
16400+
let sender_intended_total_msat =
16401+
payment.htlcs.first().map(|htlc| htlc.total_msat);
1641116402
pending_events.push_back((
1641216403
events::Event::PaymentClaimed {
1641316404
receiver_node_id,
1641416405
payment_hash,
1641516406
purpose: payment.purpose,
1641616407
amount_msat: claimable_amt_msat,
16417-
htlcs: payment
16418-
.htlcs
16419-
.iter()
16420-
.map(events::ClaimedHTLC::from)
16421-
.collect(),
16422-
sender_intended_total_msat: payment
16423-
.htlcs
16424-
.first()
16425-
.map(|htlc| htlc.total_msat),
16408+
htlcs,
16409+
sender_intended_total_msat,
1642616410
onion_fields: payment.onion_fields,
1642716411
payment_id: Some(payment_id),
1642816412
},

0 commit comments

Comments
 (0)