Merge remote-tracking branch 'upstream/master' into add_librustzcash_types
This commit is contained in:
commit
9c0c9aa245
|
@ -23,7 +23,7 @@ jobs:
|
|||
- uses: actions/checkout@v3
|
||||
# Build benchmarks to prevent bitrot
|
||||
- name: Build benchmarks
|
||||
run: cargo build --workspace --benches
|
||||
run: cargo build --workspace --benches --all-features
|
||||
|
||||
doc-links:
|
||||
name: Intra-doc links
|
||||
|
|
|
@ -2,4 +2,5 @@
|
|||
members = [
|
||||
"incrementalmerkletree",
|
||||
"bridgetree",
|
||||
"shardtree",
|
||||
]
|
||||
|
|
|
@ -185,7 +185,7 @@ impl<H> MerkleBridge<H> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, H: Hashable + Ord + Clone + 'a> MerkleBridge<H> {
|
||||
impl<'a, H: Hashable + Clone + Ord + 'a> MerkleBridge<H> {
|
||||
/// Constructs a new bridge to follow this one. If `mark_current_leaf` is true, the successor
|
||||
/// will track the information necessary to create a witness for the leaf most
|
||||
/// recently appended to this bridge's frontier.
|
||||
|
@ -363,8 +363,7 @@ impl<C> Checkpoint<C> {
|
|||
}
|
||||
}
|
||||
|
||||
/// The unique identifier for the checkpoint, which is simply an automatically incrementing
|
||||
/// index over all checkpoints that have ever been created in the history of the tree.
|
||||
/// The unique identifier for the checkpoint.
|
||||
pub fn id(&self) -> &C {
|
||||
&self.id
|
||||
}
|
||||
|
@ -533,7 +532,7 @@ impl<H, C, const DEPTH: u8> BridgeTree<H, C, DEPTH> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<H: Hashable + Ord + Clone, C: Clone + Ord, const DEPTH: u8> BridgeTree<H, C, DEPTH> {
|
||||
impl<H: Hashable + Clone + Ord, C: Clone + Ord, const DEPTH: u8> BridgeTree<H, C, DEPTH> {
|
||||
/// Construct a new BridgeTree that will start recording changes from the state of
|
||||
/// the specified frontier.
|
||||
pub fn from_frontier(max_checkpoints: usize, frontier: NonEmptyFrontier<H>, checkpoint_id: C) -> Self {
|
||||
|
@ -1005,7 +1004,7 @@ mod tests {
|
|||
Hashable,
|
||||
};
|
||||
|
||||
impl<H: Hashable + Ord + Clone, const DEPTH: u8> testing::Tree<H, usize>
|
||||
impl<H: Hashable + Clone + Ord, const DEPTH: u8> testing::Tree<H, usize>
|
||||
for BridgeTree<H, usize, DEPTH>
|
||||
{
|
||||
fn append(&mut self, value: H, retention: Retention<usize>) -> bool {
|
||||
|
@ -1088,7 +1087,7 @@ mod tests {
|
|||
max_count: usize,
|
||||
) -> impl Strategy<Value = BridgeTree<G::Value, usize, 8>>
|
||||
where
|
||||
G::Value: Hashable + Ord + Clone + Debug + 'static,
|
||||
G::Value: Hashable + Clone + Ord + Debug + 'static,
|
||||
{
|
||||
proptest::collection::vec(arb_operation(item_gen, 0..max_count), 0..max_count).prop_map(
|
||||
|ops| {
|
||||
|
@ -1207,7 +1206,7 @@ mod tests {
|
|||
}
|
||||
|
||||
// Combined tree tests
|
||||
fn new_combined_tree<H: Hashable + Ord + Clone + Debug>(
|
||||
fn new_combined_tree<H: Hashable + Clone + Ord + Debug>(
|
||||
max_checkpoints: usize,
|
||||
) -> CombinedTree<H, usize, CompleteTree<H, usize, 4>, BridgeTree<H, usize, 4>> {
|
||||
CombinedTree::new(
|
||||
|
|
|
@ -193,7 +193,7 @@ impl Level {
|
|||
// TODO: replace with an instance for `Step<Level>` once `step_trait`
|
||||
// is stabilized
|
||||
pub fn iter_to(self, other: Level) -> impl Iterator<Item = Self> {
|
||||
(self.0..other.0).into_iter().map(Level)
|
||||
(self.0..other.0).map(Level)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,17 +65,16 @@ pub trait Tree<H, C> {
|
|||
|
||||
/// Creates a new checkpoint for the current tree state.
|
||||
///
|
||||
/// It is valid to have multiple checkpoints for the same tree state, and
|
||||
/// each `rewind` call will remove a single checkpoint. Returns `false`
|
||||
/// if the checkpoint identifier provided is less than or equal to the
|
||||
/// maximum checkpoint identifier observed.
|
||||
/// It is valid to have multiple checkpoints for the same tree state, and each `rewind` call
|
||||
/// will remove a single checkpoint. Returns `false` if the checkpoint identifier provided is
|
||||
/// less than or equal to the maximum checkpoint identifier observed.
|
||||
fn checkpoint(&mut self, id: C) -> bool;
|
||||
|
||||
/// Rewinds the tree state to the previous checkpoint, and then removes
|
||||
/// that checkpoint record. If there are multiple checkpoints at a given
|
||||
/// tree state, the tree state will not be altered until all checkpoints
|
||||
/// at that tree state have been removed using `rewind`. This function
|
||||
/// return false and leave the tree unmodified if no checkpoints exist.
|
||||
/// Rewinds the tree state to the previous checkpoint, and then removes that checkpoint record.
|
||||
///
|
||||
/// If there are multiple checkpoints at a given tree state, the tree state will not be altered
|
||||
/// until all checkpoints at that tree state have been removed using `rewind`. This function
|
||||
/// will return false and leave the tree unmodified if no checkpoints exist.
|
||||
fn rewind(&mut self) -> bool;
|
||||
}
|
||||
|
||||
|
@ -288,7 +287,10 @@ pub fn check_operations<H: Hashable + Ord + Clone, C: Clone, T: Tree<H, C>>(
|
|||
tree_checkpoints.push(tree_size);
|
||||
}
|
||||
} else {
|
||||
prop_assert_eq!(tree_size, 1 << tree.depth());
|
||||
prop_assert_eq!(
|
||||
tree_size,
|
||||
tree.current_position().map_or(0, |p| usize::from(p) + 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
CurrentPosition => {
|
||||
|
@ -375,7 +377,7 @@ pub fn compute_root_from_witness<H: Hashable>(value: H, position: Position, path
|
|||
// Types and utilities for cross-verification property tests
|
||||
//
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CombinedTree<H, C, I: Tree<H, C>, E: Tree<H, C>> {
|
||||
inefficient: I,
|
||||
efficient: E,
|
||||
|
@ -498,9 +500,37 @@ pub fn check_root_hashes<T: Tree<String, usize>, F: Fn(usize) -> T>(new_tree: F)
|
|||
assert_eq!(t.root(0).unwrap(), "aaaa____________");
|
||||
}
|
||||
|
||||
pub fn check_witnesses<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) -> T>(new_tree: F) {
|
||||
/// This test expects a depth-4 tree and verifies that the tree reports itself as full after 2^4
|
||||
/// appends.
|
||||
pub fn check_append<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) -> T>(new_tree: F) {
|
||||
use Retention::*;
|
||||
|
||||
let mut tree = new_tree(100);
|
||||
tree.append("a".to_string(), Retention::Marked);
|
||||
assert_eq!(tree.depth(), 4);
|
||||
|
||||
// 16 appends should succeed
|
||||
for i in 0..16 {
|
||||
assert!(tree.append(i.to_string(), Ephemeral));
|
||||
assert_eq!(tree.current_position(), Some(Position::from(i)));
|
||||
}
|
||||
|
||||
// 17th append should fail
|
||||
assert!(!tree.append("16".to_string(), Ephemeral));
|
||||
|
||||
// The following checks a condition on state restoration in the case that an append fails.
|
||||
// We want to ensure that a failed append does not cause a loss of information.
|
||||
let ops = (0..17)
|
||||
.map(|i| Append(i.to_string(), Ephemeral))
|
||||
.collect::<Vec<_>>();
|
||||
let tree = new_tree(100);
|
||||
check_operations(tree, &ops).unwrap();
|
||||
}
|
||||
|
||||
pub fn check_witnesses<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) -> T>(new_tree: F) {
|
||||
use Retention::*;
|
||||
|
||||
let mut tree = new_tree(100);
|
||||
tree.append("a".to_string(), Marked);
|
||||
assert_eq!(
|
||||
tree.witness(Position::from(0), 0),
|
||||
Some(vec![
|
||||
|
@ -511,7 +541,7 @@ pub fn check_witnesses<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) ->
|
|||
])
|
||||
);
|
||||
|
||||
tree.append("b".to_string(), Retention::Ephemeral);
|
||||
tree.append("b".to_string(), Ephemeral);
|
||||
assert_eq!(
|
||||
tree.witness(0.into(), 0),
|
||||
Some(vec![
|
||||
|
@ -522,7 +552,7 @@ pub fn check_witnesses<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) ->
|
|||
])
|
||||
);
|
||||
|
||||
tree.append("c".to_string(), Retention::Marked);
|
||||
tree.append("c".to_string(), Marked);
|
||||
assert_eq!(
|
||||
tree.witness(Position::from(2), 0),
|
||||
Some(vec![
|
||||
|
@ -533,7 +563,7 @@ pub fn check_witnesses<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) ->
|
|||
])
|
||||
);
|
||||
|
||||
tree.append("d".to_string(), Retention::Ephemeral);
|
||||
tree.append("d".to_string(), Ephemeral);
|
||||
assert_eq!(
|
||||
tree.witness(Position::from(2), 0),
|
||||
Some(vec![
|
||||
|
@ -544,7 +574,7 @@ pub fn check_witnesses<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) ->
|
|||
])
|
||||
);
|
||||
|
||||
tree.append("e".to_string(), Retention::Ephemeral);
|
||||
tree.append("e".to_string(), Ephemeral);
|
||||
assert_eq!(
|
||||
tree.witness(Position::from(2), 0),
|
||||
Some(vec![
|
||||
|
@ -556,12 +586,12 @@ pub fn check_witnesses<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) ->
|
|||
);
|
||||
|
||||
let mut tree = new_tree(100);
|
||||
tree.append("a".to_string(), Retention::Marked);
|
||||
tree.append("a".to_string(), Marked);
|
||||
for c in 'b'..'g' {
|
||||
tree.append(c.to_string(), Retention::Ephemeral);
|
||||
tree.append(c.to_string(), Ephemeral);
|
||||
}
|
||||
tree.append("g".to_string(), Retention::Marked);
|
||||
tree.append("h".to_string(), Retention::Ephemeral);
|
||||
tree.append("g".to_string(), Marked);
|
||||
tree.append("h".to_string(), Ephemeral);
|
||||
|
||||
assert_eq!(
|
||||
tree.witness(0.into(), 0),
|
||||
|
@ -574,13 +604,13 @@ pub fn check_witnesses<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) ->
|
|||
);
|
||||
|
||||
let mut tree = new_tree(100);
|
||||
tree.append("a".to_string(), Retention::Marked);
|
||||
tree.append("b".to_string(), Retention::Ephemeral);
|
||||
tree.append("c".to_string(), Retention::Ephemeral);
|
||||
tree.append("d".to_string(), Retention::Marked);
|
||||
tree.append("e".to_string(), Retention::Marked);
|
||||
tree.append("f".to_string(), Retention::Marked);
|
||||
tree.append("g".to_string(), Retention::Ephemeral);
|
||||
tree.append("a".to_string(), Marked);
|
||||
tree.append("b".to_string(), Ephemeral);
|
||||
tree.append("c".to_string(), Ephemeral);
|
||||
tree.append("d".to_string(), Marked);
|
||||
tree.append("e".to_string(), Marked);
|
||||
tree.append("f".to_string(), Marked);
|
||||
tree.append("g".to_string(), Ephemeral);
|
||||
|
||||
assert_eq!(
|
||||
tree.witness(Position::from(5), 0),
|
||||
|
@ -594,10 +624,10 @@ pub fn check_witnesses<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) ->
|
|||
|
||||
let mut tree = new_tree(100);
|
||||
for c in 'a'..'k' {
|
||||
tree.append(c.to_string(), Retention::Ephemeral);
|
||||
assert!(tree.append(c.to_string(), Ephemeral));
|
||||
}
|
||||
tree.append('k'.to_string(), Retention::Marked);
|
||||
tree.append('l'.to_string(), Retention::Ephemeral);
|
||||
assert!(tree.append('k'.to_string(), Marked));
|
||||
assert!(tree.append('l'.to_string(), Ephemeral));
|
||||
|
||||
assert_eq!(
|
||||
tree.witness(Position::from(10), 0),
|
||||
|
@ -612,18 +642,18 @@ pub fn check_witnesses<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) ->
|
|||
let mut tree = new_tree(100);
|
||||
assert!(tree.append(
|
||||
'a'.to_string(),
|
||||
Retention::Checkpoint {
|
||||
Checkpoint {
|
||||
id: 1,
|
||||
is_marked: true
|
||||
}
|
||||
));
|
||||
assert!(tree.rewind());
|
||||
for c in 'b'..'e' {
|
||||
tree.append(c.to_string(), Retention::Ephemeral);
|
||||
tree.append(c.to_string(), Ephemeral);
|
||||
}
|
||||
tree.append("e".to_string(), Retention::Marked);
|
||||
tree.append("e".to_string(), Marked);
|
||||
for c in 'f'..'i' {
|
||||
tree.append(c.to_string(), Retention::Ephemeral);
|
||||
tree.append(c.to_string(), Ephemeral);
|
||||
}
|
||||
assert_eq!(
|
||||
tree.witness(0.into(), 0),
|
||||
|
@ -636,20 +666,20 @@ pub fn check_witnesses<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) ->
|
|||
);
|
||||
|
||||
let mut tree = new_tree(100);
|
||||
tree.append('a'.to_string(), Retention::Ephemeral);
|
||||
tree.append('b'.to_string(), Retention::Ephemeral);
|
||||
tree.append('c'.to_string(), Retention::Marked);
|
||||
tree.append('d'.to_string(), Retention::Ephemeral);
|
||||
tree.append('e'.to_string(), Retention::Ephemeral);
|
||||
tree.append('f'.to_string(), Retention::Ephemeral);
|
||||
tree.append('a'.to_string(), Ephemeral);
|
||||
tree.append('b'.to_string(), Ephemeral);
|
||||
tree.append('c'.to_string(), Marked);
|
||||
tree.append('d'.to_string(), Ephemeral);
|
||||
tree.append('e'.to_string(), Ephemeral);
|
||||
tree.append('f'.to_string(), Ephemeral);
|
||||
assert!(tree.append(
|
||||
'g'.to_string(),
|
||||
Retention::Checkpoint {
|
||||
Checkpoint {
|
||||
id: 1,
|
||||
is_marked: true
|
||||
}
|
||||
));
|
||||
tree.append('h'.to_string(), Retention::Ephemeral);
|
||||
tree.append('h'.to_string(), Ephemeral);
|
||||
assert!(tree.rewind());
|
||||
assert_eq!(
|
||||
tree.witness(Position::from(2), 0),
|
||||
|
@ -662,18 +692,18 @@ pub fn check_witnesses<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) ->
|
|||
);
|
||||
|
||||
let mut tree = new_tree(100);
|
||||
tree.append('a'.to_string(), Retention::Ephemeral);
|
||||
tree.append('b'.to_string(), Retention::Marked);
|
||||
tree.append('a'.to_string(), Ephemeral);
|
||||
tree.append('b'.to_string(), Marked);
|
||||
assert_eq!(tree.witness(Position::from(0), 0), None);
|
||||
|
||||
let mut tree = new_tree(100);
|
||||
for c in 'a'..'m' {
|
||||
tree.append(c.to_string(), Retention::Ephemeral);
|
||||
tree.append(c.to_string(), Ephemeral);
|
||||
}
|
||||
tree.append('m'.to_string(), Retention::Marked);
|
||||
tree.append('n'.to_string(), Retention::Marked);
|
||||
tree.append('o'.to_string(), Retention::Ephemeral);
|
||||
tree.append('p'.to_string(), Retention::Ephemeral);
|
||||
tree.append('m'.to_string(), Marked);
|
||||
tree.append('n'.to_string(), Marked);
|
||||
tree.append('o'.to_string(), Ephemeral);
|
||||
tree.append('p'.to_string(), Ephemeral);
|
||||
|
||||
assert_eq!(
|
||||
tree.witness(Position::from(12), 0),
|
||||
|
@ -686,10 +716,9 @@ pub fn check_witnesses<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) ->
|
|||
);
|
||||
|
||||
let ops = ('a'..='l')
|
||||
.into_iter()
|
||||
.map(|c| Append(c.to_string(), Retention::Marked))
|
||||
.chain(Some(Append('m'.to_string(), Retention::Ephemeral)))
|
||||
.chain(Some(Append('n'.to_string(), Retention::Ephemeral)))
|
||||
.map(|c| Append(c.to_string(), Marked))
|
||||
.chain(Some(Append('m'.to_string(), Ephemeral)))
|
||||
.chain(Some(Append('n'.to_string(), Ephemeral)))
|
||||
.chain(Some(Witness(11usize.into(), 0)))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -706,6 +735,153 @@ pub fn check_witnesses<T: Tree<String, usize> + std::fmt::Debug, F: Fn(usize) ->
|
|||
]
|
||||
))
|
||||
);
|
||||
|
||||
let ops = vec![
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Append("b".to_string(), Ephemeral),
|
||||
Append("c".to_string(), Ephemeral),
|
||||
Append(
|
||||
"d".to_string(),
|
||||
Checkpoint {
|
||||
id: 1,
|
||||
is_marked: true,
|
||||
},
|
||||
),
|
||||
Append("e".to_string(), Marked),
|
||||
Operation::Checkpoint(2),
|
||||
Append(
|
||||
"f".to_string(),
|
||||
Checkpoint {
|
||||
id: 3,
|
||||
is_marked: false,
|
||||
},
|
||||
),
|
||||
Append(
|
||||
"g".to_string(),
|
||||
Checkpoint {
|
||||
id: 4,
|
||||
is_marked: false,
|
||||
},
|
||||
),
|
||||
Append(
|
||||
"h".to_string(),
|
||||
Checkpoint {
|
||||
id: 5,
|
||||
is_marked: false,
|
||||
},
|
||||
),
|
||||
Witness(3usize.into(), 5),
|
||||
];
|
||||
let mut tree = new_tree(100);
|
||||
assert_eq!(
|
||||
Operation::apply_all(&ops, &mut tree),
|
||||
Some((
|
||||
Position::from(3),
|
||||
vec![
|
||||
"c".to_string(),
|
||||
"ab".to_string(),
|
||||
"____".to_string(),
|
||||
"________".to_string()
|
||||
]
|
||||
))
|
||||
);
|
||||
let ops = vec![
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Append(
|
||||
"a".to_string(),
|
||||
Checkpoint {
|
||||
id: 1,
|
||||
is_marked: true,
|
||||
},
|
||||
),
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Append(
|
||||
"a".to_string(),
|
||||
Checkpoint {
|
||||
id: 2,
|
||||
is_marked: false,
|
||||
},
|
||||
),
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Witness(Position(3), 1),
|
||||
];
|
||||
let mut tree = new_tree(100);
|
||||
assert_eq!(
|
||||
Operation::apply_all(&ops, &mut tree),
|
||||
Some((
|
||||
Position::from(3),
|
||||
vec![
|
||||
"a".to_string(),
|
||||
"aa".to_string(),
|
||||
"aaaa".to_string(),
|
||||
"________".to_string()
|
||||
]
|
||||
))
|
||||
);
|
||||
|
||||
let ops = vec![
|
||||
Append("a".to_string(), Marked),
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Operation::Checkpoint(1),
|
||||
Append("a".to_string(), Marked),
|
||||
Operation::Checkpoint(2),
|
||||
Operation::Checkpoint(3),
|
||||
Append(
|
||||
"a".to_string(),
|
||||
Checkpoint {
|
||||
id: 4,
|
||||
is_marked: false,
|
||||
},
|
||||
),
|
||||
Rewind,
|
||||
Rewind,
|
||||
Witness(Position(7), 2),
|
||||
];
|
||||
let mut tree = new_tree(100);
|
||||
assert_eq!(Operation::apply_all(&ops, &mut tree), None);
|
||||
|
||||
let ops = vec![
|
||||
Append("a".to_string(), Marked),
|
||||
Append("a".to_string(), Ephemeral),
|
||||
Append(
|
||||
"a".to_string(),
|
||||
Checkpoint {
|
||||
id: 1,
|
||||
is_marked: true,
|
||||
},
|
||||
),
|
||||
Append(
|
||||
"a".to_string(),
|
||||
Checkpoint {
|
||||
id: 4,
|
||||
is_marked: false,
|
||||
},
|
||||
),
|
||||
Witness(Position(2), 2),
|
||||
];
|
||||
let mut tree = new_tree(100);
|
||||
assert_eq!(
|
||||
Operation::apply_all(&ops, &mut tree),
|
||||
Some((
|
||||
Position::from(2),
|
||||
vec![
|
||||
"_".to_string(),
|
||||
"aa".to_string(),
|
||||
"____".to_string(),
|
||||
"________".to_string()
|
||||
]
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
pub fn check_checkpoint_rewind<T: Tree<String, usize>, F: Fn(usize) -> T>(new_tree: F) {
|
||||
|
@ -791,15 +967,15 @@ pub fn check_rewind_remove_mark<T: Tree<String, usize>, F: Fn(usize) -> T>(new_t
|
|||
|
||||
// use a maximum number of checkpoints of 1
|
||||
let mut tree = new_tree(1);
|
||||
tree.append("e".to_string(), Retention::Marked);
|
||||
tree.checkpoint(1);
|
||||
assert!(tree.append("e".to_string(), Retention::Marked));
|
||||
assert!(tree.checkpoint(1));
|
||||
assert!(tree.marked_positions().contains(&0usize.into()));
|
||||
tree.append("f".to_string(), Retention::Ephemeral);
|
||||
assert!(tree.append("f".to_string(), Retention::Ephemeral));
|
||||
// simulate a spend of `e` at `f`
|
||||
assert!(tree.remove_mark(0usize.into()));
|
||||
// even though the mark has been staged for removal, it's not gone yet
|
||||
assert!(tree.marked_positions().contains(&0usize.into()));
|
||||
tree.checkpoint(2);
|
||||
assert!(tree.checkpoint(2));
|
||||
// the newest checkpoint will have caused the oldest to roll off, and
|
||||
// so the forgotten node will be unmarked
|
||||
assert!(!tree.marked_positions().contains(&0usize.into()));
|
||||
|
|
|
@ -321,8 +321,8 @@ mod tests {
|
|||
use super::CompleteTree;
|
||||
use crate::{
|
||||
testing::{
|
||||
check_checkpoint_rewind, check_rewind_remove_mark, check_root_hashes, check_witnesses,
|
||||
compute_root_from_witness, SipHashable, Tree,
|
||||
check_append, check_checkpoint_rewind, check_rewind_remove_mark, check_root_hashes,
|
||||
check_witnesses, compute_root_from_witness, SipHashable, Tree,
|
||||
},
|
||||
Hashable, Level, Position, Retention,
|
||||
};
|
||||
|
@ -342,7 +342,7 @@ mod tests {
|
|||
#[test]
|
||||
fn correct_root() {
|
||||
const DEPTH: u8 = 3;
|
||||
let values = (0..(1 << DEPTH)).into_iter().map(SipHashable);
|
||||
let values = (0..(1 << DEPTH)).map(SipHashable);
|
||||
|
||||
let mut tree = CompleteTree::<SipHashable, (), DEPTH>::new(100, ());
|
||||
for value in values {
|
||||
|
@ -367,6 +367,11 @@ mod tests {
|
|||
assert_eq!(tree.root(0).unwrap(), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn append() {
|
||||
check_append(|max_checkpoints| CompleteTree::<String, usize, 4>::new(max_checkpoints, 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn root_hashes() {
|
||||
check_root_hashes(|max_checkpoints| {
|
||||
|
@ -375,7 +380,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn witness() {
|
||||
fn witnesses() {
|
||||
check_witnesses(|max_checkpoints| {
|
||||
CompleteTree::<String, usize, 4>::new(max_checkpoints, 0)
|
||||
});
|
||||
|
@ -386,7 +391,7 @@ mod tests {
|
|||
use crate::{testing::Tree, Retention};
|
||||
|
||||
const DEPTH: u8 = 3;
|
||||
let values = (0..(1 << DEPTH)).into_iter().map(SipHashable);
|
||||
let values = (0..(1 << DEPTH)).map(SipHashable);
|
||||
|
||||
let mut tree = CompleteTree::<SipHashable, (), DEPTH>::new(100, ());
|
||||
for value in values {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
[package]
|
||||
name = "shardtree"
|
||||
version = "0.0.0"
|
||||
authors = [
|
||||
"Kris Nuttycombe <kris@nutty.land>",
|
||||
]
|
||||
edition = "2018"
|
||||
license = "MIT OR Apache-2.0"
|
||||
description = "A space-efficient Merkle tree with witnessing of marked leaves, checkpointing & state restoration."
|
||||
homepage = "https://github.com/zcash/incrementalmerkletree"
|
||||
repository = "https://github.com/zcash/incrementalmerkletree"
|
||||
categories = ["algorithms", "data-structures"]
|
||||
|
||||
[dependencies]
|
||||
bitflags = "1.3"
|
||||
either = "1.8"
|
||||
incrementalmerkletree = { version = "0.3", path = "../incrementalmerkletree" }
|
||||
proptest = { version = "1.0.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
assert_matches = "1.5"
|
||||
criterion = "0.3"
|
||||
incrementalmerkletree = { version = "0.3", path = "../incrementalmerkletree", features = ["test-dependencies"] }
|
||||
proptest = "1.0.0"
|
||||
|
||||
[features]
|
||||
test-dependencies = ["proptest"]
|
||||
|
||||
[target.'cfg(unix)'.dev-dependencies]
|
||||
pprof = { version = "0.9", features = ["criterion", "flamegraph"] } # MSRV 1.56
|
||||
inferno = ">=0.11, <0.11.5" # MSRV 1.59
|
|
@ -0,0 +1,202 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-2021 The Electric Coin Company
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1,18 @@
|
|||
# Seeds for failure cases proptest has generated in the past. It is
|
||||
# automatically read and these particular cases re-run before any
|
||||
# novel cases are generated.
|
||||
#
|
||||
# It is recommended to check this file in to source control so that
|
||||
# everyone who runs the test benefits from these saved cases.
|
||||
cc 38b4ca3c029291dfe2a6b5907c33a2e8ae7900f19c759c5db74b616ab19f6c5c # shrinks to ops = [Append(SipHashable(0), MC), Rewind, Rewind]
|
||||
cc f1a96f73b9f3ba2a2e4b5271037322150450c573b6c3a5ef34f71a540ff0fad2 # shrinks to ops = [Append("a", C), Rewind, Rewind]
|
||||
cc ad5f5d4276adea6e928376c6dc8c013745e60a8b507e6fa4e716f6c35477fe65 # shrinks to ops = [Append("a", E), Append("a", E), Append("a", E), Append("a", E), Append("a", E), Append("a", E), Append("a", E), Append("a", E), Append("a", E)]
|
||||
cc ab2690ff3cf593d2e7a78b2f56d76699e525391b87852bbf15315a1f36742f48 # shrinks to ops = [Append(SipHashable(0), C), Append(SipHashable(0), E), Append(SipHashable(0), E), Unmark(Position(0))]
|
||||
cc 1603359084b0c614a2ff9008036a5e10db9f32fb31b3333e59aaa517686e174d # shrinks to ops = [Append(SipHashable(0), Checkpoint { id: (), is_marked: false })]
|
||||
cc faaf929be4b27e652712b705e297bfe15c53767102516e56882d177ac6fc58d9 # shrinks to ops = [CurrentPosition, Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Checkpoint { id: (), is_marked: true }), Append("a", Marked), Checkpoint(()), Append("a", Checkpoint { id: (), is_marked: false }), Append("a", Checkpoint { id: (), is_marked: false }), Append("a", Checkpoint { id: (), is_marked: false }), Witness(Position(3), 5)]
|
||||
cc 8836c27ead7afb8d10092bdaeed33eb31007eaa47e3c3fca248cc00fbce772a3 # shrinks to ops = [Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral)]
|
||||
cc 2303f82f255c60d7bdd45e2d13ff526bdc1d7f5ce846a7c07b38ab7f255c0300 # shrinks to ops = [Append("a", Marked), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral)]
|
||||
cc cf1a33ef6df58bbf7cc199b8b1879c3a078e7784aa3edc0aba9ca03772bea5f2 # shrinks to ops = [Append(SipHashable(0), Checkpoint { id: (), is_marked: false }), Append(SipHashable(0), Checkpoint { id: (), is_marked: false }), Append(SipHashable(0), Checkpoint { id: (), is_marked: false }), Checkpoint(()), Append(SipHashable(0), Checkpoint { id: (), is_marked: false }), Checkpoint(()), Rewind, Rewind, Rewind, Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Checkpoint { id: (), is_marked: false }), Append(SipHashable(0), Checkpoint { id: (), is_marked: false }), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Ephemeral), Append(SipHashable(0), Checkpoint { id: (), is_marked: true }), Witness(Position(8), 2)]
|
||||
cc 544e027d994eaf7f97b1c8d9ee7b35522a64a610b1430d56d74ec947018b759d # shrinks to ops = [Append("a", Marked), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Append("a", Ephemeral), Checkpoint(()), Append("a", Marked), Checkpoint(()), Checkpoint(()), Append("a", Checkpoint { id: (), is_marked: false }), Rewind, Rewind, Witness(Position(7), 2)]
|
||||
cc 55d00b68a0f0a02f83ab53f18a29d16d0233153b69a01414a1622104e0eead31 # shrinks to ops = [Append("a", Marked), Append("a", Checkpoint { id: (), is_marked: false }), Append("a", Marked), Checkpoint(()), Checkpoint(()), Checkpoint(()), Append("a", Checkpoint { id: (), is_marked: false }), Append("a", Checkpoint { id: (), is_marked: false }), Witness(Position(0), 7)]
|
||||
cc 9dd966ff1ab66965c5b84153ae13f684258560cdd5e84c7deb24f724cb12aba7 # shrinks to ops = [Append("a", Marked), Append("a", Ephemeral), Append("a", Checkpoint { id: (), is_marked: true }), Checkpoint(()), Append("a", Checkpoint { id: (), is_marked: false }), Rewind, Rewind, Append("a", Checkpoint { id: (), is_marked: false }), Append("a", Checkpoint { id: (), is_marked: false }), Checkpoint(()), Witness(Position(2), 4)]
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue