Skip to content

Commit c6d6561

Browse files
committed
Rustfmt touch ups
1 parent 1ed3121 commit c6d6561

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
@@ -6190,10 +6190,9 @@ where
61906190
let mut htlc_value_msat = 0;
61916191
for (idx, htlc) in self.context.pending_inbound_htlcs.iter().enumerate() {
61926192
if htlc.htlc_id == htlc_id_arg {
6193-
debug_assert_eq!(
6194-
htlc.payment_hash,
6195-
PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).to_byte_array())
6196-
);
6193+
let expected_hash =
6194+
PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).to_byte_array());
6195+
debug_assert_eq!(htlc.payment_hash, expected_hash);
61976196
log_debug!(
61986197
logger,
61996198
"Claiming inbound HTLC id {} with payment hash {} with preimage {}",
@@ -6347,10 +6346,8 @@ where
63476346
self.context.latest_monitor_update_id = monitor_update.update_id;
63486347
monitor_update.updates.append(&mut additional_update.updates);
63496348
} else {
6350-
let new_mon_id = self
6351-
.context
6352-
.blocked_monitor_updates
6353-
.get(0)
6349+
let blocked_upd = self.context.blocked_monitor_updates.get(0);
6350+
let new_mon_id = blocked_upd
63546351
.map(|upd| upd.update.update_id)
63556352
.unwrap_or(monitor_update.update_id);
63566353
monitor_update.update_id = new_mon_id;
@@ -6682,11 +6679,9 @@ where
66826679
));
66836680
}
66846681

6685-
self.mark_outbound_htlc_removed(
6686-
msg.htlc_id,
6687-
OutboundHTLCOutcome::Success(msg.payment_preimage),
6688-
)
6689-
.map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat))
6682+
let outcome = OutboundHTLCOutcome::Success(msg.payment_preimage);
6683+
self.mark_outbound_htlc_removed(msg.htlc_id, outcome)
6684+
.map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat))
66906685
}
66916686

