@@ -4484,85 +4484,67 @@ where
4484
4484
})
4485
4485
}
4486
4486
4487
- fn construct_pending_htlc_status<'a>(
4488
- &self, msg: &msgs::UpdateAddHTLC, counterparty_node_id: &PublicKey, shared_secret: [u8; 32],
4489
- decoded_hop: onion_utils::Hop, allow_underpay: bool,
4490
- next_packet_pubkey_opt: Option<Result<PublicKey, secp256k1::Error>>,
4491
- ) -> PendingHTLCStatus {
4492
- macro_rules! return_err {
4493
- ($msg: expr, $reason: expr, $data: expr) => {
4494
- {
4495
- let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(msg.channel_id), Some(msg.payment_hash));
4496
- log_info!(logger, "Failed to accept/forward incoming HTLC: {}", $msg);
4497
- if msg.blinding_point.is_some() {
4498
- return PendingHTLCStatus::Fail(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: LocalHTLCFailureReason::InvalidOnionBlinding.failure_code(),
4504
- }
4505
- ))
4487
+ fn construct_pending_htlc_fail_msg<'a>(&self, msg: &msgs::UpdateAddHTLC,
4488
+ counterparty_node_id: &PublicKey, shared_secret: [u8; 32], inbound_err: InboundHTLCErr) -> HTLCFailureMsg {
4489
+ let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(msg.channel_id), Some(msg.payment_hash));
4490
+ log_info!(logger, "Failed to accept/forward incoming HTLC: {}", inbound_err.msg);
4491
+
4492
+ if msg.blinding_point.is_some() {
4493
+ return HTLCFailureMsg::Malformed(
4494
+ msgs::UpdateFailMalformedHTLC {
4495
+ channel_id: msg.channel_id,
4496
+ htlc_id: msg.htlc_id,
4497
+ sha256_of_onion: [0; 32],
4498
+ failure_code: LocalHTLCFailureReason::InvalidOnionBlinding.failure_code(),
4506
4499
}
4507
- let failure = HTLCFailReason::reason($reason, $data.to_vec())
4508
- .get_encrypted_failure_packet(&shared_secret, &None);
4509
- return PendingHTLCStatus::Fail(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
4510
- channel_id: msg.channel_id,
4511
- htlc_id: msg.htlc_id,
4512
- reason: failure.data,
4513
- }));
4514
- }
4515
- }
4500
+ )
4516
4501
}
4502
+
4503
+ let failure = HTLCFailReason::reason(inbound_err.reason, inbound_err.err_data.to_vec())
4504
+ .get_encrypted_failure_packet(&shared_secret, &None);
4505
+ return HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
4506
+ channel_id: msg.channel_id,
4507
+ htlc_id: msg.htlc_id,
4508
+ reason: failure.data,
4509
+ });
4510
+ }
4511
+
4512
+ fn get_pending_htlc_info<'a>(
4513
+ &self, msg: &msgs::UpdateAddHTLC, shared_secret: [u8; 32],
4514
+ decoded_hop: onion_utils::Hop, allow_underpay: bool,
4515
+ next_packet_pubkey_opt: Option<Result<PublicKey, secp256k1::Error>>,
4516
+ ) -> Result<PendingHTLCInfo, InboundHTLCErr> {
4517
4517
match decoded_hop {
4518
4518
onion_utils::Hop::Receive { .. } | onion_utils::Hop::BlindedReceive { .. } => {
4519
4519
// OUR PAYMENT!
4520
+ // Note that we could obviously respond immediately with an update_fulfill_htlc
4521
+ // message, however that would leak that we are the recipient of this payment, so
4522
+ // instead we stay symmetric with the forwarding case, only responding (after a
4523
+ // delay) once they've send us a commitment_signed!
4520
4524
let current_height: u32 = self.best_block.read().unwrap().height;
4521
- match create_recv_pending_htlc_info(decoded_hop, shared_secret, msg.payment_hash,
4525
+ create_recv_pending_htlc_info(decoded_hop, shared_secret, msg.payment_hash,
4522
4526
msg.amount_msat, msg.cltv_expiry, None, allow_underpay, msg.skimmed_fee_msat,
4523
4527
current_height)
4524
- {
4525
- Ok(info) => {
4526
- // Note that we could obviously respond immediately with an update_fulfill_htlc
4527
- // message, however that would leak that we are the recipient of this payment, so
4528
- // instead we stay symmetric with the forwarding case, only responding (after a
4529
- // delay) once they've sent us a commitment_signed!
4530
- PendingHTLCStatus::Forward(info)
4531
- },
4532
- Err(InboundHTLCErr { reason, err_data, msg }) => return_err!(msg, reason, &err_data)
4533
- }
4534
4528
},
4535
4529
#[cfg(trampoline)]
4536
4530
onion_utils::Hop::TrampolineReceive { .. } | onion_utils::Hop::TrampolineBlindedReceive { .. } => {
4537
4531
// OUR PAYMENT!
4532
+ // Note that we could obviously respond immediately with an update_fulfill_htlc
4533
+ // message, however that would leak that we are the recipient of this payment, so
4534
+ // instead we stay symmetric with the forwarding case, only responding (after a
4535
+ // delay) once they've send us a commitment_signed!
4538
4536
let current_height: u32 = self.best_block.read().unwrap().height;
4539
- match create_recv_pending_htlc_info(decoded_hop, shared_secret, msg.payment_hash,
4537
+ create_recv_pending_htlc_info(decoded_hop, shared_secret, msg.payment_hash,
4540
4538
msg.amount_msat, msg.cltv_expiry, None, allow_underpay, msg.skimmed_fee_msat,
4541
4539
current_height)
4542
- {
4543
- Ok(info) => {
4544
- // Note that we could obviously respond immediately with an update_fulfill_htlc
4545
- // message, however that would leak that we are the recipient of this payment, so
4546
- // instead we stay symmetric with the forwarding case, only responding (after a
4547
- // delay) once they've sent us a commitment_signed!
4548
- PendingHTLCStatus::Forward(info)
4549
- },
4550
- Err(InboundHTLCErr { reason, err_data, msg }) => return_err!(msg, reason , &err_data)
4551
- }
4552
4540
},
4553
4541
onion_utils::Hop::Forward { .. } | onion_utils::Hop::BlindedForward { .. } => {
4554
- match create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt) {
4555
- Ok(info) => PendingHTLCStatus::Forward(info),
4556
- Err(InboundHTLCErr { reason, err_data, msg }) => return_err!(msg, reason, &err_data)
4557
- }
4542
+ create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt)
4558
4543
},
4559
4544
#[cfg(trampoline)]
4560
4545
onion_utils::Hop::TrampolineForward { .. } | onion_utils::Hop::TrampolineBlindedForward { .. } => {
4561
- match create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt) {
4562
- Ok(info) => PendingHTLCStatus::Forward(info),
4563
- Err(InboundHTLCErr { reason, err_data, msg }) => return_err!(msg, reason, &err_data)
4564
- }
4565
- }
4546
+ create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt)
4547
+ },
4566
4548
}
4567
4549
}
4568
4550
@@ -5863,16 +5845,14 @@ where
5863
5845
}
5864
5846
}
5865
5847
5866
- match self.construct_pending_htlc_status (
5867
- &update_add_htlc, &incoming_counterparty_node_id, shared_secret, next_hop,
5868
- incoming_accept_underpaying_htlcs, next_packet_details_opt.map(|d| d.next_packet_pubkey),
5848
+ match self.get_pending_htlc_info (
5849
+ &update_add_htlc, shared_secret, next_hop, incoming_accept_underpaying_htlcs ,
5850
+ next_packet_details_opt.map(|d| d.next_packet_pubkey),
5869
5851
) {
5870
- PendingHTLCStatus::Forward(htlc_forward) => {
5871
- htlc_forwards.push((htlc_forward, update_add_htlc.htlc_id));
5872
- },
5873
- PendingHTLCStatus::Fail(htlc_fail) => {
5852
+ Ok(info) => htlc_forwards.push((info, update_add_htlc.htlc_id)),
5853
+ Err(inbound_err) => {
5874
5854
let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash);
5875
- htlc_fails.push((htlc_fail , htlc_destination));
5855
+ htlc_fails.push((self.construct_pending_htlc_fail_msg(&update_add_htlc, &incoming_counterparty_node_id, shared_secret, inbound_err) , htlc_destination));
5876
5856
},
5877
5857
}
5878
5858
}
@@ -11825,7 +11805,6 @@ where
11825
11805
payment.htlcs.retain(|htlc| {
11826
11806
// If height is approaching the number of blocks we think it takes us to get
11827
11807
// our commitment transaction confirmed before the HTLC expires, plus the
11828
- // number of blocks we generally consider it to take to do a commitment update,
11829
11808
// just give up on it and fail the HTLC.
11830
11809
if height >= htlc.cltv_expiry - HTLC_FAIL_BACK_BUFFER {
11831
11810
let mut htlc_msat_height_data = htlc.value.to_be_bytes().to_vec();
0 commit comments