From 80405b44d013168dc12bebb824c69e59faeb3728 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Thu, 31 Aug 2023 17:31:46 -0400 Subject: [PATCH] Remove unreachable error case in construct_fwd_pending_htlc_info Since we completed handling for all wrong-payload-provided cases in the previous commit, we can remove an unreachable error on constructing pending HTLC info. This simplifies error handling down the line since we won't need even more unreachable code for handling a construct_fwd_pending_htlc_info intro node error. --- lightning/src/ln/channelmanager.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index c68b8fdf85b..7b1af71634a 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -2719,7 +2719,7 @@ where &self, msg: &msgs::UpdateAddHTLC, hop_data: msgs::InboundOnionPayload, hop_hmac: [u8; 32], new_packet_bytes: [u8; onion_utils::ONION_DATA_LEN], shared_secret: [u8; 32], next_packet_pubkey_opt: Option> - ) -> Result { + ) -> PendingHTLCInfo { debug_assert!(next_packet_pubkey_opt.is_some()); let outgoing_packet = msgs::OnionPacket { version: 0, @@ -2731,16 +2731,16 @@ where let (short_channel_id, amt_to_forward, outgoing_cltv_value) = match hop_data { msgs::InboundOnionPayload::Forward { short_channel_id, amt_to_forward, outgoing_cltv_value } => (short_channel_id, amt_to_forward, outgoing_cltv_value), - msgs::InboundOnionPayload::Receive { .. } => - return Err(InboundOnionErr { - msg: "Final Node OnionHopData provided for us as an intermediary node", - err_code: 0x4000 | 22, - err_data: Vec::new(), - }), - _ => todo!() + msgs::InboundOnionPayload::Receive { .. } | + msgs::InboundOnionPayload::BlindedReceive { .. } | + msgs::InboundOnionPayload::BlindedForward { .. } => + { + // We checked for this case in [`Self::decode_update_add_htlc_onion`]. + unreachable!() + } }; - Ok(PendingHTLCInfo { + PendingHTLCInfo { routing: PendingHTLCRouting::Forward { onion_packet: outgoing_packet, short_channel_id, @@ -2751,7 +2751,7 @@ where outgoing_amt_msat: amt_to_forward, outgoing_cltv_value, skimmed_fee_msat: None, - }) + } } fn construct_recv_pending_htlc_info( @@ -3152,11 +3152,10 @@ where } }, onion_utils::Hop::Forward { next_hop_data, next_hop_hmac, new_packet_bytes } => { - match self.construct_fwd_pending_htlc_info(msg, next_hop_data, next_hop_hmac, - new_packet_bytes, shared_secret, next_packet_pubkey_opt) { - Ok(info) => PendingHTLCStatus::Forward(info), - Err(InboundOnionErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data) - } + let fwd_info = self.construct_fwd_pending_htlc_info( + msg, next_hop_data, next_hop_hmac, new_packet_bytes, shared_secret, next_packet_pubkey_opt + ); + PendingHTLCStatus::Forward(fwd_info) } } }