Skip to content

Commit

Permalink
Remove unreachable error case in construct_fwd_pending_htlc_info
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
valentinewallace committed Sep 8, 2023
1 parent 68e01d9 commit 80405b4
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PublicKey, secp256k1::Error>>
) -> Result<PendingHTLCInfo, InboundOnionErr> {
) -> PendingHTLCInfo {
debug_assert!(next_packet_pubkey_opt.is_some());
let outgoing_packet = msgs::OnionPacket {
version: 0,
Expand All @@ -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,
Expand All @@ -2751,7 +2751,7 @@ where
outgoing_amt_msat: amt_to_forward,
outgoing_cltv_value,
skimmed_fee_msat: None,
})
}
}

fn construct_recv_pending_htlc_info(
Expand Down Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit 80405b4

Please sign in to comment.