mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 07:17:40 +01:00
Don't modify path when advance_path_by_one errors
When using advance_path_by_one when we are the introduction node, any error will result having the first hop of the input blinded path removed. Instead, only remove the first hop on success. Otherwise, the path will be invalid.
This commit is contained in:
parent
3bf84204e3
commit
efc4647c65
1 changed files with 5 additions and 2 deletions
|
@ -106,6 +106,8 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
|
|||
|
||||
// Advance the blinded onion message path by one hop, so make the second hop into the new
|
||||
// introduction node.
|
||||
//
|
||||
// Will only modify `path` when returning `Ok`.
|
||||
pub(crate) fn advance_path_by_one<NS: Deref, NL: Deref, T>(
|
||||
path: &mut BlindedPath, node_signer: &NS, node_id_lookup: &NL, secp_ctx: &Secp256k1<T>
|
||||
) -> Result<(), ()>
|
||||
|
@ -116,8 +118,8 @@ where
|
|||
{
|
||||
let control_tlvs_ss = node_signer.ecdh(Recipient::Node, &path.blinding_point, None)?;
|
||||
let rho = onion_utils::gen_rho_from_shared_secret(&control_tlvs_ss.secret_bytes());
|
||||
let encrypted_control_tlvs = path.blinded_hops.remove(0).encrypted_payload;
|
||||
let mut s = Cursor::new(&encrypted_control_tlvs);
|
||||
let encrypted_control_tlvs = &path.blinded_hops.get(0).ok_or(())?.encrypted_payload;
|
||||
let mut s = Cursor::new(encrypted_control_tlvs);
|
||||
let mut reader = FixedLengthReader::new(&mut s, encrypted_control_tlvs.len() as u64);
|
||||
match ChaChaPolyReadAdapter::read(&mut reader, rho) {
|
||||
Ok(ChaChaPolyReadAdapter {
|
||||
|
@ -139,6 +141,7 @@ where
|
|||
};
|
||||
mem::swap(&mut path.blinding_point, &mut new_blinding_point);
|
||||
path.introduction_node = IntroductionNode::NodeId(next_node_id);
|
||||
path.blinded_hops.remove(0);
|
||||
Ok(())
|
||||
},
|
||||
_ => Err(())
|
||||
|
|
Loading…
Add table
Reference in a new issue