Skip to content

Commit

Permalink
Error on blinded forward and wrong-payload-provided
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
valentinewallace committed Sep 8, 2023
1 parent c397e22 commit 68e01d9
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2881,11 +2881,14 @@ where
macro_rules! return_malformed_err {
($msg: expr, $err_code: expr) => {
{
let sha256_of_onion = if msg.blinding_point.is_some() { [0; 32] } else {
Sha256::hash(&msg.onion_routing_packet.hop_data).into_inner()
};
log_info!(self.logger, "Failed to accept/forward incoming HTLC: {}", $msg);
return Err(HTLCFailureMsg::Malformed(msgs::UpdateFailMalformedHTLC {
channel_id: msg.channel_id,
htlc_id: msg.htlc_id,
sha256_of_onion: Sha256::hash(&msg.onion_routing_packet.hop_data).into_inner(),
sha256_of_onion,
failure_code: $err_code,
}));
}
Expand Down Expand Up @@ -2929,6 +2932,15 @@ where
}
}
}
macro_rules! return_blinded_htlc_err {
($msg: expr) => {
if msg.blinding_point.is_some() {
return_malformed_err!($msg, INVALID_ONION_BLINDING);
} else {
return_err!($msg, INVALID_ONION_BLINDING, [0; 32]);
}
}
}

let next_hop = match onion_utils::decode_next_payment_hop(shared_secret,
&msg.onion_routing_packet.hop_data[..], msg.onion_routing_packet.hmac, msg.payment_hash,
Expand All @@ -2952,13 +2964,22 @@ where
msg.onion_routing_packet.public_key.unwrap(), &shared_secret);
(short_channel_id, amt_to_forward, outgoing_cltv_value, Some(next_packet_pk))
},
onion_utils::Hop::Forward {
next_hop_data: msgs::InboundOnionPayload::BlindedForward { .. }, ..
} => {
return_blinded_htlc_err!("Forwarding blinded HTLCs is not supported yet");
},
// We'll do receive checks in [`Self::construct_pending_htlc_info`] so we have access to the
// inbound channel's state.
onion_utils::Hop::Receive { .. } => return Ok((next_hop, shared_secret, None)),
onion_utils::Hop::Forward { next_hop_data: msgs::InboundOnionPayload::Receive { .. }, .. } => {
return_err!("Final Node OnionHopData provided for us as an intermediary node", 0x4000 | 22, &[0; 0]);
},
_ => todo!()
onion_utils::Hop::Forward {
next_hop_data: msgs::InboundOnionPayload::BlindedReceive { .. }, ..
} => {
return_blinded_htlc_err!("Blinded final node onion provided for us as an intermediary node");
}
};

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

0 comments on commit 68e01d9

Please sign in to comment.