Skip to content

Commit b762012

Browse files
Error on blinded forward and wrong-payload-provided
Until we add forwarding support, we should error if we get a blinded forward payload. The new error macro will be reused when we add further error handling.
1 parent 69eeee0 commit b762012

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,11 +2881,14 @@ where
28812881
macro_rules! return_malformed_err {
28822882
($msg: expr, $err_code: expr) => {
28832883
{
2884+
let sha256_of_onion = if msg.blinding_point.is_some() { [0; 32] } else {
2885+
Sha256::hash(&msg.onion_routing_packet.hop_data).into_inner()
2886+
};
28842887
log_info!(self.logger, "Failed to accept/forward incoming HTLC: {}", $msg);
28852888
return Err(HTLCFailureMsg::Malformed(msgs::UpdateFailMalformedHTLC {
28862889
channel_id: msg.channel_id,
28872890
htlc_id: msg.htlc_id,
2888-
sha256_of_onion: Sha256::hash(&msg.onion_routing_packet.hop_data).into_inner(),
2891+
sha256_of_onion,
28892892
failure_code: $err_code,
28902893
}));
28912894
}
@@ -2929,6 +2932,15 @@ where
29292932
}
29302933
}
29312934
}
2935+
macro_rules! return_blinded_htlc_err {
2936+
($msg: expr) => {
2937+
if msg.blinding_point.is_some() {
2938+
return_malformed_err!($msg, INVALID_ONION_BLINDING);
2939+
} else {
2940+
return_err!($msg, INVALID_ONION_BLINDING, [0; 32]);
2941+
}
2942+
}
2943+
}
29322944

29332945
let next_hop = match onion_utils::decode_next_payment_hop(shared_secret,
29342946
&msg.onion_routing_packet.hop_data[..], msg.onion_routing_packet.hmac, msg.payment_hash,
@@ -2952,13 +2964,22 @@ where
29522964
msg.onion_routing_packet.public_key.unwrap(), &shared_secret);
29532965
(short_channel_id, amt_to_forward, outgoing_cltv_value, Some(next_packet_pk))
29542966
},
2967+
onion_utils::Hop::Forward {
2968+
next_hop_data: msgs::InboundOnionPayload::BlindedForward { .. }, ..
2969+
} => {
2970+
return_blinded_htlc_err!("Forwarding blinded HTLCs is not supported yet");
2971+
},
29552972
// We'll do receive checks in [`Self::construct_pending_htlc_info`] so we have access to the
29562973
// inbound channel's state.
29572974
onion_utils::Hop::Receive { .. } => return Ok((next_hop, shared_secret, None)),
29582975
onion_utils::Hop::Forward { next_hop_data: msgs::InboundOnionPayload::Receive { .. }, .. } => {
29592976
return_err!("Final Node OnionHopData provided for us as an intermediary node", 0x4000 | 22, &[0; 0]);
29602977
},
2961-
_ => todo!()
2978+
onion_utils::Hop::Forward {
2979+
next_hop_data: msgs::InboundOnionPayload::BlindedReceive { .. }, ..
2980+
} => {
2981+
return_blinded_htlc_err!("Blinded final node onion provided for us as an intermediary node");
2982+
}
29622983
};
29632984

29642985
// Perform outbound checks here instead of in [`Self::construct_pending_htlc_info`] because we

0 commit comments

Comments
 (0)