mirror of
https://github.com/monero-project/monero.git
synced 2025-03-10 15:39:21 -04:00
new_leaf_tuples -> new_outputs
This commit is contained in:
parent
67f5546d10
commit
918befb0f5
@ -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{
|
||||
|
@ -1783,7 +1783,7 @@ public:
|
||||
virtual bool for_all_alt_blocks(std::function<bool(const crypto::hash &blkid, const alt_block_data_t &data, const cryptonote::blobdata_ref *blob)> f, bool include_blob = false) const = 0;
|
||||
|
||||
// TODO: description and make private
|
||||
virtual void grow_tree(std::vector<fcmp_pp::curve_trees::OutputContext> &&new_leaves) = 0;
|
||||
virtual void grow_tree(std::vector<fcmp_pp::curve_trees::OutputContext> &&new_outputs) = 0;
|
||||
|
||||
virtual void trim_tree(const uint64_t trim_n_leaf_tuples) = 0;
|
||||
|
||||
|
@ -1345,10 +1345,10 @@ void BlockchainLMDB::remove_spent_key(const crypto::key_image& k_image)
|
||||
}
|
||||
}
|
||||
|
||||
void BlockchainLMDB::grow_tree(std::vector<fcmp_pp::curve_trees::OutputContext> &&new_leaves)
|
||||
void BlockchainLMDB::grow_tree(std::vector<fcmp_pp::curve_trees::OutputContext> &&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<fcmp_pp::curve_trees::OutputContext>
|
||||
|
||||
// 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
|
||||
|
@ -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<fcmp_pp::curve_trees::OutputContext> &&new_leaves);
|
||||
virtual void grow_tree(std::vector<fcmp_pp::curve_trees::OutputContext> &&new_outputs);
|
||||
|
||||
virtual void trim_tree(const uint64_t trim_n_leaf_tuples);
|
||||
|
||||
|
@ -116,7 +116,7 @@ public:
|
||||
virtual void add_tx_amount_output_indices(const uint64_t tx_index, const std::vector<uint64_t>& 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<fcmp_pp::curve_trees::OutputContext> &&new_leaves) override {};
|
||||
virtual void grow_tree(std::vector<fcmp_pp::curve_trees::OutputContext> &&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<uint8_t, 32UL> get_tree_root() const override { return {}; };
|
||||
|
@ -706,25 +706,25 @@ template<typename C1, typename C2>
|
||||
typename CurveTrees<C1, C2>::TreeExtension CurveTrees<C1, C2>::get_tree_extension(
|
||||
const uint64_t old_n_leaf_tuples,
|
||||
const LastHashes &existing_last_hashes,
|
||||
std::vector<OutputContext> &&new_leaf_tuples) const
|
||||
std::vector<OutputContext> &&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<typename C2::Scalar> 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<C1, C2>::TreeExtension CurveTrees<C1, C2>::get_tree_extensio
|
||||
template CurveTrees<Helios, Selene>::TreeExtension CurveTrees<Helios, Selene>::get_tree_extension(
|
||||
const uint64_t old_n_leaf_tuples,
|
||||
const LastHashes &existing_last_hashes,
|
||||
std::vector<OutputContext> &&new_leaf_tuples) const;
|
||||
std::vector<OutputContext> &&new_outputs) const;
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
template<typename C1, typename C2>
|
||||
std::vector<TrimLayerInstructions> CurveTrees<C1, C2>::get_trim_instructions(
|
||||
|
@ -246,7 +246,7 @@ public:
|
||||
std::vector<typename C2::Scalar> flatten_leaves(std::vector<LeafTuple> &&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<OutputContext> &&new_leaf_tuples) const;
|
||||
|
@ -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");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user