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