Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Leouarz committed Apr 10, 2024
1 parent 763ae9f commit 288925f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
23 changes: 15 additions & 8 deletions core/src/data_lookup/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion core/src/data_lookup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ 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(),
is_error: false,
}
}

/// This function is only used when something has gone wrong during header extension building
pub fn new_error() -> Self {
Self {
index: Vec::new(),
Expand All @@ -139,6 +140,10 @@ impl TryFrom<CompactDataLookup> for DataLookup {
type Error = Error;

fn try_from(compacted: CompactDataLookup) -> Result<Self, Self::Error> {
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(
Expand Down

0 comments on commit 288925f

Please sign in to comment.