diff --git a/kate/recovery/src/com.rs b/kate/recovery/src/com.rs index 32858dee..b661b298 100644 --- a/kate/recovery/src/com.rs +++ b/kate/recovery/src/com.rs @@ -4,13 +4,16 @@ use dusk_plonk::{fft::EvaluationDomain, prelude::BlsScalar}; use num::ToPrimitive; use rand::seq::SliceRandom; use std::{ - collections::{BTreeSet, HashMap}, + collections::{HashMap, HashSet}, convert::TryFrom, iter::FromIterator, }; use thiserror::Error; -use crate::{config, data, index, matrix}; +use crate::{ + config::{self, CHUNK_SIZE}, + data, index, matrix, +}; #[derive(Debug, Error)] pub enum ReconstructionError { @@ -36,7 +39,7 @@ pub enum ReconstructionError { /// Function panics if factor is above 1.0. pub fn columns_positions( dimensions: &matrix::Dimensions, - positions: Vec, + positions: &[matrix::Position], factor: f64, ) -> Vec { assert!(factor <= 1.0); @@ -47,7 +50,9 @@ pub fn columns_positions( let rng = &mut rand::thread_rng(); - BTreeSet::from_iter(positions.iter().map(|position| position.col)) + let columns: HashSet = HashSet::from_iter(positions.iter().map(|position| position.col)); + + columns .into_iter() .map(|col| dimensions.col_positions(col)) .flat_map(|col| col.choose_multiple(rng, cells).cloned().collect::>()) @@ -158,10 +163,17 @@ pub fn reconstruct_extrinsics( unflatten_padded_data(ranges, data).map_err(ReconstructionError::DataDecodingError) } +/// Reconstructs columns for given cells. +/// +/// # Arguments +/// +/// * `dimensions` - Extended matrix dimensions +/// * `cells` - Cells from required columns, at least 50% cells per column pub fn reconstruct_columns( dimensions: &matrix::Dimensions, - cells: Vec, -) -> Result)>, ReconstructionError> { + cells: &[data::Cell], +) -> Result>, ReconstructionError> { + let cells: Vec = cells.iter().cloned().map(Into::into).collect::>(); let columns = map_cells(dimensions, cells)?; columns @@ -176,8 +188,8 @@ pub fn reconstruct_columns( let column = reconstruct_column(dimensions.extended_rows(), &cells) .map_err(ReconstructionError::ColumnReconstructionError)? .iter() - .flat_map(BlsScalar::to_bytes) - .collect::>(); + .map(BlsScalar::to_bytes) + .collect::>(); Ok((col, column)) })