File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed
lightning/src/blinded_path Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -179,24 +179,25 @@ impl Writeable for Padding {
179179}
180180
181181
182- /// A wrapper struct that stores the largest packet size for the given [`BlindedPath`].
182+ /// A wrapper struct that stores the largest packet size for a [`BlindedPath`].
183183/// This helps us calculate the appropriate padding size for the tlvs when writing them.
184- pub struct WithPadding < T : Writeable > {
184+ pub ( super ) struct WithPadding < T : Writeable > {
185185 /// Length of the packet with the largest size in the [`BlindedPath`].
186- pub ( crate ) max_length : usize ,
186+ pub ( super ) max_length : usize ,
187187 /// The current packet's TLVs.
188- pub ( crate ) tlvs : T ,
188+ pub ( super ) tlvs : T ,
189189}
190190
191191impl < T : Writeable > Writeable for WithPadding < T > {
192192 fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
193- let length = self . max_length . saturating_sub ( self . tlvs . serialized_length ( ) ) ;
194- let padding = Some ( Padding :: new ( length) ) ;
193+ let length = self . max_length . checked_sub ( self . tlvs . serialized_length ( ) ) ;
194+ debug_assert ! ( length. is_some( ) , "Size of this packet should not be larger than the size of largest packet." ) ;
195+ let padding = Some ( Padding :: new ( length. unwrap ( ) ) ) ;
195196
196197 encode_tlv_stream ! ( writer, {
197198 ( 1 , padding, option)
198199 } ) ;
199200
200201 self . tlvs . write ( writer)
201202 }
202- }
203+ }
You can’t perform that action at this time.
0 commit comments