@@ -4487,67 +4487,55 @@ where
4487
4487
})
4488
4488
}
4489
4489
4490
- fn construct_pending_htlc_status<'a>(
4491
- &self, msg: &msgs::UpdateAddHTLC, counterparty_node_id: &PublicKey, shared_secret: [u8; 32],
4492
- decoded_hop: onion_utils::Hop, allow_underpay: bool,
4493
- next_packet_pubkey_opt: Option<Result<PublicKey, secp256k1::Error>>,
4494
- ) -> PendingHTLCStatus {
4495
- macro_rules! return_err {
4496
- ($msg: expr, $reason: expr, $data: expr) => {
4497
- {
4498
- let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(msg.channel_id), Some(msg.payment_hash));
4499
- log_info!(logger, "Failed to accept/forward incoming HTLC: {}", $msg);
4500
- if msg.blinding_point.is_some() {
4501
- return PendingHTLCStatus::Fail(HTLCFailureMsg::Malformed(
4502
- msgs::UpdateFailMalformedHTLC {
4503
- channel_id: msg.channel_id,
4504
- htlc_id: msg.htlc_id,
4505
- sha256_of_onion: [0; 32],
4506
- failure_code: LocalHTLCFailureReason::InvalidOnionBlinding.failure_code(),
4507
- }
4508
- ))
4490
+ fn construct_pending_htlc_fail_msg<'a>(&self, msg: &msgs::UpdateAddHTLC,
4491
+ counterparty_node_id: &PublicKey, shared_secret: [u8; 32], inbound_err: InboundHTLCErr) -> HTLCFailureMsg {
4492
+ let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(msg.channel_id), Some(msg.payment_hash));
4493
+ log_info!(logger, "Failed to accept/forward incoming HTLC: {}", inbound_err.msg);
4494
+
4495
+ if msg.blinding_point.is_some() {
4496
+ return HTLCFailureMsg::Malformed(
4497
+ msgs::UpdateFailMalformedHTLC {
4498
+ channel_id: msg.channel_id,
4499
+ htlc_id: msg.htlc_id,
4500
+ sha256_of_onion: [0; 32],
4501
+ failure_code: LocalHTLCFailureReason::InvalidOnionBlinding.failure_code(),
4509
4502
}
4510
- let failure = HTLCFailReason::reason($reason, $data.to_vec())
4511
- .get_encrypted_failure_packet(&shared_secret, &None);
4512
- return PendingHTLCStatus::Fail(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
4513
- channel_id: msg.channel_id,
4514
- htlc_id: msg.htlc_id,
4515
- reason: failure.data,
4516
- }));
4517
- }
4518
- }
4503
+ )
4519
4504
}
4505
+
4506
+ let failure = HTLCFailReason::reason(inbound_err.reason, inbound_err.err_data.to_vec())
4507
+ .get_encrypted_failure_packet(&shared_secret, &None);
4508
+ return HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
4509
+ channel_id: msg.channel_id,
4510
+ htlc_id: msg.htlc_id,
4511
+ reason: failure.data,
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> {
4520
4520
match decoded_hop {
4521
4521
onion_utils::Hop::Receive { .. } | onion_utils::Hop::BlindedReceive { .. } |
4522
4522
onion_utils::Hop::TrampolineReceive { .. } | onion_utils::Hop::TrampolineBlindedReceive { .. } => {
4523
4523
// OUR PAYMENT!
4524
+ // Note that we could obviously respond immediately with an update_fulfill_htlc
4525
+ // message, however that would leak that we are the recipient of this payment, so
4526
+ // instead we stay symmetric with the forwarding case, only responding (after a
4527
+ // delay) once they've send us a commitment_signed!
4524
4528
let current_height: u32 = self.best_block.read().unwrap().height;
4525
- match create_recv_pending_htlc_info(decoded_hop, shared_secret, msg.payment_hash,
4529
+ create_recv_pending_htlc_info(decoded_hop, shared_secret, msg.payment_hash,
4526
4530
msg.amount_msat, msg.cltv_expiry, None, allow_underpay, msg.skimmed_fee_msat,
4527
4531
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
4532
},
4539
4533
onion_utils::Hop::Forward { .. } | onion_utils::Hop::BlindedForward { .. } => {
4540
- match create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt) {
4541
- Ok(info) => PendingHTLCStatus::Forward(info),
4542
- Err(InboundHTLCErr { reason, err_data, msg }) => return_err!(msg, reason, &err_data)
4543
- }
4534
+ create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt)
4544
4535
},
4545
4536
onion_utils::Hop::TrampolineForward { .. } | onion_utils::Hop::TrampolineBlindedForward { .. } => {
4546
- match create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt) {
4547
- Ok(info) => PendingHTLCStatus::Forward(info),
4548
- Err(InboundHTLCErr { reason, err_data, msg }) => return_err!(msg, reason, &err_data)
4549
- }
4550
- }
4537
+ create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt)
4538
+ },
4551
4539
}
4552
4540
}
4553
4541
@@ -5839,16 +5827,14 @@ where
5839
5827
}
5840
5828
}
5841
5829
5842
- match self.construct_pending_htlc_status (
5843
- &update_add_htlc, &incoming_counterparty_node_id, shared_secret, next_hop,
5844
- incoming_accept_underpaying_htlcs, next_packet_details_opt.map(|d| d.next_packet_pubkey),
5830
+ match self.get_pending_htlc_info (
5831
+ &update_add_htlc, shared_secret, next_hop, incoming_accept_underpaying_htlcs ,
5832
+ next_packet_details_opt.map(|d| d.next_packet_pubkey),
5845
5833
) {
5846
- PendingHTLCStatus::Forward(htlc_forward) => {
5847
- htlc_forwards.push((htlc_forward, update_add_htlc.htlc_id));
5848
- },
5849
- PendingHTLCStatus::Fail(htlc_fail) => {
5834
+ Ok(info) => htlc_forwards.push((info, update_add_htlc.htlc_id)),
5835
+ Err(inbound_err) => {
5850
5836
let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash);
5851
- htlc_fails.push((htlc_fail , htlc_destination));
5837
+ htlc_fails.push((self.construct_pending_htlc_fail_msg(&update_add_htlc, &incoming_counterparty_node_id, shared_secret, inbound_err) , htlc_destination));
5852
5838
},
5853
5839
}
5854
5840
}
@@ -11784,7 +11770,6 @@ where
11784
11770
payment.htlcs.retain(|htlc| {
11785
11771
// If height is approaching the number of blocks we think it takes us to get
11786
11772
// our commitment transaction confirmed before the HTLC expires, plus the
11787
- // number of blocks we generally consider it to take to do a commitment update,
11788
11773
// just give up on it and fail the HTLC.
11789
11774
if height >= htlc.cltv_expiry - HTLC_FAIL_BACK_BUFFER {
11790
11775
let mut htlc_msat_height_data = htlc.value.to_be_bytes().to_vec();
0 commit comments