Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync protocol optimization #357

Merged
merged 44 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
45b874a
pruning fix
SupremoUGH May 31, 2023
29334a9
it works
SupremoUGH Jun 5, 2023
af61ea3
more things
SupremoUGH Jun 5, 2023
b7fea06
everything ready
SupremoUGH Jun 5, 2023
ceba725
everything ready
SupremoUGH Jun 5, 2023
32acf17
final touches
SupremoUGH Jun 5, 2023
58b3f61
changelog
SupremoUGH Jun 5, 2023
aedbd2c
clippy
SupremoUGH Jun 5, 2023
38c0942
final error found
SupremoUGH Jun 6, 2023
f8f06c6
no removing paths
SupremoUGH Jun 6, 2023
00b69fb
modified extend
SupremoUGH Jun 6, 2023
d158299
remove optimization
SupremoUGH Jun 6, 2023
70c7377
asset list method
SupremoUGH Jun 6, 2023
78d5e01
type asset_list_response
SupremoUGH Jun 6, 2023
1f925c5
asset list method takes normal ref
SupremoUGH Jun 6, 2023
4804bfb
asset list doesnt return zero assets
SupremoUGH Jun 7, 2023
23e5254
consolidation
SupremoUGH Jun 7, 2023
21039ad
consolidation prerequest
SupremoUGH Jun 7, 2023
b0ba214
clippy
SupremoUGH Jun 7, 2023
fd7f4bd
consolidation test
SupremoUGH Jun 8, 2023
034a2cc
test docs
SupremoUGH Jun 8, 2023
b8d3750
comment addressed
SupremoUGH Jun 9, 2023
f83ace6
Merge branch 'reinstore_pruning_good' into consolidate_utxos
SupremoUGH Jun 9, 2023
7673981
estimate posts
SupremoUGH Jun 9, 2023
888e915
docs and changelog
SupremoUGH Jun 9, 2023
ac92c05
docs
SupremoUGH Jun 9, 2023
9121a4a
docs
SupremoUGH Jun 9, 2023
98d9251
merge
SupremoUGH Jun 14, 2023
faf2599
estimate transferposts correction
SupremoUGH Jun 14, 2023
0be1ee2
done
SupremoUGH Jun 14, 2023
fbd5d4a
docs and changelog
SupremoUGH Jun 14, 2023
c7605ce
estimate posts update
SupremoUGH Jun 14, 2023
365169b
estimate again
SupremoUGH Jun 14, 2023
5c4920c
test
SupremoUGH Jun 14, 2023
ea23e3c
comments addressed
SupremoUGH Jun 15, 2023
a1eca87
final touch
SupremoUGH Jun 15, 2023
d9501d4
Merge branch 'consolidate_utxos' into sync_protocol_optimization
SupremoUGH Jun 15, 2023
4eff57c
bug fixed
SupremoUGH Jun 15, 2023
5c5ec22
removed useless debugs
SupremoUGH Jun 15, 2023
edf4df2
assert message
SupremoUGH Jun 15, 2023
427c08b
ready to merge
SupremoUGH Jun 15, 2023
c49087b
changelog
SupremoUGH Jun 15, 2023
9e8d7d8
merge main
SupremoUGH Jun 19, 2023
ac064dd
comment addressed
SupremoUGH Jun 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [\#353](https://github.com/Manta-Network/manta-rs/pull/353) Restore Merkle tree pruning for the wallet.

### Changed
- [\#357](https://github.com/Manta-Network/manta-rs/pull/357) Sync protocol optimization.
- [\#356](https://github.com/Manta-Network/manta-rs/pull/356) Signer ToPublic optimization.

### Deprecated
Expand Down
2 changes: 1 addition & 1 deletion manta-crypto/src/merkle_tree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ impl NodeRange {
}
};
for i in range {
result.push(Node(i).join_leaves(parameters, &leaves[i], &leaves[i + 1]))
result.push(parameters.join_leaves(&leaves[i], &leaves[i + 1]));
}
if dual_parity.final_parity().is_left() {
result.push(self.last_node().join_leaves(
Expand Down
12 changes: 10 additions & 2 deletions manta-crypto/src/merkle_tree/partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,23 @@ where
let marked_leaf_digests = marked_leaf_digests.into_iter();
if matches!(marked_leaf_digests.size_hint().1, Some(max) if max <= capacity::<C, _>() - self.len())
{
let mut marked_inserts = Vec::new();
for (marking, leaf_digest) in marked_leaf_digests {
if marking {
assert!(self.push_digest(parameters, || leaf_digest),
"Unable to push digest even though the tree should have enough capacity to do so.");
marked_inserts.push(leaf_digest);
} else {
if !marked_inserts.is_empty() {
assert!(self.batch_push_digest(parameters, || marked_inserts.drain(..).collect::<Vec<_>>()),
"Unable to push digest even though the tree should have enough capacity to do so.");
}
assert!(self.push_provable_digest(parameters, move || leaf_digest),
"Unable to push digest even though the tree should have enough capacity to do so.");
}
}
if !marked_inserts.is_empty() {
assert!(self.batch_push_digest(parameters, || marked_inserts.drain(..).collect::<Vec<_>>()),
"Unable to push digest even though the tree should have enough capacity to do so.");
}
return Ok(());
}
Err(marked_leaf_digests)
Expand Down
42 changes: 42 additions & 0 deletions manta-crypto/src/merkle_tree/test/batch_insertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,45 @@ fn test_batch_insertion_forest() {
|forest, _, leaves| forest.batch_insert(leaves),
)
}

/// Tests that [`merge_fork_partial`] returns the same root as [`merge_fork`].
///
/// [`merge_fork`]: ForkedTree::merge_fork
/// [`merge_fork_partial`]: ForkedTree::merge_fork_partial
#[inline]
fn branch_and_merge_test() {
let mut rng = OsRng;
let parameters = Parameters::sample(Default::default(), &mut rng);
let mut tree = ForkedTree::new(Partial::new(&parameters), &parameters);
let number_of_insertions = rng.gen_range(1..(1 << (HEIGHT - 1)) / 2);
let insertions = (0..number_of_insertions)
.map(|_| rng.gen())
.collect::<Vec<_>>();
for leaf in insertions {
Tree::push(&mut tree, &parameters, &leaf);
}
tree.merge_fork(&parameters);
let second_number_of_insertions = rng.gen_range(number_of_insertions..(1 << (HEIGHT - 1)));
let insertions = (number_of_insertions..second_number_of_insertions)
.map(|_| rng.gen())
.collect::<Vec<_>>();
for leaf in insertions {
Tree::push(&mut tree, &parameters, &leaf);
}
let mut cloned_tree = tree.clone();
tree.merge_fork_partial(&parameters);
cloned_tree.merge_fork(&parameters);
assert_eq!(
tree.root(),
cloned_tree.root(),
"Merge fork and merge fork partial should return the same Merkle root"
);
SupremoUGH marked this conversation as resolved.
Show resolved Hide resolved
}

/// Runs [`branch_and_merge_test`] 10 times.
#[test]
fn branch_and_merge_test_10_times() {
for _ in 0..10 {
branch_and_merge_test();
}
}