mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 20:57:10 +00:00
pending payload cache: restore vec-backed column shape
This commit is contained in:
@@ -1,28 +1,41 @@
|
|||||||
use kzg::KzgProof;
|
use kzg::KzgProof;
|
||||||
use ssz_types::VariableList;
|
use ssz_types::VariableList;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{Cell, ColumnIndex, DataColumnSidecar, DataColumnSidecarGloas, EthSpec, Hash256, Slot};
|
use types::{Cell, ColumnIndex, DataColumnSidecar, DataColumnSidecarGloas, EthSpec, Hash256, Slot};
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone)]
|
||||||
pub struct PendingColumn<E: EthSpec> {
|
pub struct PendingColumn<E: EthSpec> {
|
||||||
cells: HashMap<usize, (Cell<E>, KzgProof)>,
|
cells: Vec<Option<(Cell<E>, KzgProof)>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<E: EthSpec> Default for PendingColumn<E> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self { cells: Vec::new() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: EthSpec> PendingColumn<E> {
|
impl<E: EthSpec> PendingColumn<E> {
|
||||||
|
pub fn new_with_capacity(_blobs: usize) -> Self {
|
||||||
|
Self { cells: Vec::new() }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, index: usize, cell: &Cell<E>, proof: &KzgProof) {
|
pub fn insert(&mut self, index: usize, cell: &Cell<E>, proof: &KzgProof) {
|
||||||
self.cells
|
if let Some(existing_cell) = self.cells.get_mut(index)
|
||||||
.entry(index)
|
&& existing_cell.is_none()
|
||||||
.or_insert_with(|| (cell.clone(), *proof));
|
{
|
||||||
|
*existing_cell = Some((cell.clone(), *proof));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cell_matches(&self, index: usize, cell: &Cell<E>, proof: &KzgProof) -> Option<bool> {
|
pub fn cell_matches(&self, index: usize, cell: &Cell<E>, proof: &KzgProof) -> Option<bool> {
|
||||||
let (c, p) = self.cells.get(&index)?;
|
self.cells
|
||||||
Some(c == cell && p == proof)
|
.get(index)?
|
||||||
|
.as_ref()
|
||||||
|
.map(|(c, p)| c == cell && p == proof)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_complete(&self, blob_count: usize) -> bool {
|
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(
|
pub fn try_to_sidecar(
|
||||||
@@ -32,11 +45,17 @@ impl<E: EthSpec> PendingColumn<E> {
|
|||||||
beacon_block_root: Hash256,
|
beacon_block_root: Hash256,
|
||||||
blob_count: usize,
|
blob_count: usize,
|
||||||
) -> Option<Arc<DataColumnSidecar<E>>> {
|
) -> Option<Arc<DataColumnSidecar<E>>> {
|
||||||
let mut column = Vec::with_capacity(blob_count);
|
if self.cells.len() != blob_count {
|
||||||
let mut kzg_proofs = Vec::with_capacity(blob_count);
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
for i in 0..blob_count {
|
let mut column = Vec::with_capacity(blob_count);
|
||||||
let (cell, proof) = self.cells.get(&i)?;
|
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
|
// TODO(gloas): we likely want to go and arc all cells
|
||||||
column.push(cell.clone());
|
column.push(cell.clone());
|
||||||
kzg_proofs.push(*proof);
|
kzg_proofs.push(*proof);
|
||||||
|
|||||||
@@ -81,10 +81,11 @@ impl<E: EthSpec> PendingComponents<E> {
|
|||||||
) -> Result<(), AvailabilityCheckError> {
|
) -> Result<(), AvailabilityCheckError> {
|
||||||
for data_column in kzg_verified_data_columns {
|
for data_column in kzg_verified_data_columns {
|
||||||
let data_column = data_column.as_data_column();
|
let data_column = data_column.as_data_column();
|
||||||
|
let num_blobs_expected = self.num_blobs_expected();
|
||||||
let col = self
|
let col = self
|
||||||
.verified_data_columns
|
.verified_data_columns
|
||||||
.entry(*data_column.index())
|
.entry(*data_column.index())
|
||||||
.or_default();
|
.or_insert_with(|| PendingColumn::new_with_capacity(num_blobs_expected));
|
||||||
for (cell_idx, (cell, proof)) in data_column
|
for (cell_idx, (cell, proof)) in data_column
|
||||||
.column()
|
.column()
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
Reference in New Issue
Block a user