Skip to content

Commit 90965a9

Browse files
committed
Rustfmt touch ups
1 parent 1c06390 commit 90965a9

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
@@ -6177,10 +6177,9 @@ where
61776177
let mut htlc_value_msat = 0;
61786178
for (idx, htlc) in self.context.pending_inbound_htlcs.iter().enumerate() {
61796179
if htlc.htlc_id == htlc_id_arg {
6180-
debug_assert_eq!(
6181-
htlc.payment_hash,
6182-
PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).to_byte_array())
6183-
);
6180+
let expected_hash =
6181+
PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).to_byte_array());
6182+
debug_assert_eq!(htlc.payment_hash, expected_hash);
61846183
log_debug!(
61856184
logger,
61866185
"Claiming inbound HTLC id {} with payment hash {} with preimage {}",
@@ -6334,10 +6333,8 @@ where
63346333
self.context.latest_monitor_update_id = monitor_update.update_id;
63356334
monitor_update.updates.append(&mut additional_update.updates);
63366335
} else {
6337-
let new_mon_id = self
6338-
.context
6339-
.blocked_monitor_updates
6340-
.get(0)
6336+
let blocked_upd = self.context.blocked_monitor_updates.get(0);
6337+
let new_mon_id = blocked_upd
63416338
.map(|upd| upd.update.update_id)
63426339
.unwrap_or(monitor_update.update_id);
63436340
monitor_update.update_id = new_mon_id;
@@ -6669,11 +6666,9 @@ where
66696666
));
66706667
}
66716668

6672-
self.mark_outbound_htlc_removed(
6673-
msg.htlc_id,
6674-
OutboundHTLCOutcome::Success(msg.payment_preimage),
6675-
)
6676-
.map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat))
6669+
let outcome = OutboundHTLCOutcome::Success(msg.payment_preimage);
6670+
self.mark_outbound_htlc_removed(msg.htlc_id, outcome)
6671+
.map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat))
66776672
}
66786673

