Commit Graph

19 Commits

Author SHA1 Message Date
j-berman
5ddca0ce11 Implement and test trim_tree algo in memory 2024-07-29 03:40:44 -07:00
j-berman
36f1e1965f Fix grow_tree, restructure it, and clean the approach
The initial impl didn't capture the following edge case:

  - Tree has 3 (or more) layers + 1 leaf layeri
  - Leaf layer last chunk IS full
  - Layer 0 last chunk is NOT full
  - Layer 1 last chunk is NOT full
  - Layer 2 last chunk IS NOT full

In this case, when updating layer 1, we need to use layer 0's old
last hash to update layer 1's old last hash. Same for Layer 2.

The solution is to use logic that checks the *prev* layer when
updating a layer to determine if the old last hash from the prev
layer is needed.

This commit restructures the grow_tree impl to account for this
and simplifies the approach as follows:

1. Read the tree to get num leaf tuples + last hashes in each layer

2. Get the tree extension using the above values + new leaf tuples
2a. Prior to updating the leaf layer, call the function
get_update_leaf_layer_metadata. This function uses existing totals
in the leaf layer, the new total of leaf tuples,  and tree params
to calculate how the layer after the leaf layer should be updated.
2b. For each subsequent layer, call the function
get_update_layer_metadata. This function uses the existing totals
in the *prev* layer, the new total of children in the *prev* layer,
and tree params to calculate how the layer should be updated.

3. Grow the tree using the tree extension.

This approach isolates update logic and actual hashing into neat
structured functions, rather than mix the two. This makes the code
easier to follow without needing to keep so much in your head at
one time.
2024-07-29 03:40:44 -07:00
j-berman
8287ba6f78 faster trim_tree tests 2024-07-29 03:40:44 -07:00
j-berman
ed040cacc1 implement trim_tree_in_memory 2024-07-29 03:40:44 -07:00
j-berman
e8af7090b0 expose and test hash_trim from rust lib 2024-07-29 03:40:44 -07:00
j-berman
ae89fddc00 Set up trim_tree_in_memory test 2024-07-29 03:40:44 -07:00
j-berman
c7c6c6afff CurveTreesUnitTest -> CurveTreesGlobalTree class 2024-07-29 03:40:44 -07:00
j-berman
17b1f421c0 cleaner lmdb test structure for curve trees 2024-07-29 03:40:44 -07:00
j-berman
ab7c74136b Simplify edge case handling in hash_layer
- When retrieving last chunks, set next_start_child_chunk_index
so can know the correct start index without needing to modify
the offset
- Other smaller cleanup
2024-07-29 03:40:44 -07:00
Luke Parker
c792b21535 Use statics on the Rust side for generators 2024-07-29 03:40:44 -07:00
Luke Parker
af47a135eb Remove cxx and expose scalars/points directly 2024-07-29 03:40:44 -07:00
j-berman
af9b74fcc7 start LMDB grow_tree 2024-07-29 03:40:44 -07:00
j-berman
5ad026975a Cleaner template usage, moved static functions out of CurveTrees class 2024-07-29 03:40:44 -07:00
j-berman
4ade675939 Consolidate hash_leaf_layer into hash_layer 2024-07-29 03:40:44 -07:00
j-berman
9e68475ebd Use widths from fcmp++ repo test & align tests with width 2024-07-29 03:40:44 -07:00
j-berman
29e0fe759e Add Curve class, and Helios & Selene classes that derive from Curve 2024-07-29 03:40:44 -07:00
j-berman
d9390c7b08 Implement CurveTrees & CurveTreesUnitTest classes to simplify callers 2024-07-29 03:40:44 -07:00
j-berman
5103a94ee9 template all curve_trees types & funcs, rename tower_cycle_types to tower_cycle 2024-07-29 03:40:44 -07:00
j-berman
ad8872a76b Cleaner file organization 2024-07-29 03:40:44 -07:00