@@ -4495,68 +4495,58 @@ where
4495
4495
})
4496
4496
}
4497
4497
4498
- fn construct_pending_htlc_status<'a>(
4499
- &self, msg: &msgs::UpdateAddHTLC, counterparty_node_id: &PublicKey, shared_secret: [u8; 32],
4500
- decoded_hop: onion_utils::Hop, allow_underpay: bool,
4501
- next_packet_pubkey_opt: Option<Result<PublicKey, secp256k1::Error>>,
4502
- ) -> PendingHTLCStatus {
4503
- macro_rules! return_err {
4504
- ($msg: expr, $reason: expr, $data: expr) => {
4505
- {
4506
- let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(msg.channel_id), Some(msg.payment_hash));
4507
- log_info!(logger, "Failed to accept/forward incoming HTLC: {}", $msg);
4508
- if msg.blinding_point.is_some() {
4509
- return PendingHTLCStatus::Fail(HTLCFailureMsg::Malformed(
4510
- msgs::UpdateFailMalformedHTLC {
4511
- channel_id: msg.channel_id,
4512
- htlc_id: msg.htlc_id,
4513
- sha256_of_onion: [0; 32],
4514
- failure_code: LocalHTLCFailureReason::InvalidOnionBlinding.failure_code(),
4515
- }
4516
- ))
4517
- }
4518
- let failure = HTLCFailReason::reason($reason, $data.to_vec())
4519
- .get_encrypted_failure_packet(&shared_secret, &None);
4520
- return PendingHTLCStatus::Fail(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
4521
- channel_id: msg.channel_id,
4522
- htlc_id: msg.htlc_id,
4523
- reason: failure.data,
4524
- attribution_data: failure.attribution_data,
4525
- }));
4498
+ fn construct_pending_htlc_fail_msg<'a>(
4499
+ &self, msg: &msgs::UpdateAddHTLC, counterparty_node_id: &PublicKey,
4500
+ shared_secret: [u8; 32], inbound_err: InboundHTLCErr
4501
+ ) -> HTLCFailureMsg {
4502
+ let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(msg.channel_id), Some(msg.payment_hash));
4503
+ log_info!(logger, "Failed to accept/forward incoming HTLC: {}", inbound_err.msg);
4504
+
4505
+ if msg.blinding_point.is_some() {
4506
+ return HTLCFailureMsg::Malformed(
4507
+ msgs::UpdateFailMalformedHTLC {
4508
+ channel_id: msg.channel_id,
4509
+ htlc_id: msg.htlc_id,
4510
+ sha256_of_onion: [0; 32],
4511
+ failure_code: LocalHTLCFailureReason::InvalidOnionBlinding.failure_code(),
4526
4512
}
4527
- }
4513
+ )
4528
4514
}
4515
+
4516
+ let failure = HTLCFailReason::reason(inbound_err.reason, inbound_err.err_data.to_vec())
4517
+ .get_encrypted_failure_packet(&shared_secret, &None);
4518
+ return HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
4519
+ channel_id: msg.channel_id,
4520
+ htlc_id: msg.htlc_id,
4521
+ reason: failure.data,
4522
+ attribution_data: failure.attribution_data,
4523
+ });
4524
+ }
4525
+
4526
+ fn get_pending_htlc_info<'a>(
4527
+ &self, msg: &msgs::UpdateAddHTLC, shared_secret: [u8; 32],
4528
+ decoded_hop: onion_utils::Hop, allow_underpay: bool,
4529
+ next_packet_pubkey_opt: Option<Result<PublicKey, secp256k1::Error>>,
4530
+ ) -> Result<PendingHTLCInfo, InboundHTLCErr> {
4529
4531
match decoded_hop {
4530
4532
onion_utils::Hop::Receive { .. } | onion_utils::Hop::BlindedReceive { .. } |
4531
4533
onion_utils::Hop::TrampolineReceive { .. } | onion_utils::Hop::TrampolineBlindedReceive { .. } => {
4532
4534
// OUR PAYMENT!
4535
+ // Note that we could obviously respond immediately with an update_fulfill_htlc
4536
+ // message, however that would leak that we are the recipient of this payment, so
4537
+ // instead we stay symmetric with the forwarding case, only responding (after a
4538
+ // delay) once they've send us a commitment_signed!
4533
4539
let current_height: u32 = self.best_block.read().unwrap().height;
4534
- match create_recv_pending_htlc_info(decoded_hop, shared_secret, msg.payment_hash,
4540
+ create_recv_pending_htlc_info(decoded_hop, shared_secret, msg.payment_hash,
4535
4541
msg.amount_msat, msg.cltv_expiry, None, allow_underpay, msg.skimmed_fee_msat,
4536
4542
current_height)
4537
- {
4538
- Ok(info) => {
4539
- // Note that we could obviously respond immediately with an update_fulfill_htlc
4540
- // message, however that would leak that we are the recipient of this payment, so
4541
- // instead we stay symmetric with the forwarding case, only responding (after a
4542
- // delay) once they've sent us a commitment_signed!
4543
- PendingHTLCStatus::Forward(info)
4544
- },
4545
- Err(InboundHTLCErr { reason, err_data, msg }) => return_err!(msg, reason , &err_data)
4546
- }
4547
4543
},
4548
4544
onion_utils::Hop::Forward { .. } | onion_utils::Hop::BlindedForward { .. } => {
4549
- match create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt) {
4550
- Ok(info) => PendingHTLCStatus::Forward(info),
4551
- Err(InboundHTLCErr { reason, err_data, msg }) => return_err!(msg, reason, &err_data)
4552
- }
4545
+ create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt)
4553
4546
},
4554
4547
onion_utils::Hop::TrampolineForward { .. } | onion_utils::Hop::TrampolineBlindedForward { .. } => {
4555
- match create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt) {
4556
- Ok(info) => PendingHTLCStatus::Forward(info),
4557
- Err(InboundHTLCErr { reason, err_data, msg }) => return_err!(msg, reason, &err_data)
4558
- }
4559
- }
4548
+ create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt)
4549
+ },
4560
4550
}
4561
4551
}
4562
4552
@@ -5848,15 +5838,14 @@ where
5848
5838
}
5849
5839
}
5850
5840
5851
- match self.construct_pending_htlc_status (
5852
- &update_add_htlc, &incoming_counterparty_node_id, shared_secret, next_hop,
5853
- incoming_accept_underpaying_htlcs, next_packet_details_opt.map(|d| d.next_packet_pubkey),
5841
+ match self.get_pending_htlc_info (
5842
+ &update_add_htlc, shared_secret, next_hop, incoming_accept_underpaying_htlcs ,
5843
+ next_packet_details_opt.map(|d| d.next_packet_pubkey),
5854
5844
) {
5855
- PendingHTLCStatus::Forward(htlc_forward) => {
5856
- htlc_forwards.push((htlc_forward, update_add_htlc.htlc_id));
5857
- },
5858
- PendingHTLCStatus::Fail(htlc_fail) => {
5845
+ Ok(info) => htlc_forwards.push((info, update_add_htlc.htlc_id)),
5846
+ Err(inbound_err) => {
5859
5847
let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash);
5848
+ let htlc_fail = self.construct_pending_htlc_fail_msg(&update_add_htlc, &incoming_counterparty_node_id, shared_secret, inbound_err);
5860
5849
htlc_fails.push((htlc_fail, htlc_destination));
5861
5850
},
5862
5851
}
0 commit comments