@@ -2777,16 +2777,21 @@ impl Writeable for OutboundTrampolinePayload {
2777
2777
} ) ;
2778
2778
} ,
2779
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
- }
2780
+ let mut blinded_path_serialization = [ 0u8 ; 2048 ] ; // Fixed-length buffer on the stack
2781
+ let serialization_length = {
2782
+ let mut blinded_path_slice = & mut blinded_path_serialization[ ..] ;
2783
+ for current_payment_path in payment_paths {
2784
+ current_payment_path. inner_blinded_path ( ) . write ( & mut blinded_path_slice) ?;
2785
+ current_payment_path. payinfo . write ( & mut blinded_path_slice) ?;
2786
+ }
2787
+ 2048 - blinded_path_slice. len ( )
2788
+ } ;
2789
+ let blinded_path_serialization = & blinded_path_serialization[ ..serialization_length] ;
2785
2790
_encode_varint_length_prefixed_tlv ! ( w, {
2786
2791
( 2 , HighZeroBytesDroppedBigSize ( * amt_to_forward) , required) ,
2787
2792
( 4 , HighZeroBytesDroppedBigSize ( * outgoing_cltv_value) , required) ,
2788
2793
( 21 , invoice_features. as_ref( ) . map( |m| WithoutLength ( m) ) , option) ,
2789
- ( 22 , WithoutLength ( & blinded_path_serialization) , required)
2794
+ ( 22 , WithoutLength ( blinded_path_serialization) , required)
2790
2795
} ) ;
2791
2796
} ,
2792
2797
}
0 commit comments