Rename zcash_mmr to zcash_history.

This crate will contain all chain history logic.
This commit is contained in:
Sean Bowe
2020-03-03 18:05:14 -07:00
parent 9379eec1b8
commit 5e1a2f9d3f
11 changed files with 43 additions and 33 deletions

View File

@@ -28,7 +28,7 @@ libc = "0.2"
pairing = { version = "0.15.0", path = "../pairing" }
lazy_static = "1"
rand_core = "0.5.1"
zcash_mmr = { version = "0.1.0", path = "../zcash_history" }
zcash_history = { version = "0.0.1", path = "../zcash_history" }
zcash_primitives = { version = "0.1.0", path = "../zcash_primitives" }
zcash_proofs = { version = "0.1.0", path = "../zcash_proofs" }

View File

@@ -65,7 +65,7 @@ use zcash_proofs::{
sprout,
};
use zcash_mmr::{Entry as MMREntry, NodeData as MMRNodeData, Tree as MMRTree};
use zcash_history::{Entry as MMREntry, NodeData as MMRNodeData, Tree as MMRTree};
#[cfg(test)]
mod tests;
@@ -1173,7 +1173,7 @@ fn construct_mmr_tree(
// Indices of provided tree nodes, length of p_len+e_len
ni_ptr: *const u32,
// Provided tree nodes data, length of p_len+e_len
n_ptr: *const [c_uchar; zcash_mmr::MAX_ENTRY_SIZE],
n_ptr: *const [c_uchar; zcash_history::MAX_ENTRY_SIZE],
// Peaks count
p_len: size_t,
@@ -1211,17 +1211,17 @@ pub extern "system" fn librustzcash_mmr_append(
// Indices of provided tree nodes, length of p_len
ni_ptr: *const u32,
// Provided tree nodes data, length of p_len
n_ptr: *const [c_uchar; zcash_mmr::MAX_ENTRY_SIZE],
n_ptr: *const [c_uchar; zcash_history::MAX_ENTRY_SIZE],
// Peaks count
p_len: size_t,
// New node pointer
nn_ptr: *const [u8; zcash_mmr::MAX_NODE_DATA_SIZE],
nn_ptr: *const [u8; zcash_history::MAX_NODE_DATA_SIZE],
// Return of root commitment
rt_ret: *mut [u8; 32],
// Return buffer for appended leaves, should be pre-allocated of ceiling(log2(t_len)) length
buf_ret: *mut [c_uchar; zcash_mmr::MAX_NODE_DATA_SIZE],
buf_ret: *mut [c_uchar; zcash_history::MAX_NODE_DATA_SIZE],
) -> u32 {
let new_node_bytes: &[u8; zcash_mmr::MAX_NODE_DATA_SIZE] = unsafe {
let new_node_bytes: &[u8; zcash_history::MAX_NODE_DATA_SIZE] = unsafe {
match nn_ptr.as_ref() {
Some(r) => r,
None => {
@@ -1283,7 +1283,7 @@ pub extern "system" fn librustzcash_mmr_delete(
// Indices of provided tree nodes, length of p_len+e_len
ni_ptr: *const u32,
// Provided tree nodes data, length of p_len+e_len
n_ptr: *const [c_uchar; zcash_mmr::MAX_ENTRY_SIZE],
n_ptr: *const [c_uchar; zcash_history::MAX_ENTRY_SIZE],
// Peaks count
p_len: size_t,
// Extra nodes loaded (for deletion) count
@@ -1319,10 +1319,10 @@ pub extern "system" fn librustzcash_mmr_delete(
#[no_mangle]
pub extern "system" fn librustzcash_mmr_hash_node(
cbranch: u32,
n_ptr: *const [u8; zcash_mmr::MAX_NODE_DATA_SIZE],
n_ptr: *const [u8; zcash_history::MAX_NODE_DATA_SIZE],
h_ret: *mut [u8; 32],
) -> u32 {
let node_bytes: &[u8; zcash_mmr::MAX_NODE_DATA_SIZE] = unsafe {
let node_bytes: &[u8; zcash_history::MAX_NODE_DATA_SIZE] = unsafe {
match n_ptr.as_ref() {
Some(r) => r,
None => return 1,

View File

@@ -1,4 +1,4 @@
use zcash_mmr::{Entry, EntryLink, NodeData};
use zcash_history::{Entry, EntryLink, NodeData};
use crate::{librustzcash_mmr_append, librustzcash_mmr_delete};
@@ -82,7 +82,7 @@ fn prepare_tree(nodes: &[NodeData]) -> TreeView {
TreeView { peaks, extra }
}
fn preload_tree_append(nodes: &[NodeData]) -> (Vec<u32>, Vec<[u8; zcash_mmr::MAX_ENTRY_SIZE]>) {
fn preload_tree_append(nodes: &[NodeData]) -> (Vec<u32>, Vec<[u8; zcash_history::MAX_ENTRY_SIZE]>) {
assert!(!nodes.is_empty());
let tree_view = prepare_tree(nodes);
@@ -91,7 +91,7 @@ fn preload_tree_append(nodes: &[NodeData]) -> (Vec<u32>, Vec<[u8; zcash_mmr::MAX
let mut bytes = Vec::new();
for (idx, entry) in tree_view.peaks.into_iter() {
let mut buf = [0u8; zcash_mmr::MAX_ENTRY_SIZE];
let mut buf = [0u8; zcash_history::MAX_ENTRY_SIZE];
entry
.write(&mut &mut buf[..])
.expect("Cannot fail if enough buffer length");
@@ -105,7 +105,7 @@ fn preload_tree_append(nodes: &[NodeData]) -> (Vec<u32>, Vec<[u8; zcash_mmr::MAX
// also returns number of peaks
fn preload_tree_delete(
nodes: &[NodeData],
) -> (Vec<u32>, Vec<[u8; zcash_mmr::MAX_ENTRY_SIZE]>, usize) {
) -> (Vec<u32>, Vec<[u8; zcash_history::MAX_ENTRY_SIZE]>, usize) {
assert!(!nodes.is_empty());
let tree_view = prepare_tree(nodes);
@@ -120,7 +120,7 @@ fn preload_tree_delete(
.into_iter()
.chain(tree_view.extra.into_iter())
{
let mut buf = [0u8; zcash_mmr::MAX_ENTRY_SIZE];
let mut buf = [0u8; zcash_history::MAX_ENTRY_SIZE];
entry
.write(&mut &mut buf[..])
.expect("Cannot fail if enough buffer length");
@@ -136,7 +136,7 @@ fn load_nodes(bytes: &'static [u8]) -> Vec<NodeData> {
let mut cursor = std::io::Cursor::new(bytes);
while (cursor.position() as usize) < bytes.len() {
let node_data =
zcash_mmr::NodeData::read(0, &mut cursor).expect("Statically checked to be correct");
zcash_history::NodeData::read(0, &mut cursor).expect("Statically checked to be correct");
res.push(node_data);
}
@@ -150,9 +150,9 @@ fn append() {
let mut rt_ret = [0u8; 32];
let mut buf_ret = Vec::<[u8; zcash_mmr::MAX_NODE_DATA_SIZE]>::with_capacity(32);
let mut buf_ret = Vec::<[u8; zcash_history::MAX_NODE_DATA_SIZE]>::with_capacity(32);
let mut new_node_data = [0u8; zcash_mmr::MAX_NODE_DATA_SIZE];
let mut new_node_data = [0u8; zcash_history::MAX_NODE_DATA_SIZE];
let new_node = NodeData {
consensus_branch_id: 0,
subtree_commitment: [0u8; 32],