Merge branch 'gloas-payload-cache' of https://github.com/dknopik/lighthouse into gloas-payload-cache

This commit is contained in:
Eitan Seri-Levi
2026-05-01 03:32:10 +02:00

View File

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