66926687
#[rustfmt::skip]
@@ -7259,10 +7254,10 @@ where
72597254
// `ChannelMonitorUpdate` to the user, making this one redundant, however
72607255
// there's no harm in including the extra `ChannelMonitorUpdateStep` here.
72617256
// We do not bother to track and include `payment_info` here, however.
7257+
let fulfill =
7258+
self.get_update_fulfill_htlc(htlc_id, *payment_preimage, None, logger);
72627259
let mut additional_monitor_update =
7263-
if let UpdateFulfillFetch::NewClaim { monitor_update, .. } = self
7264-
.get_update_fulfill_htlc(htlc_id, *payment_preimage, None, logger)
7265-
{
7260+
if let UpdateFulfillFetch::NewClaim { monitor_update, .. } = fulfill {
72667261
monitor_update
72677262
} else {
72687263
unreachable!()
@@ -12434,12 +12429,8 @@ where
1243412429

1243512430
// Write out the old serialization for shutdown_pubkey for backwards compatibility, if
1243612431
// deserialized from that format.
12437-
match self
12438-
.context
12439-
.shutdown_scriptpubkey
12440-
.as_ref()
12441-
.and_then(|script| script.as_legacy_pubkey())
12442-
{
12432+
let shutdown_scriptpubkey = self.context.shutdown_scriptpubkey.as_ref();
12433+
match shutdown_scriptpubkey.and_then(|script| script.as_legacy_pubkey()) {
1244312434
Some(shutdown_pubkey) => shutdown_pubkey.write(writer)?,
1244412435
None => [0u8; PUBLIC_KEY_SIZE].write(writer)?,
1244512436
}
@@ -12718,11 +12709,11 @@ where
1271812709
// the default, and when `holder_max_htlc_value_in_flight_msat` is configured to be set to
1271912710
// a different percentage of the channel value then 10%, which older versions of LDK used
1272012711
// to set it to before the percentage was made configurable.
12712+
let legacy_reserve_satoshis = get_legacy_default_holder_selected_channel_reserve_satoshis(
12713+
self.funding.get_value_satoshis(),
12714+
);
1272112715
let serialized_holder_selected_reserve =
12722-
if self.funding.holder_selected_channel_reserve_satoshis
12723-
!= get_legacy_default_holder_selected_channel_reserve_satoshis(
12724-
self.funding.get_value_satoshis(),
12725-
) {
12716+
if self.funding.holder_selected_channel_reserve_satoshis != legacy_reserve_satoshis {
1272612717
Some(self.funding.holder_selected_channel_reserve_satoshis)
1272712718
} else {
1272812719
None
@@ -12731,12 +12722,12 @@ where
1273112722
let mut old_max_in_flight_percent_config = UserConfig::default().channel_handshake_config;
1273212723
old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel =
1273312724
MAX_IN_FLIGHT_PERCENT_LEGACY;
12725+
let max_in_flight_msat = get_holder_max_htlc_value_in_flight_msat(
12726+
self.funding.get_value_satoshis(),
12727+
&old_max_in_flight_percent_config,
12728+
);
1273412729
let serialized_holder_htlc_max_in_flight =
12735-
if self.context.holder_max_htlc_value_in_flight_msat
12736-
!= get_holder_max_htlc_value_in_flight_msat(
12737-
self.funding.get_value_satoshis(),
12738-
&old_max_in_flight_percent_config,
12739-
) {
12730+
if self.context.holder_max_htlc_value_in_flight_msat != max_in_flight_msat {
1274012731
Some(self.context.holder_max_htlc_value_in_flight_msat)
1274112732
} else {
1274212733
None
@@ -14233,16 +14224,17 @@ mod tests {
1423314224
&logger,
1423414225
)
1423514226
.unwrap();
14227+
let open_channel_msg = &outbound_chan
14228+
.get_open_channel(ChainHash::using_genesis_block(network), &&logger)
14229+
.unwrap();
1423614230
let mut inbound_chan = InboundV1Channel::<&TestKeysInterface>::new(
1423714231
&feeest,
1423814232
&&keys_provider,
1423914233
&&keys_provider,
1424014234
node_b_node_id,
1424114235
&channelmanager::provided_channel_type_features(&config),
1424214236
&features,
14243-
&outbound_chan
14244-
.get_open_channel(ChainHash::using_genesis_block(network), &&logger)
14245-
.unwrap(),
14237+
open_channel_msg,
1424614238
7,
1424714239
&config,
1424814240
0,

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15121,13 +15121,9 @@ where
1512115121
}
1512215122

1512315123
for short_channel_id in channel.context.historical_scids() {
15124-
short_to_chan_info.insert(
15125-
*short_channel_id,
15126-
(
15127-
channel.context.get_counterparty_node_id(),
15128-
channel.context.channel_id(),
15129-
),
15130-
);
15124+
let cp_id = channel.context.get_counterparty_node_id();
15125+
let chan_id = channel.context.channel_id();
15126+
short_to_chan_info.insert(*short_channel_id, (cp_id, chan_id));
1513115127
}
1513215128

1513315129
per_peer_state
@@ -15961,10 +15957,8 @@ where
1596115957
.into_iter()
1596215958
.zip(onion_fields.into_iter().zip(claimable_htlcs_list.into_iter()))
1596315959
{
15964-
let existing_payment = claimable_payments.insert(
15965-
payment_hash,
15966-
ClaimablePayment { purpose, htlcs, onion_fields: onion },
15967-
);
15960+
let claimable = ClaimablePayment { purpose, htlcs, onion_fields: onion };
15961+
let existing_payment = claimable_payments.insert(payment_hash, claimable);
1596815962
if existing_payment.is_some() {
1596915963
return Err(DecodeError::InvalidValue);
1597015964
}
@@ -15973,10 +15967,8 @@ where
1597315967
for (purpose, (payment_hash, htlcs)) in
1597415968
purposes.into_iter().zip(claimable_htlcs_list.into_iter())
1597515969
{
15976-
let existing_payment = claimable_payments.insert(
15977-
payment_hash,
15978-
ClaimablePayment { purpose, htlcs, onion_fields: None },
15979-
);
15970+
let claimable = ClaimablePayment { purpose, htlcs, onion_fields: None };
15971+
let existing_payment = claimable_payments.insert(payment_hash, claimable);
1598015972
if existing_payment.is_some() {
1598115973
return Err(DecodeError::InvalidValue);
1598215974
}
@@ -16097,13 +16089,9 @@ where
1609716089
return Err(DecodeError::InvalidValue);
1609816090
}
1609916091
if funded_chan.context.is_usable() {
16100-
if short_to_chan_info
16101-
.insert(
16102-
funded_chan.context.outbound_scid_alias(),
16103-
(funded_chan.context.get_counterparty_node_id(), *chan_id),
16104-
)
16105-
.is_some()
16106-
{
16092+
let alias = funded_chan.context.outbound_scid_alias();
16093+
let cp_id = funded_chan.context.get_counterparty_node_id();
16094+
if short_to_chan_info.insert(alias, (cp_id, *chan_id)).is_some() {
1610716095
// Note that in rare cases its possible to hit this while reading an older
1610816096
// channel if we just happened to pick a colliding outbound alias above.
1610916097
log_error!(
@@ -16492,21 +16480,17 @@ where
1649216480
let mut pending_events = channel_manager.pending_events.lock().unwrap();
1649316481
let payment_id =
1649416482
payment.inbound_payment_id(&inbound_payment_id_secret.unwrap());
16483+
let htlcs = payment.htlcs.iter().map(events::ClaimedHTLC::from).collect();
16484+
let sender_intended_total_msat =
16485+
payment.htlcs.first().map(|htlc| htlc.total_msat);
1649516486
pending_events.push_back((
1649616487
events::Event::PaymentClaimed {
1649716488
receiver_node_id,
1649816489
payment_hash,
1649916490
purpose: payment.purpose,
1650016491
amount_msat: claimable_amt_msat,
16501-
htlcs: payment
16502-
.htlcs
16503-
.iter()
16504-
.map(events::ClaimedHTLC::from)
16505-
.collect(),
16506-
sender_intended_total_msat: payment
16507-
.htlcs
16508-
.first()
16509-
.map(|htlc| htlc.total_msat),
16492+
htlcs,
16493+
sender_intended_total_msat,
1651016494
onion_fields: payment.onion_fields,
1651116495
payment_id: Some(payment_id),
1651216496
},

0 commit comments

Comments
 (0)