Skip to content

Commit 0c54d97

Browse files
committed
Rustfmt touch ups
1 parent 506b14e commit 0c54d97

File tree

2 files changed

+38
-62
lines changed

2 files changed

+38
-62
lines changed

lightning/src/ln/channel.rs

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6220,10 +6220,9 @@ where
62206220
let mut htlc_value_msat = 0;
62216221
for (idx, htlc) in self.context.pending_inbound_htlcs.iter().enumerate() {
62226222
if htlc.htlc_id == htlc_id_arg {
6223-
debug_assert_eq!(
6224-
htlc.payment_hash,
6225-
PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).to_byte_array())
6226-
);
6223+
let expected_hash =
6224+
PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).to_byte_array());
6225+
debug_assert_eq!(htlc.payment_hash, expected_hash);
62276226
log_debug!(
62286227
logger,
62296228
"Claiming inbound HTLC id {} with payment hash {} with preimage {}",
@@ -6377,10 +6376,8 @@ where
63776376
self.context.latest_monitor_update_id = monitor_update.update_id;
63786377
monitor_update.updates.append(&mut additional_update.updates);
63796378
} else {
6380-
let new_mon_id = self
6381-
.context
6382-
.blocked_monitor_updates
6383-
.get(0)
6379+
let blocked_upd = self.context.blocked_monitor_updates.get(0);
6380+
let new_mon_id = blocked_upd
63846381
.map(|upd| upd.update.update_id)
63856382
.unwrap_or(monitor_update.update_id);
63866383
monitor_update.update_id = new_mon_id;
@@ -6712,11 +6709,9 @@ where
67126709
));
67136710
}
67146711

6715-
self.mark_outbound_htlc_removed(
6716-
msg.htlc_id,
6717-
OutboundHTLCOutcome::Success(msg.payment_preimage),
6718-
)
6719-
.map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat))
6712+
let outcome = OutboundHTLCOutcome::Success(msg.payment_preimage);
6713+
self.mark_outbound_htlc_removed(msg.htlc_id, outcome)
6714+
.map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat))
67206715
}
67216716

67226717
#[rustfmt::skip]
@@ -12465,12 +12460,8 @@ where
1246512460

