diff --git a/core/src/data_lookup/compact.rs b/core/src/data_lookup/compact.rs index 99a3322..86f8f23 100644 --- a/core/src/data_lookup/compact.rs +++ b/core/src/data_lookup/compact.rs @@ -42,14 +42,21 @@ pub struct CompactDataLookup { impl CompactDataLookup { pub fn from_expanded(lookup: &DataLookup) -> Self { - let index = lookup - .index - .iter() - .filter(|(id, _)| *id != AppId(0)) - .map(|(id, range)| DataLookupItem::new(*id, range.start)) - .collect(); - let size = lookup.index.last().map_or(0, |(_, range)| range.end); - Self { size, index } + if lookup.is_error { + CompactDataLookup { + size: u32::MAX, + index: Vec::default(), + } + } else { + let index = lookup + .index + .iter() + .filter(|(id, _)| *id != AppId(0)) + .map(|(id, range)| DataLookupItem::new(*id, range.start)) + .collect(); + let size = lookup.index.last().map_or(0, |(_, range)| range.end); + Self { size, index } + } } } diff --git a/core/src/data_lookup/mod.rs b/core/src/data_lookup/mod.rs index 7cb91f4..256ad13 100644 --- a/core/src/data_lookup/mod.rs +++ b/core/src/data_lookup/mod.rs @@ -119,7 +119,7 @@ impl DataLookup { }) } - /// This function is only used when something has gone wrong during header extension building + /// This function is used a block contains no data submissions. pub fn new_empty() -> Self { Self { index: Vec::new(), @@ -127,6 +127,7 @@ impl DataLookup { } } + /// This function is only used when something has gone wrong during header extension building pub fn new_error() -> Self { Self { index: Vec::new(), @@ -139,6 +140,10 @@ impl TryFrom for DataLookup { type Error = Error; fn try_from(compacted: CompactDataLookup) -> Result { + if compacted.size == u32::MAX { + return Ok(DataLookup::new_error()); + } + let mut offset = 0; let mut prev_id = AppId(0); let mut index = Vec::with_capacity(