monero/tests/unit_tests
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
..
account.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
address_from_url.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
aligned.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
apply_permutation.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
base58.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
block_queue.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
block_reward.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
blockchain_db.cpp cleaner lmdb test structure for curve trees 2024-07-29 03:40:44 -07:00
bootstrap_node_selector.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
bulletproofs_plus.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
bulletproofs.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
canonical_amounts.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
chacha.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
checkpoints.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
CMakeLists.txt Cleaner file organization 2024-07-29 03:40:44 -07:00
command_line.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
crypto.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
curve_trees.cpp Fix grow_tree, restructure it, and clean the approach 2024-07-29 03:40:44 -07:00
curve_trees.h Fix grow_tree, restructure it, and clean the approach 2024-07-29 03:40:44 -07:00
decompose_amount_into_digits.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
device.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
difficulty.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
dns_resolver.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
epee_boosted_tcp_server.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
epee_levin_protocol_handler_async.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
epee_serialization.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
epee_utils.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
expect.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
get_xtype_from_string.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
hardfork.cpp Merge pull request #9386 2024-07-16 19:01:09 -04:00
hashchain.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
hmac_keccak.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
http.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
is_hdd.cpp Merge pull request #4424 2018-09-29 22:19:44 +02:00
json_serialization.cpp Enforce Tx unlock_time is Zero by Relay Rule 2024-02-24 14:27:17 -06:00
json_serialization.h copyright: bump to 2024 2024-05-21 16:29:33 +00:00
keccak.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
levin.cpp Merge pull request #9353 2024-07-16 18:51:30 -04:00
lmdb.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
logging.cpp Merge pull request #9386 2024-07-16 19:01:09 -04:00
long_term_block_weight.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
main.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
memwipe.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
mlocker.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
mnemonics.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
mul_div.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
multiexp.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
multisig.cpp Merge pull request #9338 2024-07-16 18:42:49 -04:00
net.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
node_server.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
notify.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
output_distribution.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
output_selection.cpp Merge pull request #9386 2024-07-16 19:01:09 -04:00
parse_amount.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
pruning.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
random.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
ringct.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
ringdb.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
rolling_median.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
rpc_version_str.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
scaling_2021.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
serialization.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
sha256.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
slow_memmem.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
subaddress.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
test_notifier.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
test_peerlist.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
test_protocol_pack.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
test_tx_utils.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
threadpool.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
tx_proof.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
unbound.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
unit_tests_utils.h cleaner lmdb test structure for curve trees 2024-07-29 03:40:44 -07:00
uri.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
util.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
variant.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
varint.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
ver_rct_non_semantics_simple_cached.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
vercmp.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
wallet_storage.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00
wipeable_string.cpp Merge pull request #9338 2024-07-16 18:42:49 -04:00
zmq_rpc.cpp copyright: bump to 2024 2024-05-21 16:29:33 +00:00