Skip to content

Commit

Permalink
Make cache internally optional again.
Browse files Browse the repository at this point in the history
  • Loading branch information
porcuquine committed Sep 25, 2020
1 parent 3cfbf0a commit db08d49
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
22 changes: 16 additions & 6 deletions storage-proofs/porep/src/stacked/circuit/create_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod tests {
use crate::stacked::vanilla::{create_label, StackedBucketGraph, EXP_DEGREE, TOTAL_PARENTS};

#[test]
fn test_create_label_multi() {
fn test_create_label() {
let mut cs = TestConstraintSystem::<Bls12>::new();
let rng = &mut XorShiftRng::from_seed(crate::TEST_SEED);

Expand Down Expand Up @@ -165,17 +165,27 @@ mod tests {
assert_eq!(cs.num_constraints(), 532_025);

let (l1, l2) = data.split_at_mut(size * NODE_SIZE);
// FIXME: Update this test.
create_label::multi::create_label(
&mut graph.parent_cache().unwrap(),
&fr_into_bytes(&id_fr),
create_label::single::create_label_exp(
&graph,
None,
fr_into_bytes(&id_fr),
&*l2,
l1,
layer,
node,
false,
)
.unwrap();

// create_label::single::create_label(
// &graph,
// Some(&mut graph.parent_cache().unwrap()),
// &fr_into_bytes(&id_fr),
// // &*l2,
// l2,
// layer,
// node,
// )
// .unwrap();
let expected_raw = data_at_node(&l1, node).unwrap();
let expected = bytes_into_fr(expected_raw).unwrap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn create_labels<Tree: 'static + MerkleTreeTrait, T: AsRef<[u8]>>(
for node in 0..graph.size() {
create_label(
graph,
parents_cache,
Some(parents_cache),
&replica_id,
&mut layer_labels,
layer,
Expand All @@ -53,7 +53,7 @@ pub fn create_labels<Tree: 'static + MerkleTreeTrait, T: AsRef<[u8]>>(
for node in 0..graph.size() {
create_label_exp(
graph,
parents_cache,
Some(parents_cache),
&replica_id,
&exp_labels,
&mut layer_labels,
Expand Down Expand Up @@ -106,7 +106,7 @@ pub fn create_labels<Tree: 'static + MerkleTreeTrait, T: AsRef<[u8]>>(

pub fn create_label<H: Hasher, T: AsRef<[u8]>>(
graph: &StackedBucketGraph<H>,
cache: &mut ParentCache,
cache: Option<&mut ParentCache>,
replica_id: T,
layer_labels: &mut [u8],
layer_index: usize,
Expand Down Expand Up @@ -143,7 +143,7 @@ pub fn create_label<H: Hasher, T: AsRef<[u8]>>(

pub fn create_label_exp<H: Hasher, T: AsRef<[u8]>>(
graph: &StackedBucketGraph<H>,
cache: &mut ParentCache,
cache: Option<&mut ParentCache>,
replica_id: T,
exp_parents_data: &[u8],
layer_labels: &mut [u8],
Expand Down
28 changes: 22 additions & 6 deletions storage-proofs/porep/src/stacked/vanilla/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,37 @@ where
base_data: &[u8],
exp_data: &[u8],
hasher: Sha256,
cache: &mut ParentCache,
mut cache: Option<&mut ParentCache>,
) -> Result<[u8; 32]> {
let cache_parents = cache.read(node as u32)?;
Ok(self.copy_parents_data_inner_exp(&cache_parents, base_data, exp_data, hasher))
if let Some(ref mut cache) = cache {
let cache_parents = cache.read(node as u32)?;
Ok(self.copy_parents_data_inner_exp(&cache_parents, base_data, exp_data, hasher))
} else {
let mut cache_parents = [0u32; DEGREE];

self.parents(node as usize, &mut cache_parents[..])
.expect("parents failure");
Ok(self.copy_parents_data_inner_exp(&cache_parents, base_data, exp_data, hasher))
}
}

pub fn copy_parents_data(
&self,
node: u32,
base_data: &[u8],
hasher: Sha256,
cache: &mut ParentCache,
mut cache: Option<&mut ParentCache>,
) -> Result<[u8; 32]> {
let cache_parents = cache.read(node as u32)?;
Ok(self.copy_parents_data_inner(&cache_parents, base_data, hasher))
if let Some(ref mut cache) = cache {
let cache_parents = cache.read(node as u32)?;
Ok(self.copy_parents_data_inner(&cache_parents, base_data, hasher))
} else {
let mut cache_parents = [0u32; DEGREE];

self.parents(node as usize, &mut cache_parents[..])
.expect("parents failure");
Ok(self.copy_parents_data_inner(&cache_parents, base_data, hasher))
}
}

fn copy_parents_data_inner_exp(
Expand Down

0 comments on commit db08d49

Please sign in to comment.