Skip to content

Commit c2715bf

Browse files
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.
1 parent b762012 commit c2715bf

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

lightning/src/ln/channelmanager.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ where
27192719
&self, msg: &msgs::UpdateAddHTLC, hop_data: msgs::InboundOnionPayload, hop_hmac: [u8; 32],
27202720
new_packet_bytes: [u8; onion_utils::ONION_DATA_LEN], shared_secret: [u8; 32],
27212721
next_packet_pubkey_opt: Option<Result<PublicKey, secp256k1::Error>>
2722-
) -> Result<PendingHTLCInfo, InboundOnionErr> {
2722+
) -> PendingHTLCInfo {
27232723
debug_assert!(next_packet_pubkey_opt.is_some());
27242724
let outgoing_packet = msgs::OnionPacket {
27252725
version: 0,
@@ -2731,16 +2731,16 @@ where
27312731
let (short_channel_id, amt_to_forward, outgoing_cltv_value) = match hop_data {
27322732
msgs::InboundOnionPayload::Forward { short_channel_id, amt_to_forward, outgoing_cltv_value } =>
27332733
(short_channel_id, amt_to_forward, outgoing_cltv_value),
2734-
msgs::InboundOnionPayload::Receive { .. } =>
2735-
return Err(InboundOnionErr {
2736-
msg: "Final Node OnionHopData provided for us as an intermediary node",
2737-
err_code: 0x4000 | 22,
2738-
err_data: Vec::new(),
2739-
}),
2740-
_ => todo!()
2734+
msgs::InboundOnionPayload::Receive { .. } |
2735+
msgs::InboundOnionPayload::BlindedReceive { .. } |
2736+
msgs::InboundOnionPayload::BlindedForward { .. } =>
2737+
{
2738+
// We checked for this case in [`Self::decode_update_add_htlc_onion`].
2739+
unreachable!()
2740+
}
27412741
};
27422742

2743-
Ok(PendingHTLCInfo {
2743+
PendingHTLCInfo {
27442744
routing: PendingHTLCRouting::Forward {
27452745
onion_packet: outgoing_packet,
27462746
short_channel_id,
@@ -2751,7 +2751,7 @@ where
27512751
outgoing_amt_msat: amt_to_forward,
27522752
outgoing_cltv_value,
27532753
skimmed_fee_msat: None,
2754-
})
2754+
}
27552755
}
27562756

27572757
fn construct_recv_pending_htlc_info(
@@ -3152,11 +3152,10 @@ where
31523152
}
31533153
},
31543154
onion_utils::Hop::Forward { next_hop_data, next_hop_hmac, new_packet_bytes } => {
3155-
match self.construct_fwd_pending_htlc_info(msg, next_hop_data, next_hop_hmac,
3156-
new_packet_bytes, shared_secret, next_packet_pubkey_opt) {
3157-
Ok(info) => PendingHTLCStatus::Forward(info),
3158-
Err(InboundOnionErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
3159-
}
3155+
let fwd_info = self.construct_fwd_pending_htlc_info(
3156+
msg, next_hop_data, next_hop_hmac, new_packet_bytes, shared_secret, next_packet_pubkey_opt
3157+
);
3158+
PendingHTLCStatus::Forward(fwd_info)
31603159
}
31613160
}
31623161
}

0 commit comments

Comments
 (0)