Skip to content

Commit 543adf1

Browse files
committed
Rustfmt forwarding_channel_not_found
Wasn't previously formatted because it was a macro.
1 parent 79ef565 commit 543adf1

File tree

1 file changed

+111
-44
lines changed

1 file changed

+111
-44
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 111 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6394,7 +6394,6 @@ where
63946394
}
63956395

63966396
/// Fail the list of provided HTLC forwards because the channel they were to be forwarded over does no longer exist.
6397-
#[rustfmt::skip]
63986397
fn forwarding_channel_not_found(
63996398
&self, forward_infos: impl Iterator<Item = HTLCForwardInfo>, short_chan_id: u64,
64006399
forwarding_counterparty: Option<PublicKey>, failed_forwards: &mut Vec<FailedHTLCForward>,
@@ -6403,16 +6402,31 @@ where
64036402
for forward_info in forward_infos {
64046403
match forward_info {
64056404
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
6406-
prev_short_channel_id, prev_htlc_id, prev_channel_id, prev_funding_outpoint,
6407-
prev_user_channel_id, prev_counterparty_node_id, forward_info: PendingHTLCInfo {
6408-
routing, incoming_shared_secret, payment_hash, outgoing_amt_msat,
6409-
outgoing_cltv_value, ..
6410-
}
6405+
prev_short_channel_id,
6406+
prev_htlc_id,
6407+
prev_channel_id,
6408+
prev_funding_outpoint,
6409+
prev_user_channel_id,
6410+
prev_counterparty_node_id,
6411+
forward_info:
6412+
PendingHTLCInfo {
6413+
routing,
6414+
incoming_shared_secret,
6415+
payment_hash,
6416+
outgoing_amt_msat,
6417+
outgoing_cltv_value,
6418+
..
6419+
},
64116420
}) => {
64126421
let cltv_expiry = routing.incoming_cltv_expiry();
64136422
macro_rules! failure_handler {
64146423
($msg: expr, $reason: expr, $err_data: expr, $phantom_ss: expr, $next_hop_unknown: expr) => {
6415-
let logger = WithContext::from(&self.logger, forwarding_counterparty, Some(prev_channel_id), Some(payment_hash));
6424+
let logger = WithContext::from(
6425+
&self.logger,
6426+
forwarding_counterparty,
6427+
Some(prev_channel_id),
6428+
Some(payment_hash),
6429+
);
64166430
log_info!(logger, "Failed to accept/forward incoming HTLC: {}", $msg);
64176431

64186432
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
@@ -6429,83 +6443,136 @@ where
64296443
});
64306444

64316445
let reason = if $next_hop_unknown {
6432-
HTLCHandlingFailureType::InvalidForward { requested_forward_scid: short_chan_id }
6446+
HTLCHandlingFailureType::InvalidForward {
6447+
requested_forward_scid: short_chan_id,
6448+
}
64336449
} else {
6434-
HTLCHandlingFailureType::Receive{ payment_hash }
6450+
HTLCHandlingFailureType::Receive { payment_hash }
64356451
};
64366452

6437-
failed_forwards.push((htlc_source, payment_hash,
6453+
failed_forwards.push((
6454+
htlc_source,
6455+
payment_hash,
64386456
HTLCFailReason::reason($reason, $err_data),
6439-
reason
6457+
reason,
64406458
));
64416459
continue;
6442-
}
6460+
};
64436461
}
64446462
macro_rules! fail_forward {
6445-
($msg: expr, $reason: expr, $err_data: expr, $phantom_ss: expr) => {
6446-
{
6447-
failure_handler!($msg, $reason, $err_data, $phantom_ss, true);
6448-
}
6449-
}
6463+
($msg: expr, $reason: expr, $err_data: expr, $phantom_ss: expr) => {{
6464+
failure_handler!($msg, $reason, $err_data, $phantom_ss, true);
6465+
}};
64506466
}
64516467
macro_rules! failed_payment {
6452-
($msg: expr, $reason: expr, $err_data: expr, $phantom_ss: expr) => {
6453-
{
6454-
failure_handler!($msg, $reason, $err_data, $phantom_ss, false);
6455-
}
6456-
}
6468+
($msg: expr, $reason: expr, $err_data: expr, $phantom_ss: expr) => {{
6469+
failure_handler!($msg, $reason, $err_data, $phantom_ss, false);
6470+
}};
64576471
}
64586472
if let PendingHTLCRouting::Forward { ref onion_packet, .. } = routing {
6459-
let phantom_pubkey_res = self.node_signer.get_node_id(Recipient::PhantomNode);
6460-
if phantom_pubkey_res.is_ok() && fake_scid::is_valid_phantom(&self.fake_scid_rand_bytes, short_chan_id, &self.chain_hash) {
6473+
let phantom_pubkey_res =
6474+
self.node_signer.get_node_id(Recipient::PhantomNode);
6475+
if phantom_pubkey_res.is_ok()
6476+
&& fake_scid::is_valid_phantom(
6477+
&self.fake_scid_rand_bytes,
6478+
short_chan_id,
6479+
&self.chain_hash,
6480+
) {
64616481
let decode_res = onion_utils::decode_next_payment_hop(
6462-
Recipient::PhantomNode, &onion_packet.public_key.unwrap(), &onion_packet.hop_data,
6463-
onion_packet.hmac, payment_hash, None, &*self.node_signer
6482+
Recipient::PhantomNode,
6483+
&onion_packet.public_key.unwrap(),
6484+
&onion_packet.hop_data,
6485+
onion_packet.hmac,
6486+
payment_hash,
6487+
None,
6488+
&*self.node_signer,
64646489
);
64656490
let next_hop = match decode_res {
64666491
Ok(res) => res,
64676492
Err(onion_utils::OnionDecodeErr::Malformed { err_msg, reason }) => {
6468-
let sha256_of_onion = Sha256::hash(&onion_packet.hop_data).to_byte_array();
6493+
let sha256_of_onion =
6494+
Sha256::hash(&onion_packet.hop_data).to_byte_array();
64696495
// In this scenario, the phantom would have sent us an
64706496
// `update_fail_malformed_htlc`, meaning here we encrypt the error as
64716497
// if it came from us (the second-to-last hop) but contains the sha256
64726498
// of the onion.
6473-
failed_payment!(err_msg, reason, sha256_of_onion.to_vec(), None);
6499+
failed_payment!(
6500+
err_msg,
6501+
reason,
6502+
sha256_of_onion.to_vec(),
6503+
None
6504+
);
64746505
},
6475-
Err(onion_utils::OnionDecodeErr::Relay { err_msg, reason, shared_secret, .. }) => {
6506+
Err(onion_utils::OnionDecodeErr::Relay {
6507+
err_msg,
6508+
reason,
6509+
shared_secret,
6510+
..
6511+
}) => {
64766512
let phantom_shared_secret = shared_secret.secret_bytes();
6477-
failed_payment!(err_msg, reason, Vec::new(), Some(phantom_shared_secret));
6513+
failed_payment!(
6514+
err_msg,
6515+
reason,
6516+
Vec::new(),
6517+
Some(phantom_shared_secret)
6518+
);
64786519
},
64796520
};
64806521
let phantom_shared_secret = next_hop.shared_secret().secret_bytes();
64816522
let current_height: u32 = self.best_block.read().unwrap().height;
6482-
let create_res = create_recv_pending_htlc_info(next_hop,
6483-
incoming_shared_secret, payment_hash, outgoing_amt_msat,
6484-
outgoing_cltv_value, Some(phantom_shared_secret), false, None,
6485-
current_height);
6486-
match create_res
6487-
{
6523+
let create_res = create_recv_pending_htlc_info(
6524+
next_hop,
6525+
incoming_shared_secret,
6526+
payment_hash,
6527+
outgoing_amt_msat,
6528+
outgoing_cltv_value,
6529+
Some(phantom_shared_secret),
6530+
false,
6531+
None,
6532+
current_height,
6533+
);
6534+
match create_res {
64886535
Ok(info) => phantom_receives.push((
6489-
prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint,
6490-
prev_channel_id, prev_user_channel_id, vec![(info, prev_htlc_id)]
6536+
prev_short_channel_id,
6537+
prev_counterparty_node_id,
6538+
prev_funding_outpoint,
6539+
prev_channel_id,
6540+
prev_user_channel_id,
6541+
vec![(info, prev_htlc_id)],
64916542
)),
6492-
Err(InboundHTLCErr { reason, err_data, msg }) => failed_payment!(msg, reason, err_data, Some(phantom_shared_secret))
6543+
Err(InboundHTLCErr { reason, err_data, msg }) => failed_payment!(
6544+
msg,
6545+
reason,
6546+
err_data,
6547+
Some(phantom_shared_secret)
6548+
),
64936549
}
64946550
} else {
6495-
fail_forward!(format!("Unknown short channel id {} for forward HTLC", short_chan_id),
6496-
LocalHTLCFailureReason::UnknownNextPeer, Vec::new(), None);
6551+
fail_forward!(
6552+
format!(
6553+
"Unknown short channel id {} for forward HTLC",
6554+
short_chan_id
6555+
),
6556+
LocalHTLCFailureReason::UnknownNextPeer,
6557+
Vec::new(),
6558+
None
6559+
);
64976560
}
64986561
} else {
6499-
fail_forward!(format!("Unknown short channel id {} for forward HTLC", short_chan_id),
6500-
LocalHTLCFailureReason::UnknownNextPeer, Vec::new(), None);
6562+
fail_forward!(
6563+
format!("Unknown short channel id {} for forward HTLC", short_chan_id),
6564+
LocalHTLCFailureReason::UnknownNextPeer,
6565+
Vec::new(),
6566+
None
6567+
);
65016568
}
65026569
},
65036570
HTLCForwardInfo::FailHTLC { .. } | HTLCForwardInfo::FailMalformedHTLC { .. } => {
65046571
// Channel went away before we could fail it. This implies
65056572
// the channel is now on chain and our counterparty is
65066573
// trying to broadcast the HTLC-Timeout, but that's their
65076574
// problem, not ours.
6508-
}
6575+
},
65096576
}
65106577
}
65116578
}

0 commit comments

Comments
 (0)