1246612461
// Write out the old serialization for shutdown_pubkey for backwards compatibility, if
1246712462
// deserialized from that format.
12468-
match self
12469-
.context
12470-
.shutdown_scriptpubkey
12471-
.as_ref()
12472-
.and_then(|script| script.as_legacy_pubkey())
12473-
{
12463+
let shutdown_scriptpubkey = self.context.shutdown_scriptpubkey.as_ref();
12464+
match shutdown_scriptpubkey.and_then(|script| script.as_legacy_pubkey()) {
1247412465
Some(shutdown_pubkey) => shutdown_pubkey.write(writer)?,
1247512466
None => [0u8; PUBLIC_KEY_SIZE].write(writer)?,
1247612467
}
@@ -12749,11 +12740,11 @@ where
1274912740
// the default, and when `holder_max_htlc_value_in_flight_msat` is configured to be set to
1275012741
// a different percentage of the channel value then 10%, which older versions of LDK used
1275112742
// to set it to before the percentage was made configurable.
12743+
let legacy_reserve_satoshis = get_legacy_default_holder_selected_channel_reserve_satoshis(
12744+
self.funding.get_value_satoshis(),
12745+
);
1275212746
let serialized_holder_selected_reserve =
12753-
if self.funding.holder_selected_channel_reserve_satoshis
12754-
!= get_legacy_default_holder_selected_channel_reserve_satoshis(
12755-
self.funding.get_value_satoshis(),
12756-
) {
12747+
if self.funding.holder_selected_channel_reserve_satoshis != legacy_reserve_satoshis {
1275712748
Some(self.funding.holder_selected_channel_reserve_satoshis)
1275812749
} else {
1275912750
None
@@ -12762,12 +12753,12 @@ where
1276212753
let mut old_max_in_flight_percent_config = UserConfig::default().channel_handshake_config;
1276312754
old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel =
1276412755
MAX_IN_FLIGHT_PERCENT_LEGACY;
12756+
let max_in_flight_msat = get_holder_max_htlc_value_in_flight_msat(
12757+
self.funding.get_value_satoshis(),
12758+
&old_max_in_flight_percent_config,
12759+
);
1276512760
let serialized_holder_htlc_max_in_flight =
12766-
if self.context.holder_max_htlc_value_in_flight_msat
12767-
!= get_holder_max_htlc_value_in_flight_msat(
12768-
self.funding.get_value_satoshis(),
12769-
&old_max_in_flight_percent_config,
12770-
) {
12761+
if self.context.holder_max_htlc_value_in_flight_msat != max_in_flight_msat {
1277112762
Some(self.context.holder_max_htlc_value_in_flight_msat)
1277212763
} else {
1277312764
None
@@ -14262,16 +14253,17 @@ mod tests {
1426214253
&logger,
1426314254
)
1426414255
.unwrap();
14256+
let open_channel_msg = &outbound_chan
14257+
.get_open_channel(ChainHash::using_genesis_block(network), &&logger)
14258+
.unwrap();
1426514259
let mut inbound_chan = InboundV1Channel::<&TestKeysInterface>::new(
1426614260
&feeest,
1426714261
&&keys_provider,
1426814262
&&keys_provider,
1426914263
node_b_node_id,
1427014264
&channelmanager::provided_channel_type_features(&config),
1427114265
&features,
14272-
&outbound_chan
14273-
.get_open_channel(ChainHash::using_genesis_block(network), &&logger)
14274-
.unwrap(),
14266+
open_channel_msg,
1427514267
7,
1427614268
&config,
1427714269
0,

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15025,13 +15025,9 @@ where
1502515025
}
1502615026

1502715027
for short_channel_id in channel.context.historical_scids() {
15028-
short_to_chan_info.insert(
15029-
*short_channel_id,
15030-
(
15031-
channel.context.get_counterparty_node_id(),
15032-
channel.context.channel_id(),
15033-
),
15034-
);
15028+
let cp_id = channel.context.get_counterparty_node_id();
15029+
let chan_id = channel.context.channel_id();
15030+
short_to_chan_info.insert(*short_channel_id, (cp_id, chan_id));
1503515031
}
1503615032

1503715033
per_peer_state
@@ -15865,10 +15861,8 @@ where
1586515861
.into_iter()
1586615862
.zip(onion_fields.into_iter().zip(claimable_htlcs_list.into_iter()))
1586715863
{
15868-
let existing_payment = claimable_payments.insert(
15869-
payment_hash,
15870-
ClaimablePayment { purpose, htlcs, onion_fields: onion },
15871-
);
15864+
let claimable = ClaimablePayment { purpose, htlcs, onion_fields: onion };
15865+
let existing_payment = claimable_payments.insert(payment_hash, claimable);
1587215866
if existing_payment.is_some() {
1587315867
return Err(DecodeError::InvalidValue);
1587415868
}
@@ -15877,10 +15871,8 @@ where
1587715871
for (purpose, (payment_hash, htlcs)) in
1587815872
purposes.into_iter().zip(claimable_htlcs_list.into_iter())
1587915873
{
15880-
let existing_payment = claimable_payments.insert(
15881-
payment_hash,
15882-
ClaimablePayment { purpose, htlcs, onion_fields: None },
15883-
);
15874+
let claimable = ClaimablePayment { purpose, htlcs, onion_fields: None };
15875+
let existing_payment = claimable_payments.insert(payment_hash, claimable);
1588415876
if existing_payment.is_some() {
1588515877
return Err(DecodeError::InvalidValue);
1588615878
}
@@ -16001,13 +15993,9 @@ where
1600115993
return Err(DecodeError::InvalidValue);
1600215994
}
1600315995
if funded_chan.context.is_usable() {
16004-
if short_to_chan_info
16005-
.insert(
16006-
funded_chan.context.outbound_scid_alias(),
16007-
(funded_chan.context.get_counterparty_node_id(), *chan_id),
16008-
)
16009-
.is_some()
16010-
{
15996+
let alias = funded_chan.context.outbound_scid_alias();
15997+
let cp_id = funded_chan.context.get_counterparty_node_id();
15998+
if short_to_chan_info.insert(alias, (cp_id, *chan_id)).is_some() {
1601115999
// Note that in rare cases its possible to hit this while reading an older
1601216000
// channel if we just happened to pick a colliding outbound alias above.
1601316001
log_error!(
@@ -16396,21 +16384,17 @@ where
1639616384
let mut pending_events = channel_manager.pending_events.lock().unwrap();
1639716385
let payment_id =
1639816386
payment.inbound_payment_id(&inbound_payment_id_secret.unwrap());
16387+
let htlcs = payment.htlcs.iter().map(events::ClaimedHTLC::from).collect();
16388+
let sender_intended_total_msat =
16389+
payment.htlcs.first().map(|htlc| htlc.total_msat);
1639916390
pending_events.push_back((
1640016391
events::Event::PaymentClaimed {
1640116392
receiver_node_id,
1640216393
payment_hash,
1640316394
purpose: payment.purpose,
1640416395
amount_msat: claimable_amt_msat,
16405-
htlcs: payment
16406-
.htlcs
16407-
.iter()
16408-
.map(events::ClaimedHTLC::from)
16409-
.collect(),
16410-
sender_intended_total_msat: payment
16411-
.htlcs
16412-
.first()
16413-
.map(|htlc| htlc.total_msat),
16396+
htlcs,
16397+
sender_intended_total_msat,
1641416398
onion_fields: payment.onion_fields,
1641516399
payment_id: Some(payment_id),
1641616400
},

0 commit comments

Comments
 (0)