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