Skip to content

Commit c329c45

Browse files
committed
Serialize blinded path forwards in Trampoline onions.
1 parent b2bcfca commit c329c45

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

lightning/src/ln/msgs.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,9 +1746,9 @@ pub struct FinalOnionHopData {
17461746

17471747
mod fuzzy_internal_msgs {
17481748
use bitcoin::secp256k1::PublicKey;
1749-
use crate::blinded_path::payment::{PaymentConstraints, PaymentContext, PaymentRelay};
1749+
use crate::blinded_path::payment::{BlindedPaymentPath, PaymentConstraints, PaymentContext, PaymentRelay};
17501750
use crate::types::payment::{PaymentPreimage, PaymentSecret};
1751-
use crate::types::features::BlindedHopFeatures;
1751+
use crate::types::features::{BlindedHopFeatures, Bolt12InvoiceFeatures};
17521752
use super::{FinalOnionHopData, TrampolineOnionPacket};
17531753

17541754
#[allow(unused_imports)]
@@ -1836,9 +1836,21 @@ mod fuzzy_internal_msgs {
18361836
/// The value, in msat, of the payment after this hop's fee is deducted.
18371837
amt_to_forward: u64,
18381838
outgoing_cltv_value: u32,
1839-
/// The node id to which the trampoline node must find a route
1839+
/// The node id to which the trampoline node must find a route.
18401840
outgoing_node_id: PublicKey,
1841-
}
1841+
},
1842+
#[allow(unused)]
1843+
/// This is the last Trampoline hop, whereupon the Trampoline forward mechanism is exited,
1844+
/// and payment data is relayed using non-Trampoline blinded hops
1845+
LegacyBlindedPathEntry {
1846+
/// The value, in msat, of the payment after this hop's fee is deducted.
1847+
amt_to_forward: u64,
1848+
outgoing_cltv_value: u32,
1849+
/// List of blinded path options the last trampoline hop may choose to route through.
1850+
payment_paths: Vec<BlindedPaymentPath>,
1851+
/// If applicable, features of the BOLT12 invoice being paid.
1852+
invoice_features: Option<Bolt12InvoiceFeatures>,
1853+
},
18421854
}
18431855

18441856
pub struct DecodedOnionErrorPacket {
@@ -2763,7 +2775,20 @@ impl Writeable for OutboundTrampolinePayload {
27632775
(4, HighZeroBytesDroppedBigSize(*outgoing_cltv_value), required),
27642776
(14, outgoing_node_id, required)
27652777
});
2766-
}
2778+
},
2779+
Self::LegacyBlindedPathEntry { amt_to_forward, outgoing_cltv_value, payment_paths, invoice_features } => {
2780+
let mut blinded_path_serialization: Vec<u8> = Vec::with_capacity(2048);
2781+
for current_payment_path in payment_paths {
2782+
current_payment_path.inner_blinded_path().write(&mut blinded_path_serialization)?;
2783+
current_payment_path.payinfo.write(&mut blinded_path_serialization)?;
2784+
}
2785+
_encode_varint_length_prefixed_tlv!(w, {
2786+
(2, HighZeroBytesDroppedBigSize(*amt_to_forward), required),
2787+
(4, HighZeroBytesDroppedBigSize(*outgoing_cltv_value), required),
2788+
(21, invoice_features.as_ref().map(|m| WithoutLength(m)), option),
2789+
(22, WithoutLength(&blinded_path_serialization), required)
2790+
});
2791+
},
27672792
}
27682793
Ok(())
27692794
}

0 commit comments

Comments
 (0)