diff --git a/beacon_node/beacon_chain/src/pending_payload_cache/pending_column.rs b/beacon_node/beacon_chain/src/pending_payload_cache/pending_column.rs index 5ace1e25b2..a69bd22d34 100644 --- a/beacon_node/beacon_chain/src/pending_payload_cache/pending_column.rs +++ b/beacon_node/beacon_chain/src/pending_payload_cache/pending_column.rs @@ -1,28 +1,41 @@ use kzg::KzgProof; use ssz_types::VariableList; -use std::collections::HashMap; use std::sync::Arc; use types::{Cell, ColumnIndex, DataColumnSidecar, DataColumnSidecarGloas, EthSpec, Hash256, Slot}; -#[derive(Clone, Default)] +#[derive(Clone)] pub struct PendingColumn { - cells: HashMap, KzgProof)>, + cells: Vec, KzgProof)>>, +} + +impl Default for PendingColumn { + fn default() -> Self { + Self { cells: Vec::new() } + } } impl PendingColumn { + pub fn new_with_capacity(_blobs: usize) -> Self { + Self { cells: Vec::new() } + } + pub fn insert(&mut self, index: usize, cell: &Cell, proof: &KzgProof) { - self.cells - .entry(index) - .or_insert_with(|| (cell.clone(), *proof)); + if let Some(existing_cell) = self.cells.get_mut(index) + && existing_cell.is_none() + { + *existing_cell = Some((cell.clone(), *proof)); + } } pub fn cell_matches(&self, index: usize, cell: &Cell, proof: &KzgProof) -> Option { - let (c, p) = self.cells.get(&index)?; - Some(c == cell && p == proof) + self.cells + .get(index)? + .as_ref() + .map(|(c, p)| c == cell && p == proof) } pub fn is_complete(&self, blob_count: usize) -> bool { - (0..blob_count).all(|i| self.cells.contains_key(&i)) + self.cells.len() == blob_count && self.cells.iter().all(|cell| cell.is_some()) } pub fn try_to_sidecar( @@ -32,11 +45,17 @@ impl PendingColumn { beacon_block_root: Hash256, blob_count: usize, ) -> Option>> { - let mut column = Vec::with_capacity(blob_count); - let mut kzg_proofs = Vec::with_capacity(blob_count); + if self.cells.len() != blob_count { + return None; + } - for i in 0..blob_count { - let (cell, proof) = self.cells.get(&i)?; + let mut column = Vec::with_capacity(blob_count); + let mut kzg_proofs = Vec::with_capacity(self.cells.len()); + + for cell in self.cells.iter() { + let Some((cell, proof)) = cell else { + return None; + }; // TODO(gloas): we likely want to go and arc all cells column.push(cell.clone()); kzg_proofs.push(*proof); diff --git a/beacon_node/beacon_chain/src/pending_payload_cache/pending_components.rs b/beacon_node/beacon_chain/src/pending_payload_cache/pending_components.rs index de351cd527..d3b4e3007b 100644 --- a/beacon_node/beacon_chain/src/pending_payload_cache/pending_components.rs +++ b/beacon_node/beacon_chain/src/pending_payload_cache/pending_components.rs @@ -81,10 +81,11 @@ impl PendingComponents { ) -> Result<(), AvailabilityCheckError> { for data_column in kzg_verified_data_columns { let data_column = data_column.as_data_column(); + let num_blobs_expected = self.num_blobs_expected(); let col = self .verified_data_columns .entry(*data_column.index()) - .or_default(); + .or_insert_with(|| PendingColumn::new_with_capacity(num_blobs_expected)); for (cell_idx, (cell, proof)) in data_column .column() .iter()