Commit Graph

31 Commits

Author SHA1 Message Date
Kris Nuttycombe 61a06de241 Fix formatting. 2022-02-23 21:30:52 -07:00
Kris Nuttycombe b4339d94db Return the current position & leaf from the witness operation.
Co-authored-by: str4d <jack@electriccoin.co>
2022-02-23 19:30:10 -07:00
Kris Nuttycombe 1dbb0d057d Update the property tests to generate positioned unwitness and auth_path operations. 2022-02-23 13:35:17 -07:00
Kris Nuttycombe b23b6ff9ec Record position with hash when constructing witnesses. 2022-02-23 11:33:08 -07:00
Kris Nuttycombe d5b7d90e13 Add bridgetree garbage collection.
This adds a garbage collection method to BridgeTree that
can be used to eliminate checkpoints and removed witnesses
that are no longer reachable for possible rewinds. It also
prunes unnecessary auth fragments from the tree.
2022-02-23 08:59:12 -07:00
Kris Nuttycombe c284081a0a Merge remote-tracking branch 'upstream/master' into fix_bridgetree_checkpoint_rewind 2022-02-22 21:05:11 -07:00
Kris Nuttycombe 993dd64650 Fix bridgetree checkpoint/rewind logic to fully restore the tree state.
Removal of witnesses is now recorded on a per-checkpoint
level, so that rewinding the tree state now restores any
witnesses that were removed since the checkpoint.

A number of internal consistency checks previously enforced
by the property tests have been removed as they did not
correctly implement this semantic, and reimplementing these
consistency checks would be equivalent to reimplementing the
sample tree, so these checks are now performed simply by
comparison against the reference implentation.
2022-02-22 09:44:32 -07:00
Kris Nuttycombe aedd865d42 Make example tests reusable across tree implementations. 2022-02-20 13:09:49 -07:00
Kris Nuttycombe efffa8a442 Key auth fragments by note position rather than bridge index.
This substantially simplifies reasoning about authentication
path fragments in garbage collection.
2022-02-20 10:21:58 -07:00
Kris Nuttycombe da420277a5 Use BTreeMap instead of HashMap when keyed by leaf hashes 2022-02-20 10:21:58 -07:00
Kris Nuttycombe 6327364524 Add current_leaf and is_witnessed to the tree API
Rename `current_position` to `current_offset` in the
sample API to avoid confusion with the meaning of
the `Position` type.
2022-02-20 10:21:21 -07:00
ghassmo 24e1980e8a use Self instead of the type's name 2022-01-23 23:16:30 +04:00
Kris Nuttycombe 67a5d6ff29 Fix documentation of tree methods. 2021-12-06 13:37:48 -07:00
Kris Nuttycombe 4e12c24807 Move `Position` into the base lib module and ensure wraps u64 explicitly. 2021-07-30 11:52:52 -06:00
Kris Nuttycombe 2f65f19fa6 Fix formatting. 2021-07-22 12:10:42 -06:00
Kris Nuttycombe 4d44fb56f5
Apply suggestions from code review
Co-authored-by: str4d <jack@electriccoin.co>
Co-authored-by: ying tong <yingtong@z.cash>
2021-07-20 09:45:36 -06:00
Kris Nuttycombe d188121cbe Improve bridgetree documentation. 2021-07-08 10:16:55 -06:00
Kris Nuttycombe e499a27f04 Revert change to string combine function for tests. 2021-06-24 14:12:52 -06:00
Kris Nuttycombe cf68d49d3f Trivial fixup. 2021-06-23 15:39:24 -06:00
Kris Nuttycombe 3decd0bf48 Use const generic parameter for tree depth. 2021-06-23 14:14:57 -06:00
Kris Nuttycombe aed785e896 Rename "Level" -> "Altitude"
The FlyClient spec uses "Altitude" for this concept in
Merkle mountain ranges, so I'm renaming for consistency.
2021-06-19 11:24:33 -06:00
Kris Nuttycombe 06e0a5772e Add `Frontier` trait as a subset of `Tree` operations.
For some applications, it is not necessary to include the
full range of witnessing and checkpointing operations. The
Frontier trait captures the minimal operations required:
appending leaves to the tree and constructing the root
of the tree by hashing against empty nodes.
2021-06-18 14:21:03 -06:00
Kris Nuttycombe c1fcd83329 Implement efficient incremental merkle tree. 2021-06-17 19:32:50 -06:00
Kris Nuttycombe 1267c8ec07 Rename "efficient" module to "bridgetree". 2021-06-17 19:31:26 -06:00
Kris Nuttycombe 37d1f920e4 Refactor hashing api & contracts of witness & checkpoint methods.
In this commit:

* TreeHasher is replaced by the Hashable trait. Hashable is
  modified to use level information in the construction of
  the hash, and a convenience method is provided for obtaining
  the empty node at a given level.

* The pop_checkpoint method is removed from the `Tree` interface.
  Instead, a maximum number of checkpoints is established at tree
  construction time and then the oldest checkpoints are automatically
  dropped when adding new checkpoints once that number is reached.

* The `witness` method implementation in the sample tree
  is modified to ignore duplicate calls.

* Property testing functiona are modified to abstract over
  the type of hashable data.
2021-06-17 19:24:18 -06:00
Kris Nuttycombe 68c8d88bd3 Move sample tree & efficient tree to independent modules. 2021-06-17 19:17:47 -06:00
Sean Bowe 48507454f3
combined tree 2021-01-05 15:11:17 -07:00
Sean Bowe e80228fb18
lol 2021-01-05 13:56:23 -07:00
Sean Bowe ba2abda0b9
lol 2021-01-05 13:46:01 -07:00
Sean Bowe 4ad04e62a1
lol 2021-01-05 13:40:05 -07:00
Sean Bowe 1c09fdc74e Initial commit. 2015-12-19 18:37:23 -07:00