@@ -6394,7 +6394,6 @@ where
6394
6394
}
6395
6395
6396
6396
/// Fail the list of provided HTLC forwards because the channel they were to be forwarded over does no longer exist.
6397
- #[rustfmt::skip]
6398
6397
fn forwarding_channel_not_found(
6399
6398
&self, forward_infos: impl Iterator<Item = HTLCForwardInfo>, short_chan_id: u64,
6400
6399
forwarding_counterparty: Option<PublicKey>, failed_forwards: &mut Vec<FailedHTLCForward>,
@@ -6403,16 +6402,31 @@ where
6403
6402
for forward_info in forward_infos {
6404
6403
match forward_info {
6405
6404
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
+ },
6411
6420
}) => {
6412
6421
let cltv_expiry = routing.incoming_cltv_expiry();
6413
6422
macro_rules! failure_handler {
6414
6423
($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
+ );
6416
6430
log_info!(logger, "Failed to accept/forward incoming HTLC: {}", $msg);
6417
6431
6418
6432
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
@@ -6429,83 +6443,136 @@ where
6429
6443
});
6430
6444
6431
6445
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
+ }
6433
6449
} else {
6434
- HTLCHandlingFailureType::Receive{ payment_hash }
6450
+ HTLCHandlingFailureType::Receive { payment_hash }
6435
6451
};
6436
6452
6437
- failed_forwards.push((htlc_source, payment_hash,
6453
+ failed_forwards.push((
6454
+ htlc_source,
6455
+ payment_hash,
6438
6456
HTLCFailReason::reason($reason, $err_data),
6439
- reason
6457
+ reason,
6440
6458
));
6441
6459
continue;
6442
- }
6460
+ };
6443
6461
}
6444
6462
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
+ }};
6450
6466
}
6451
6467
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
+ }};
6457
6471
}
6458
6472
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
+ ) {
6461
6481
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,
6464
6489
);
6465
6490
let next_hop = match decode_res {
6466
6491
Ok(res) => res,
6467
6492
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();
6469
6495
// In this scenario, the phantom would have sent us an
6470
6496
// `update_fail_malformed_htlc`, meaning here we encrypt the error as
6471
6497
// if it came from us (the second-to-last hop) but contains the sha256
6472
6498
// 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
+ );
6474
6505
},
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
+ }) => {
6476
6512
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
+ );
6478
6519
},
6479
6520
};
6480
6521
let phantom_shared_secret = next_hop.shared_secret().secret_bytes();
6481
6522
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 {
6488
6535
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)],
6491
6542
)),
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
+ ),
6493
6549
}
6494
6550
} 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
+ );
6497
6560
}
6498
6561
} 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
+ );
6501
6568
}
6502
6569
},
6503
6570
HTLCForwardInfo::FailHTLC { .. } | HTLCForwardInfo::FailMalformedHTLC { .. } => {
6504
6571
// Channel went away before we could fail it. This implies
6505
6572
// the channel is now on chain and our counterparty is
6506
6573
// trying to broadcast the HTLC-Timeout, but that's their
6507
6574
// problem, not ours.
6508
- }
6575
+ },
6509
6576
}
6510
6577
}
6511
6578
}
0 commit comments