@@ -2506,8 +2506,8 @@ where
25062506// `total_consistency_lock`
25072507// |
25082508// |__`forward_htlcs`
2509- // | |
2510- // | | __`pending_intercepted_htlcs`
2509+ // |
2510+ // |__`pending_intercepted_htlcs`
25112511// |
25122512// |__`decode_update_add_htlcs`
25132513// |
@@ -10696,77 +10696,76 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1069610696 prev_user_channel_id,
1069710697 forward_info,
1069810698 };
10699- match forward_htlcs.entry(scid) {
10700- hash_map::Entry::Occupied(mut entry) => {
10701- entry.get_mut().push(HTLCForwardInfo::AddHTLC(pending_add));
10702- },
10703- hash_map::Entry::Vacant(entry) => {
10704- if !is_our_scid
10705- && pending_add.forward_info.incoming_amt_msat.is_some()
10706- && fake_scid::is_valid_intercept(
10707- &self.fake_scid_rand_bytes,
10708- scid,
10709- &self.chain_hash,
10710- ) {
10711- let intercept_id = InterceptId(
10712- Sha256::hash(&pending_add.forward_info.incoming_shared_secret)
10713- .to_byte_array(),
10714- );
10715- let mut pending_intercepts =
10716- self.pending_intercepted_htlcs.lock().unwrap();
10717- match pending_intercepts.entry(intercept_id) {
10718- hash_map::Entry::Vacant(entry) => {
10719- new_intercept_events.push_back((
10720- events::Event::HTLCIntercepted {
10721- requested_next_hop_scid: scid,
10722- payment_hash,
10723- inbound_amount_msat: pending_add
10724- .forward_info
10725- .incoming_amt_msat
10726- .unwrap(),
10727- expected_outbound_amount_msat: pending_add
10728- .forward_info
10729- .outgoing_amt_msat,
10730- intercept_id,
10731- },
10732- None,
10733- ));
10734- entry.insert(pending_add);
10699+
10700+ if !is_our_scid
10701+ && pending_add.forward_info.incoming_amt_msat.is_some()
10702+ && fake_scid::is_valid_intercept(
10703+ &self.fake_scid_rand_bytes,
10704+ scid,
10705+ &self.chain_hash,
10706+ ) {
10707+ let intercept_id = InterceptId(
10708+ Sha256::hash(&pending_add.forward_info.incoming_shared_secret)
10709+ .to_byte_array(),
10710+ );
10711+ let mut pending_intercepts = self.pending_intercepted_htlcs.lock().unwrap();
10712+ match pending_intercepts.entry(intercept_id) {
10713+ hash_map::Entry::Vacant(entry) => {
10714+ new_intercept_events.push_back((
10715+ events::Event::HTLCIntercepted {
10716+ requested_next_hop_scid: scid,
10717+ payment_hash,
10718+ inbound_amount_msat: pending_add
10719+ .forward_info
10720+ .incoming_amt_msat
10721+ .unwrap(),
10722+ expected_outbound_amount_msat: pending_add
10723+ .forward_info
10724+ .outgoing_amt_msat,
10725+ intercept_id,
1073510726 },
10736- hash_map::Entry::Occupied(_) => {
10737- let logger = WithContext::from(
10738- &self.logger,
10739- None,
10740- Some(prev_channel_id),
10741- Some(payment_hash),
10742- );
10743- log_info!(
10727+ None,
10728+ ));
10729+ entry.insert(pending_add);
10730+ },
10731+ hash_map::Entry::Occupied(_) => {
10732+ let logger = WithContext::from(
10733+ &self.logger,
10734+ None,
10735+ Some(prev_channel_id),
10736+ Some(payment_hash),
10737+ );
10738+ log_info!(
1074410739 logger,
1074510740 "Failed to forward incoming HTLC: detected duplicate intercepted payment over short channel id {}",
1074610741 scid
1074710742 );
10748- let htlc_source = HTLCSource::PreviousHopData(
10749- pending_add.htlc_previous_hop_data(),
10750- );
10751- let reason = HTLCFailReason::from_failure_code(
10752- LocalHTLCFailureReason::UnknownNextPeer,
10753- );
10754- let failure_type =
10755- HTLCHandlingFailureType::InvalidForward {
10756- requested_forward_scid: scid,
10757- };
10758- failed_intercept_forwards.push((
10759- htlc_source,
10760- payment_hash,
10761- reason,
10762- failure_type,
10763- ));
10764- },
10765- }
10766- } else {
10743+ let htlc_source = HTLCSource::PreviousHopData(
10744+ pending_add.htlc_previous_hop_data(),
10745+ );
10746+ let reason = HTLCFailReason::from_failure_code(
10747+ LocalHTLCFailureReason::UnknownNextPeer,
10748+ );
10749+ let failure_type = HTLCHandlingFailureType::InvalidForward {
10750+ requested_forward_scid: scid,
10751+ };
10752+ failed_intercept_forwards.push((
10753+ htlc_source,
10754+ payment_hash,
10755+ reason,
10756+ failure_type,
10757+ ));
10758+ },
10759+ }
10760+ } else {
10761+ match forward_htlcs.entry(scid) {
10762+ hash_map::Entry::Occupied(mut entry) => {
10763+ entry.get_mut().push(HTLCForwardInfo::AddHTLC(pending_add));
10764+ },
10765+ hash_map::Entry::Vacant(entry) => {
1076710766 entry.insert(vec![HTLCForwardInfo::AddHTLC(pending_add)]);
10768- }
10769- },
10767+ },
10768+ }
1077010769 }
1077110770 }
1077210771 }
0 commit comments