Skip to content

Commit 3875c52

Browse files
committed
f use bits 6 and 7 as joint descriptions of additional data length
1 parent 8ddc51e commit 3875c52

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

lightning-rapid-gossip-sync/src/processing.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,25 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
183183
node_modifications.insert(current_pubkey, synthetic_node_announcement);
184184
}
185185

186-
let has_additional_data = additional_data_marker > 0;
187186
if additional_data_marker > 0 {
188-
// 1 => u8, 2 => u16, 3 => u32
189-
let _length_prefix_bytes = 1u8 << (additional_data_marker - 1);
190-
// let _length_prefix = match length_prefix_bytes {
191-
//
192-
// };
193-
}
187+
let additional_byte_count: u64 = match additional_data_marker {
188+
1 => {
189+
u8::read(read_cursor)? as u64
190+
}
191+
2 => {
192+
u16::read(read_cursor)? as u64
193+
}
194+
3 => {
195+
u32::read(read_cursor)? as u64
196+
}
197+
_ => {
198+
return Err(DecodeError::BadLengthDescriptor.into());
199+
}
200+
};
194201

195-
if has_additional_data {
196-
// forwards compatibility
197-
let _additional_data: Vec<u8> = Readable::read(read_cursor)?;
202+
let mut additional_data_reader = FixedLengthReader::new(&mut read_cursor, additional_byte_count);
203+
let mut additional_data = Vec::new();
204+
additional_data_reader.read_to_end(&mut additional_data)?;
198205
}
199206
}
200207
} else {

0 commit comments

Comments
 (0)