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..1c7a0389c3 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,37 @@ 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 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 +41,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);