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 {
179
179
}
180
180
181
181
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`].
183
183
/// 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 > {
185
185
/// Length of the packet with the largest size in the [`BlindedPath`].
186
- pub ( crate ) max_length : usize ,
186
+ pub ( super ) max_length : usize ,
187
187
/// The current packet's TLVs.
188
- pub ( crate ) tlvs : T ,
188
+ pub ( super ) tlvs : T ,
189
189
}
190
190
191
191
impl < T : Writeable > Writeable for WithPadding < T > {
192
192
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 ( ) ) ) ;
195
196
196
197
encode_tlv_stream ! ( writer, {
197
198
( 1 , padding, option)
198
199
} ) ;
199
200
200
201
self . tlvs . write ( writer)
201
202
}
202
- }
203
+ }
You can’t perform that action at this time.
0 commit comments