66796674
#[rustfmt::skip]
@@ -7244,10 +7239,10 @@ where
72447239
// `ChannelMonitorUpdate` to the user, making this one redundant, however
72457240
// there's no harm in including the extra `ChannelMonitorUpdateStep` here.
72467241
// We do not bother to track and include `payment_info` here, however.
7242+
let fulfill =
7243+
self.get_update_fulfill_htlc(htlc_id, *payment_preimage, None, logger);
72477244
let mut additional_monitor_update =
7248-
if let UpdateFulfillFetch::NewClaim { monitor_update, .. } = self
7249-
.get_update_fulfill_htlc(htlc_id, *payment_preimage, None, logger)
7250-
{
7245+
if let UpdateFulfillFetch::NewClaim { monitor_update, .. } = fulfill {
72517246
monitor_update
72527247
} else {
72537248
unreachable!()
@@ -12404,12 +12399,8 @@ where
1240412399

1240512400
// Write out the old serialization for shutdown_pubkey for backwards compatibility, if
1240612401
// deserialized from that format.
12407-
match self
12408-
.context
12409-
.shutdown_scriptpubkey
12410-
.as_ref()
12411-
.and_then(|script| script.as_legacy_pubkey())
12412-
{
12402+
let shutdown_scriptpubkey = self.context.shutdown_scriptpubkey.as_ref();
12403+
match shutdown_scriptpubkey.and_then(|script| script.as_legacy_pubkey()) {
1241312404
Some(shutdown_pubkey) => shutdown_pubkey.write(writer)?,
1241412405
None => [0u8; PUBLIC_KEY_SIZE].write(writer)?,
1241512406
}
@@ -12688,11 +12679,11 @@ where
1268812679
// the default, and when `holder_max_htlc_value_in_flight_msat` is configured to be set to
1268912680
// a different percentage of the channel value then 10%, which older versions of LDK used
1269012681
// to set it to before the percentage was made configurable.
12682+
let legacy_reserve_satoshis = get_legacy_default_holder_selected_channel_reserve_satoshis(
12683+
self.funding.get_value_satoshis(),
12684+
);
1269112685
let serialized_holder_selected_reserve =
12692-
if self.funding.holder_selected_channel_reserve_satoshis
12693-
!= get_legacy_default_holder_selected_channel_reserve_satoshis(
12694-
self.funding.get_value_satoshis(),
12695-
) {
12686+
if self.funding.holder_selected_channel_reserve_satoshis != legacy_reserve_satoshis {
1269612687
Some(self.funding.holder_selected_channel_reserve_satoshis)
1269712688
} else {
1269812689
None
@@ -12701,12 +12692,12 @@ where
1270112692
let mut old_max_in_flight_percent_config = UserConfig::default().channel_handshake_config;
1270212693
old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel =
1270312694
MAX_IN_FLIGHT_PERCENT_LEGACY;
12695+
let max_in_flight_msat = get_holder_max_htlc_value_in_flight_msat(
12696+
self.funding.get_value_satoshis(),
12697+
&old_max_in_flight_percent_config,
12698+
);
1270412699
let serialized_holder_htlc_max_in_flight =
12705-
if self.context.holder_max_htlc_value_in_flight_msat
12706-
!= get_holder_max_htlc_value_in_flight_msat(
12707-
self.funding.get_value_satoshis(),
12708-
&old_max_in_flight_percent_config,
12709-
) {
12700+
if self.context.holder_max_htlc_value_in_flight_msat != max_in_flight_msat {
1271012701
Some(self.context.holder_max_htlc_value_in_flight_msat)
1271112702
} else {
1271212703
None
@@ -14203,16 +14194,17 @@ mod tests {
1420314194
&logger,
1420414195
)
1420514196
.unwrap();
14197+
let open_channel_msg = &outbound_chan
14198+
.get_open_channel(ChainHash::using_genesis_block(network), &&logger)
14199+
.unwrap();
1420614200
let mut inbound_chan = InboundV1Channel::<&TestKeysInterface>::new(
1420714201
&feeest,
1420814202
&&keys_provider,
1420914203
&&keys_provider,
1421014204
node_b_node_id,
1421114205
&channelmanager::provided_channel_type_features(&config),
1421214206
&features,
14213-
&outbound_chan
14214-
.get_open_channel(ChainHash::using_genesis_block(network), &&logger)
14215-
.unwrap(),
14207+
open_channel_msg,
1421614208
7,
1421714209
&config,
1421814210
0,

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15426,13 +15426,9 @@ where
1542615426
}
1542715427

1542815428
for short_channel_id in channel.context.historical_scids() {
15429-
short_to_chan_info.insert(
15430-
*short_channel_id,
15431-
(
15432-
channel.context.get_counterparty_node_id(),
15433-
channel.context.channel_id(),
15434-
),
15435-
);
15429+
let cp_id = channel.context.get_counterparty_node_id();
15430+
let chan_id = channel.context.channel_id();
15431+
short_to_chan_info.insert(*short_channel_id, (cp_id, chan_id));
1543615432
}
1543715433

1543815434
per_peer_state
@@ -16261,10 +16257,8 @@ where
1626116257
.into_iter()
1626216258
.zip(onion_fields.into_iter().zip(claimable_htlcs_list.into_iter()))
1626316259
{
16264-
let existing_payment = claimable_payments.insert(
16265-
payment_hash,
16266-
ClaimablePayment { purpose, htlcs, onion_fields: onion },
16267-
);
16260+
let claimable = ClaimablePayment { purpose, htlcs, onion_fields: onion };
16261+
let existing_payment = claimable_payments.insert(payment_hash, claimable);
1626816262
if existing_payment.is_some() {
1626916263
return Err(DecodeError::InvalidValue);
1627016264
}
@@ -16273,10 +16267,8 @@ where
1627316267
for (purpose, (payment_hash, htlcs)) in
1627416268
purposes.into_iter().zip(claimable_htlcs_list.into_iter())
1627516269
{
16276-
let existing_payment = claimable_payments.insert(
16277-
payment_hash,
16278-
ClaimablePayment { purpose, htlcs, onion_fields: None },
16279-
);
16270+
let claimable = ClaimablePayment { purpose, htlcs, onion_fields: None };
16271+
let existing_payment = claimable_payments.insert(payment_hash, claimable);
1628016272
if existing_payment.is_some() {
1628116273
return Err(DecodeError::InvalidValue);
1628216274
}
@@ -16397,13 +16389,9 @@ where
1639716389
return Err(DecodeError::InvalidValue);
1639816390
}
1639916391
if funded_chan.context.is_usable() {
16400-
if short_to_chan_info
16401-
.insert(
16402-
funded_chan.context.outbound_scid_alias(),
16403-
(funded_chan.context.get_counterparty_node_id(), *chan_id),
16404-
)
16405-
.is_some()
16406-
{
16392+
let alias = funded_chan.context.outbound_scid_alias();
16393+
let cp_id = funded_chan.context.get_counterparty_node_id();
16394+
if short_to_chan_info.insert(alias, (cp_id, *chan_id)).is_some() {
1640716395
// Note that in rare cases its possible to hit this while reading an older
1640816396
// channel if we just happened to pick a colliding outbound alias above.
1640916397
log_error!(
@@ -16792,21 +16780,17 @@ where
1679216780
let mut pending_events = channel_manager.pending_events.lock().unwrap();
1679316781
let payment_id =
1679416782
payment.inbound_payment_id(&inbound_payment_id_secret.unwrap());
16783+
let htlcs = payment.htlcs.iter().map(events::ClaimedHTLC::from).collect();
16784+
let sender_intended_total_msat =
16785+
payment.htlcs.first().map(|htlc| htlc.total_msat);
1679516786
pending_events.push_back((
1679616787
events::Event::PaymentClaimed {
1679716788
receiver_node_id,
1679816789
payment_hash,
1679916790
purpose: payment.purpose,
1680016791
amount_msat: claimable_amt_msat,
16801-
htlcs: payment
16802-
.htlcs
16803-
.iter()
16804-
.map(events::ClaimedHTLC::from)
16805-
.collect(),
16806-
sender_intended_total_msat: payment
16807-
.htlcs
16808-
.first()
16809-
.map(|htlc| htlc.total_msat),
16792+
htlcs,
16793+
sender_intended_total_msat,
1681016794
onion_fields: payment.onion_fields,
1681116795
payment_id: Some(payment_id),
1681216796
},

0 commit comments

Comments
 (0)