Fix failing vec hashing test
This commit is contained in:
parent
0c0eebd774
commit
0bdd61e564
@ -195,15 +195,18 @@ impl TreeHashCache {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn chunk_equals(&mut self, chunk: usize, other: &[u8]) -> Result<bool, Error> {
|
pub fn get_chunk(&self, chunk: usize) -> Result<&[u8], Error> {
|
||||||
let start = chunk * BYTES_PER_CHUNK;
|
let start = chunk * BYTES_PER_CHUNK;
|
||||||
let end = start + BYTES_PER_CHUNK;
|
let end = start + BYTES_PER_CHUNK;
|
||||||
|
|
||||||
Ok(self
|
Ok(self
|
||||||
.cache
|
.cache
|
||||||
.get(start..end)
|
.get(start..end)
|
||||||
.ok_or_else(|| Error::NoModifiedFieldForChunk(chunk))?
|
.ok_or_else(|| Error::NoModifiedFieldForChunk(chunk))?)
|
||||||
== other)
|
}
|
||||||
|
|
||||||
|
pub fn chunk_equals(&mut self, chunk: usize, other: &[u8]) -> Result<bool, Error> {
|
||||||
|
Ok(self.get_chunk(chunk)? == other)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn changed(&self, chunk: usize) -> Result<bool, Error> {
|
pub fn changed(&self, chunk: usize) -> Result<bool, Error> {
|
||||||
@ -218,15 +221,11 @@ impl TreeHashCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn hash_children(&self, children: (&usize, &usize)) -> Result<Vec<u8>, Error> {
|
pub fn hash_children(&self, children: (&usize, &usize)) -> Result<Vec<u8>, Error> {
|
||||||
let start = children.0 * BYTES_PER_CHUNK;
|
let mut child_bytes = Vec::with_capacity(BYTES_PER_CHUNK * 2);
|
||||||
let end = start + BYTES_PER_CHUNK * 2;
|
child_bytes.append(&mut self.get_chunk(*children.0)?.to_vec());
|
||||||
|
child_bytes.append(&mut self.get_chunk(*children.1)?.to_vec());
|
||||||
|
|
||||||
let children = &self
|
Ok(hash(&child_bytes))
|
||||||
.cache
|
|
||||||
.get(start..end)
|
|
||||||
.ok_or_else(|| Error::NoChildrenForHashing((*children.0, *children.1)))?;
|
|
||||||
|
|
||||||
Ok(hash(children))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_merkle_tree(self) -> Vec<u8> {
|
pub fn into_merkle_tree(self) -> Vec<u8> {
|
||||||
|
@ -133,14 +133,13 @@ where
|
|||||||
// The item existed in the previous list and exsits in the current list.
|
// The item existed in the previous list and exsits in the current list.
|
||||||
(Some(old), Some(new)) => {
|
(Some(old), Some(new)) => {
|
||||||
new.cached_hash_tree_root(old, cache, *start_chunk)?;
|
new.cached_hash_tree_root(old, cache, *start_chunk)?;
|
||||||
},
|
}
|
||||||
// The item didn't exist in the old list and doesn't exist in the new list,
|
// The item didn't exist in the old list and doesn't exist in the new list,
|
||||||
// nothing to do.
|
// nothing to do.
|
||||||
(None, None) => {},
|
(None, None) => {}
|
||||||
_ => panic!("variable sized lists not implemented")
|
_ => panic!("variable sized lists not implemented"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// this thing
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user