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
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
11 changed files with 43 additions and 33 deletions

6
Cargo.lock generated
View File

@ -426,7 +426,7 @@ dependencies = [
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
"pairing 0.15.1",
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"zcash_mmr 0.1.0",
"zcash_history 0.0.1",
"zcash_primitives 0.1.0",
"zcash_proofs 0.1.0",
]
@ -866,8 +866,8 @@ dependencies = [
]
[[package]]
name = "zcash_mmr"
version = "0.1.0"
name = "zcash_history"
version = "0.0.1"
dependencies = [
"assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bigint 4.4.1 (registry+https://github.com/rust-lang/crates.io-index)",

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],

View File

@ -1,4 +0,0 @@
language: rust
rust:
- nightly
- stable

14
zcash_history/COPYRIGHT Normal file
View File

@ -0,0 +1,14 @@
Copyrights in the "zcash_history" library are retained by their contributors. No
copyright assignment is required to contribute to the "zcash_history" library.
The "zcash_history" library is licensed under either of
* Apache License, Version 2.0, (see ./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license (see ./LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you, as defined in the Apache-2.0
license, shall be dual licensed as above, without any additional terms or
conditions.

View File

@ -1,6 +1,6 @@
[package]
name = "zcash_mmr"
version = "0.1.0"
name = "zcash_history"
version = "0.0.1"
authors = ["NikVolf <nikvolf@gmail.com>"]
edition = "2018"

View File

@ -1,4 +1,4 @@
# zcash_mmr
# zcash_history
Special implementation of Merkle mountain ranges (MMR) for Zcash!
@ -14,7 +14,7 @@ The main design goals of this MMR implementation are
# License
`zcash_mmr` is distributed under the terms of both the MIT
`zcash_history` is distributed under the terms of both the MIT
license and the Apache License (Version 2.0), at your choice.
See LICENSE-APACHE, and LICENSE-MIT for details.
@ -22,5 +22,5 @@ See LICENSE-APACHE, and LICENSE-MIT for details.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in `zcash_mmr` by you, as defined in the Apache-2.0 license, shall be
for inclusion in `zcash_history` by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.

View File

@ -1,4 +1,4 @@
use zcash_mmr:: {NodeData, Tree, Entry, EntryLink};
use zcash_history:: {NodeData, Tree, Entry, EntryLink};
pub struct NodeDataIterator {
return_stack: Vec<NodeData>,

View File

@ -1,4 +1,4 @@
use zcash_mmr::{Entry, EntryLink, NodeData, Tree};
use zcash_history::{Entry, EntryLink, NodeData, Tree};
#[path= "lib/shared.rs"]
mod share;

View File

@ -1,4 +1,4 @@
//! MMR library for Zcash
//! Chain history library for Zcash
//!
//! To be used in zebra and via FFI bindings in zcashd
#![warn(missing_docs)]