From 918befb0f5acfa4949b53152c9f768c678cf4be3 Mon Sep 17 00:00:00 2001 From: j-berman Date: Tue, 13 Aug 2024 09:25:43 -0700 Subject: [PATCH] new_leaf_tuples -> new_outputs --- src/blockchain_db/blockchain_db.cpp | 2 +- src/blockchain_db/blockchain_db.h | 2 +- src/blockchain_db/lmdb/db_lmdb.cpp | 6 +++--- src/blockchain_db/lmdb/db_lmdb.h | 2 +- src/blockchain_db/testdb.h | 2 +- src/fcmp_pp/curve_trees.cpp | 16 ++++++++-------- src/fcmp_pp/curve_trees.h | 2 +- tests/unit_tests/curve_trees.cpp | 16 ++++++++-------- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp index c3e58e4ee..2c0cb5033 100644 --- a/src/blockchain_db/blockchain_db.cpp +++ b/src/blockchain_db/blockchain_db.cpp @@ -69,7 +69,7 @@ static void get_outs_by_unlock_block(const cryptonote::transaction &tx, CHECK_AND_ASSERT_THROW_MES(tx.rct_signatures.outPk.size() > i, "unexpected size of outPk"); rct::key commitment = (miner_tx || tx.version != 2) - ? rct::zeroCommit(out.amount) // Needs ringct + ? rct::zeroCommit(out.amount) : tx.rct_signatures.outPk[i].mask; auto output_pair = fcmp_pp::curve_trees::OutputPair{ diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h index 8b4fac9b9..aa973fb6c 100644 --- a/src/blockchain_db/blockchain_db.h +++ b/src/blockchain_db/blockchain_db.h @@ -1783,7 +1783,7 @@ public: virtual bool for_all_alt_blocks(std::function f, bool include_blob = false) const = 0; // TODO: description and make private - virtual void grow_tree(std::vector &&new_leaves) = 0; + virtual void grow_tree(std::vector &&new_outputs) = 0; virtual void trim_tree(const uint64_t trim_n_leaf_tuples) = 0; diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index decf32d90..0011bebba 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -1345,10 +1345,10 @@ void BlockchainLMDB::remove_spent_key(const crypto::key_image& k_image) } } -void BlockchainLMDB::grow_tree(std::vector &&new_leaves) +void BlockchainLMDB::grow_tree(std::vector &&new_outputs) { LOG_PRINT_L3("BlockchainLMDB::" << __func__); - if (new_leaves.empty()) + if (new_outputs.empty()) return; check_open(); @@ -1366,7 +1366,7 @@ void BlockchainLMDB::grow_tree(std::vector // Use the number of leaf tuples and the existing last hashes to get a struct we can use to extend the tree CHECK_AND_ASSERT_THROW_MES(m_curve_trees != nullptr, "curve trees must be set"); - const auto tree_extension = m_curve_trees->get_tree_extension(old_n_leaf_tuples, last_hashes, std::move(new_leaves)); + const auto tree_extension = m_curve_trees->get_tree_extension(old_n_leaf_tuples, last_hashes, std::move(new_outputs)); // Insert the leaves // TODO: grow_leaves diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h index 2e108d554..6276aebd2 100644 --- a/src/blockchain_db/lmdb/db_lmdb.h +++ b/src/blockchain_db/lmdb/db_lmdb.h @@ -368,7 +368,7 @@ public: static int compare_string(const MDB_val *a, const MDB_val *b); // make private - virtual void grow_tree(std::vector &&new_leaves); + virtual void grow_tree(std::vector &&new_outputs); virtual void trim_tree(const uint64_t trim_n_leaf_tuples); diff --git a/src/blockchain_db/testdb.h b/src/blockchain_db/testdb.h index 91ebf8a1f..ee268bb93 100644 --- a/src/blockchain_db/testdb.h +++ b/src/blockchain_db/testdb.h @@ -116,7 +116,7 @@ public: virtual void add_tx_amount_output_indices(const uint64_t tx_index, const std::vector& amount_output_indices) override {} virtual void add_spent_key(const crypto::key_image& k_image) override {} virtual void remove_spent_key(const crypto::key_image& k_image) override {} - virtual void grow_tree(std::vector &&new_leaves) override {}; + virtual void grow_tree(std::vector &&new_outputs) override {}; virtual void trim_tree(const uint64_t trim_n_leaf_tuples) override {}; virtual bool audit_tree(const uint64_t expected_n_leaf_tuples) const override { return false; }; virtual std::array get_tree_root() const override { return {}; }; diff --git a/src/fcmp_pp/curve_trees.cpp b/src/fcmp_pp/curve_trees.cpp index e12df47ed..0bae50696 100644 --- a/src/fcmp_pp/curve_trees.cpp +++ b/src/fcmp_pp/curve_trees.cpp @@ -706,25 +706,25 @@ template typename CurveTrees::TreeExtension CurveTrees::get_tree_extension( const uint64_t old_n_leaf_tuples, const LastHashes &existing_last_hashes, - std::vector &&new_leaf_tuples) const + std::vector &&new_outputs) const { TreeExtension tree_extension; tree_extension.leaves.start_leaf_tuple_idx = old_n_leaf_tuples; - if (new_leaf_tuples.empty()) + if (new_outputs.empty()) return tree_extension; - // Sort the leaves by order they appear in the chain + // Sort the outputs by order they appear in the chain const auto sort_fn = [](const OutputContext &a, const OutputContext &b) { return a.output_id < b.output_id; }; - std::sort(new_leaf_tuples.begin(), new_leaf_tuples.end(), sort_fn); + std::sort(new_outputs.begin(), new_outputs.end(), sort_fn); // Convert sorted outputs into leaf tuples, place each element of each leaf tuple in a flat vector to be hashed, // and place the outputs in a tree extension struct for insertion into the db. We ignore invalid outputs, since // they cannot be inserted to the tree. std::vector flattened_leaves; - flattened_leaves.reserve(new_leaf_tuples.size() * LEAF_TUPLE_SIZE); - tree_extension.leaves.tuples.reserve(new_leaf_tuples.size()); - for (auto &o : new_leaf_tuples) + flattened_leaves.reserve(new_outputs.size() * LEAF_TUPLE_SIZE); + tree_extension.leaves.tuples.reserve(new_outputs.size()); + for (auto &o : new_outputs) { // TODO: this loop can be parallelized LeafTuple leaf; @@ -806,7 +806,7 @@ typename CurveTrees::TreeExtension CurveTrees::get_tree_extensio template CurveTrees::TreeExtension CurveTrees::get_tree_extension( const uint64_t old_n_leaf_tuples, const LastHashes &existing_last_hashes, - std::vector &&new_leaf_tuples) const; + std::vector &&new_outputs) const; //---------------------------------------------------------------------------------------------------------------------- template std::vector CurveTrees::get_trim_instructions( diff --git a/src/fcmp_pp/curve_trees.h b/src/fcmp_pp/curve_trees.h index 39c949d5d..1c551e22e 100644 --- a/src/fcmp_pp/curve_trees.h +++ b/src/fcmp_pp/curve_trees.h @@ -246,7 +246,7 @@ public: std::vector flatten_leaves(std::vector &&leaves) const; // Take in the existing number of leaf tuples and the existing last hash in each layer in the tree, as well as new - // leaves to add to the tree, and return a tree extension struct that can be used to extend a tree + // outputs to add to the tree, and return a tree extension struct that can be used to extend a tree TreeExtension get_tree_extension(const uint64_t old_n_leaf_tuples, const LastHashes &existing_last_hashes, std::vector &&new_leaf_tuples) const; diff --git a/tests/unit_tests/curve_trees.cpp b/tests/unit_tests/curve_trees.cpp index a16ffebc9..b5b1dc206 100644 --- a/tests/unit_tests/curve_trees.cpp +++ b/tests/unit_tests/curve_trees.cpp @@ -800,13 +800,13 @@ static bool grow_tree(CurveTreesV1 &curve_trees, global_tree.log_last_hashes(last_hashes); - auto new_leaf_tuples = generate_random_leaves(curve_trees, old_n_leaf_tuples, new_n_leaf_tuples); + auto new_outputs = generate_random_leaves(curve_trees, old_n_leaf_tuples, new_n_leaf_tuples); // Get a tree extension object to the existing tree using randomly generated leaves // - The tree extension includes all elements we'll need to add to the existing tree when adding the new leaves const auto tree_extension = curve_trees.get_tree_extension(old_n_leaf_tuples, last_hashes, - std::move(new_leaf_tuples)); + std::move(new_outputs)); global_tree.log_tree_extension(tree_extension); @@ -884,18 +884,18 @@ static bool grow_tree_db(const std::size_t init_leaves, LOG_PRINT_L1("Adding " << init_leaves << " leaves to db, then extending by " << ext_leaves << " leaves"); - auto init_leaf_tuples = generate_random_leaves(*curve_trees, 0, init_leaves); + auto init_outputs = generate_random_leaves(*curve_trees, 0, init_leaves); - test_db.m_db->grow_tree(std::move(init_leaf_tuples)); + test_db.m_db->grow_tree(std::move(init_outputs)); CHECK_AND_ASSERT_MES(test_db.m_db->audit_tree(init_leaves), false, "failed to add initial leaves to db"); MDEBUG("Successfully added initial " << init_leaves << " leaves to db, extending by " << ext_leaves << " leaves"); - auto ext_leaf_tuples = generate_random_leaves(*curve_trees, init_leaves, ext_leaves); + auto ext_outputs = generate_random_leaves(*curve_trees, init_leaves, ext_leaves); - test_db.m_db->grow_tree(std::move(ext_leaf_tuples)); + test_db.m_db->grow_tree(std::move(ext_outputs)); CHECK_AND_ASSERT_MES(test_db.m_db->audit_tree(init_leaves + ext_leaves), false, "failed to extend tree in db"); @@ -917,9 +917,9 @@ static bool trim_tree_db(const std::size_t init_leaves, LOG_PRINT_L1("Adding " << init_leaves << " leaves to db, then trimming by " << trim_leaves << " leaves"); - auto init_leaf_tuples = generate_random_leaves(*curve_trees, 0, init_leaves); + auto init_outputs = generate_random_leaves(*curve_trees, 0, init_leaves); - test_db.m_db->grow_tree(std::move(init_leaf_tuples)); + test_db.m_db->grow_tree(std::move(init_outputs)); CHECK_AND_ASSERT_MES(test_db.m_db->audit_tree(init_leaves), false, "failed to add initial leaves to db");