Skip to content

Commit e7e1afa

Browse files
committed
Trampoline onion construction.
1 parent 4baa8a7 commit e7e1afa

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

lightning/src/ln/msgs.rs

+27
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,17 @@ mod fuzzy_internal_msgs {
17401740
}
17411741
}
17421742

1743+
pub(crate) enum OutboundTrampolinePayload {
1744+
#[allow(unused)]
1745+
Forward {
1746+
/// The value, in msat, of the payment after this hop's fee is deducted.
1747+
amt_to_forward: u64,
1748+
outgoing_cltv_value: u32,
1749+
/// The node id to which the trampoline node must find a route
1750+
outgoing_node_id: PublicKey,
1751+
}
1752+
}
1753+
17431754
pub struct DecodedOnionErrorPacket {
17441755
pub(crate) hmac: [u8; 32],
17451756
pub(crate) failuremsg: Vec<u8>,
@@ -2597,6 +2608,22 @@ impl Writeable for OutboundOnionPayload {
25972608
}
25982609
}
25992610

2611+
impl Writeable for OutboundTrampolinePayload {
2612+
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
2613+
match self {
2614+
Self::Forward { amt_to_forward, outgoing_cltv_value, outgoing_node_id } => {
2615+
_encode_varint_length_prefixed_tlv!(w, {
2616+
(2, HighZeroBytesDroppedBigSize(*amt_to_forward), required),
2617+
(4, HighZeroBytesDroppedBigSize(*outgoing_cltv_value), required),
2618+
(14, outgoing_node_id, required)
2619+
});
2620+
}
2621+
}
2622+
Ok(())
2623+
}
2624+
}
2625+
2626+
26002627
impl<NS: Deref> ReadableArgs<(Option<PublicKey>, &NS)> for InboundOnionPayload where NS::Target: NodeSigner {
26012628
fn read<R: Read>(r: &mut R, args: (Option<PublicKey>, &NS)) -> Result<Self, DecodeError> {
26022629
let (update_add_blinding_point, node_signer) = args;

lightning/src/ln/onion_utils.rs

+18
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,24 @@ pub(super) fn construct_onion_packet(
291291
)
292292
}
293293

294+
#[allow(unused)]
295+
pub(super) fn construct_trampoline_onion_packet(
296+
payloads: Vec<msgs::OutboundTrampolinePayload>, onion_keys: Vec<OnionKeys>,
297+
prng_seed: [u8; 32], associated_data: &PaymentHash, length: u16,
298+
) -> Result<msgs::TrampolineOnionPacket, ()> {
299+
let mut packet_data = vec![0u8; length as usize];
300+
301+
let mut chacha = ChaCha20::new(&prng_seed, &[0; 8]);
302+
chacha.process(&vec![0u8; length as usize], &mut packet_data);
303+
304+
construct_onion_packet_with_init_noise::<_, _>(
305+
payloads,
306+
onion_keys,
307+
packet_data,
308+
Some(associated_data),
309+
)
310+
}
311+
294312
#[cfg(test)]
295313
/// Used in testing to write bogus `BogusOnionHopData` as well as `RawOnionHopData`, which is
296314
/// otherwise not representable in `msgs::OnionHopData`.

0 commit comments

Comments
 (0)