Skip to content

Commit

Permalink
Calculate Trampoline onion packet sizes dynamically.
Browse files Browse the repository at this point in the history
  • Loading branch information
arik-so committed Sep 24, 2024
1 parent 66fb520 commit 85c7d76
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lightning/src/ln/onion_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,20 @@ pub(super) fn construct_onion_packet(
#[allow(unused)]
pub(super) fn construct_trampoline_onion_packet(
payloads: Vec<msgs::OutboundTrampolinePayload>, onion_keys: Vec<OnionKeys>,
prng_seed: [u8; 32], associated_data: &PaymentHash, length: u16,
prng_seed: [u8; 32], associated_data: &PaymentHash,
) -> Result<msgs::TrampolineOnionPacket, ()> {
let mut packet_data = vec![0u8; length as usize];
let packet_length: usize = payloads
.iter()
.map(|p| {
let mut payload_len = LengthCalculatingWriter(0);
p.write(&mut payload_len).expect("Failed to calculate length");
payload_len.0 + 32
})
.sum();

let mut packet_data = vec![0u8; packet_length];
let mut chacha = ChaCha20::new(&prng_seed, &[0; 8]);
chacha.process(&vec![0u8; length as usize], &mut packet_data);
chacha.process(&vec![0u8; packet_length], &mut packet_data);

construct_onion_packet_with_init_noise::<_, _>(
payloads,
Expand Down

0 comments on commit 85c7d76

Please sign in to comment.