Skip to content

Commit

Permalink
Rename everything from fcmp* to fcmp_pp
Browse files Browse the repository at this point in the history
  • Loading branch information
j-berman committed Aug 8, 2024
1 parent d72f405 commit d4847f6
Show file tree
Hide file tree
Showing 28 changed files with 114 additions and 113 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ add_subdirectory(ringct)
add_subdirectory(checkpoints)
add_subdirectory(cryptonote_basic)
add_subdirectory(cryptonote_core)
add_subdirectory(fcmp)
add_subdirectory(fcmp_pp)
add_subdirectory(lmdb)
add_subdirectory(multisig)
add_subdirectory(net)
Expand Down
2 changes: 1 addition & 1 deletion src/blockchain_db/blockchain_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ uint64_t BlockchainDB::add_block( const std::pair<block, blobdata>& blck
// When adding a block, we also need to add all the leaf tuples included in
// the block to a table keeping track of locked leaf tuples. Once those leaf
// tuples unlock, we use them to grow the tree.
std::multimap<uint64_t, fcmp::curve_trees::LeafTupleContext> leaf_tuples_by_unlock_block;
std::multimap<uint64_t, fcmp_pp::curve_trees::LeafTupleContext> leaf_tuples_by_unlock_block;

// Get miner tx's leaf tuples
CHECK_AND_ASSERT_THROW_MES(m_curve_trees != nullptr, "curve trees must be set");
Expand Down
8 changes: 4 additions & 4 deletions src/blockchain_db/blockchain_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include "cryptonote_basic/difficulty.h"
#include "cryptonote_basic/hardfork.h"
#include "cryptonote_protocol/enums.h"
#include "fcmp/curve_trees.h"
#include "fcmp_pp/curve_trees.h"

/** \file
* Cryptonote Blockchain Database Interface
Expand Down Expand Up @@ -418,7 +418,7 @@ class BlockchainDB
, const uint64_t& coins_generated
, uint64_t num_rct_outs
, const crypto::hash& blk_hash
, const std::multimap<uint64_t, fcmp::curve_trees::LeafTupleContext>& leaf_tuples_by_unlock_block
, const std::multimap<uint64_t, fcmp_pp::curve_trees::LeafTupleContext>& leaf_tuples_by_unlock_block
) = 0;

/**
Expand Down Expand Up @@ -592,7 +592,7 @@ class BlockchainDB

HardFork* m_hardfork;

std::shared_ptr<fcmp::curve_trees::CurveTreesV1> m_curve_trees;
std::shared_ptr<fcmp_pp::curve_trees::CurveTreesV1> m_curve_trees;

public:

Expand Down Expand Up @@ -1783,7 +1783,7 @@ class BlockchainDB
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::curve_trees::LeafTupleContext> &&new_leaves) = 0;
virtual void grow_tree(std::vector<fcmp_pp::curve_trees::LeafTupleContext> &&new_leaves) = 0;

virtual void trim_tree(const uint64_t trim_n_leaf_tuples) = 0;

Expand Down
64 changes: 32 additions & 32 deletions src/blockchain_db/lmdb/db_lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ uint64_t BlockchainLMDB::get_estimated_batch_size(uint64_t batch_num_blocks, uin
}

void BlockchainLMDB::add_block(const block& blk, size_t block_weight, uint64_t long_term_block_weight, const difficulty_type& cumulative_difficulty, const uint64_t& coins_generated,
uint64_t num_rct_outs, const crypto::hash& blk_hash, const std::multimap<uint64_t, fcmp::curve_trees::LeafTupleContext> &leaf_tuples_by_unlock_block)
uint64_t num_rct_outs, const crypto::hash& blk_hash, const std::multimap<uint64_t, fcmp_pp::curve_trees::LeafTupleContext> &leaf_tuples_by_unlock_block)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
Expand Down Expand Up @@ -1344,7 +1344,7 @@ void BlockchainLMDB::remove_spent_key(const crypto::key_image& k_image)
}
}

void BlockchainLMDB::grow_tree(std::vector<fcmp::curve_trees::LeafTupleContext> &&new_leaves)
void BlockchainLMDB::grow_tree(std::vector<fcmp_pp::curve_trees::LeafTupleContext> &&new_leaves)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
if (new_leaves.empty())
Expand Down Expand Up @@ -1403,7 +1403,7 @@ void BlockchainLMDB::grow_tree(std::vector<fcmp::curve_trees::LeafTupleContext>
throw0(DB_ERROR(("Growing odd c2 layer, expected even layer idx for c1: "
+ std::to_string(layer_idx)).c_str()));

this->grow_layer<fcmp::curve_trees::Selene>(m_curve_trees->m_c2,
this->grow_layer<fcmp_pp::curve_trees::Selene>(m_curve_trees->m_c2,
c2_extensions,
c2_idx,
layer_idx);
Expand All @@ -1416,7 +1416,7 @@ void BlockchainLMDB::grow_tree(std::vector<fcmp::curve_trees::LeafTupleContext>
throw0(DB_ERROR(("Growing even c1 layer, expected odd layer idx for c2: "
+ std::to_string(layer_idx)).c_str()));

this->grow_layer<fcmp::curve_trees::Helios>(m_curve_trees->m_c1,
this->grow_layer<fcmp_pp::curve_trees::Helios>(m_curve_trees->m_c1,
c1_extensions,
c1_idx,
layer_idx);
Expand All @@ -1430,7 +1430,7 @@ void BlockchainLMDB::grow_tree(std::vector<fcmp::curve_trees::LeafTupleContext>

template<typename C>
void BlockchainLMDB::grow_layer(const std::unique_ptr<C> &curve,
const std::vector<fcmp::curve_trees::LayerExtension<C>> &layer_extensions,
const std::vector<fcmp_pp::curve_trees::LayerExtension<C>> &layer_extensions,
const uint64_t ext_idx,
const uint64_t layer_idx)
{
Expand Down Expand Up @@ -1596,7 +1596,7 @@ void BlockchainLMDB::trim_tree(const uint64_t trim_n_leaf_tuples)

template<typename C>
void BlockchainLMDB::trim_layer(const std::unique_ptr<C> &curve,
const fcmp::curve_trees::LayerReduction<C> &layer_reduction,
const fcmp_pp::curve_trees::LayerReduction<C> &layer_reduction,
const uint64_t layer_idx)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
Expand Down Expand Up @@ -1718,15 +1718,15 @@ std::array<uint8_t, 32UL> BlockchainLMDB::get_tree_root() const
return root;
}

fcmp::curve_trees::CurveTreesV1::LastHashes BlockchainLMDB::get_tree_last_hashes() const
fcmp_pp::curve_trees::CurveTreesV1::LastHashes BlockchainLMDB::get_tree_last_hashes() const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();

TXN_PREFIX_RDONLY();
RCURSOR(layers)

fcmp::curve_trees::CurveTreesV1::LastHashes last_hashes;
fcmp_pp::curve_trees::CurveTreesV1::LastHashes last_hashes;
auto &c1_last_hashes = last_hashes.c1_last_hashes;
auto &c2_last_hashes = last_hashes.c2_last_hashes;

Expand Down Expand Up @@ -1772,8 +1772,8 @@ fcmp::curve_trees::CurveTreesV1::LastHashes BlockchainLMDB::get_tree_last_hashes
return last_hashes;
}

fcmp::curve_trees::CurveTreesV1::LastChunkChildrenToTrim BlockchainLMDB::get_last_chunk_children_to_trim(
const std::vector<fcmp::curve_trees::TrimLayerInstructions> &trim_instructions) const
fcmp_pp::curve_trees::CurveTreesV1::LastChunkChildrenToTrim BlockchainLMDB::get_last_chunk_children_to_trim(
const std::vector<fcmp_pp::curve_trees::TrimLayerInstructions> &trim_instructions) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
Expand All @@ -1783,7 +1783,7 @@ fcmp::curve_trees::CurveTreesV1::LastChunkChildrenToTrim BlockchainLMDB::get_las
TXN_PREFIX_RDONLY();
RCURSOR(layers)

fcmp::curve_trees::CurveTreesV1::LastChunkChildrenToTrim last_chunk_children_to_trim;
fcmp_pp::curve_trees::CurveTreesV1::LastChunkChildrenToTrim last_chunk_children_to_trim;
auto &c1_last_children_out = last_chunk_children_to_trim.c1_children;
auto &c2_last_children_out = last_chunk_children_to_trim.c2_children;

Expand All @@ -1793,17 +1793,17 @@ fcmp::curve_trees::CurveTreesV1::LastChunkChildrenToTrim BlockchainLMDB::get_las
CHECK_AND_ASSERT_THROW_MES(!trim_instructions.empty(), "no instructions");
const auto &trim_leaf_layer_instructions = trim_instructions[0];

std::vector<fcmp::curve_trees::Selene::Scalar> leaves_to_trim;
std::vector<fcmp_pp::curve_trees::Selene::Scalar> leaves_to_trim;

if (trim_leaf_layer_instructions.end_trim_idx > trim_leaf_layer_instructions.start_trim_idx)
{
leaves_to_trim.reserve(trim_leaf_layer_instructions.end_trim_idx - trim_leaf_layer_instructions.start_trim_idx);

uint64_t idx = trim_leaf_layer_instructions.start_trim_idx;
CHECK_AND_ASSERT_THROW_MES(idx % fcmp::curve_trees::CurveTreesV1::LEAF_TUPLE_SIZE == 0,
CHECK_AND_ASSERT_THROW_MES(idx % fcmp_pp::curve_trees::CurveTreesV1::LEAF_TUPLE_SIZE == 0,
"expected divisble by leaf tuple size");

const uint64_t leaf_tuple_idx = idx / fcmp::curve_trees::CurveTreesV1::LEAF_TUPLE_SIZE;
const uint64_t leaf_tuple_idx = idx / fcmp_pp::curve_trees::CurveTreesV1::LEAF_TUPLE_SIZE;
MDB_val_copy<uint64_t> k(leaf_tuple_idx);

MDB_cursor_op leaf_op = MDB_SET;
Expand All @@ -1817,7 +1817,7 @@ fcmp::curve_trees::CurveTreesV1::LastChunkChildrenToTrim BlockchainLMDB::get_las
if (result != MDB_SUCCESS)
throw0(DB_ERROR(lmdb_error("Failed to get leaf: ", result).c_str()));

const auto preprocessed_leaf_tuple = *(fcmp::curve_trees::PreprocessedLeafTuple *)v.mv_data;
const auto preprocessed_leaf_tuple = *(fcmp_pp::curve_trees::PreprocessedLeafTuple *)v.mv_data;

// TODO: parallelize calls to this function
auto leaf = m_curve_trees->leaf_tuple(preprocessed_leaf_tuple);
Expand All @@ -1826,7 +1826,7 @@ fcmp::curve_trees::CurveTreesV1::LastChunkChildrenToTrim BlockchainLMDB::get_las
leaves_to_trim.emplace_back(std::move(leaf.I_x));
leaves_to_trim.emplace_back(std::move(leaf.C_x));

idx += fcmp::curve_trees::CurveTreesV1::LEAF_TUPLE_SIZE;
idx += fcmp_pp::curve_trees::CurveTreesV1::LEAF_TUPLE_SIZE;
}
while (idx < trim_leaf_layer_instructions.end_trim_idx);
}
Expand All @@ -1841,8 +1841,8 @@ fcmp::curve_trees::CurveTreesV1::LastChunkChildrenToTrim BlockchainLMDB::get_las
{
const auto &trim_layer_instructions = trim_instructions[i];

std::vector<fcmp::curve_trees::Helios::Scalar> c1_children;
std::vector<fcmp::curve_trees::Selene::Scalar> c2_children;
std::vector<fcmp_pp::curve_trees::Helios::Scalar> c1_children;
std::vector<fcmp_pp::curve_trees::Selene::Scalar> c2_children;

if (trim_layer_instructions.end_trim_idx > trim_layer_instructions.start_trim_idx)
{
Expand Down Expand Up @@ -1895,16 +1895,16 @@ fcmp::curve_trees::CurveTreesV1::LastChunkChildrenToTrim BlockchainLMDB::get_las
return last_chunk_children_to_trim;
}

fcmp::curve_trees::CurveTreesV1::LastHashes BlockchainLMDB::get_last_hashes_to_trim(
const std::vector<fcmp::curve_trees::TrimLayerInstructions> &trim_instructions) const
fcmp_pp::curve_trees::CurveTreesV1::LastHashes BlockchainLMDB::get_last_hashes_to_trim(
const std::vector<fcmp_pp::curve_trees::TrimLayerInstructions> &trim_instructions) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();

TXN_PREFIX_RDONLY();
RCURSOR(layers)

fcmp::curve_trees::CurveTreesV1::LastHashes last_hashes_out;
fcmp_pp::curve_trees::CurveTreesV1::LastHashes last_hashes_out;

// Traverse the tree layer-by-layer starting at the layer closest to leaf layer
uint64_t layer_idx = 0;
Expand Down Expand Up @@ -1975,7 +1975,7 @@ bool BlockchainLMDB::audit_tree(const uint64_t expected_n_leaf_tuples) const
while (1)
{
// Get next leaf chunk
std::vector<fcmp::curve_trees::CurveTreesV1::LeafTuple> leaf_tuples_chunk;
std::vector<fcmp_pp::curve_trees::CurveTreesV1::LeafTuple> leaf_tuples_chunk;
leaf_tuples_chunk.reserve(m_curve_trees->m_c2_width);

// Iterate until chunk is full or we get to the end of all leaves
Expand All @@ -1989,7 +1989,7 @@ bool BlockchainLMDB::audit_tree(const uint64_t expected_n_leaf_tuples) const
if (result != MDB_SUCCESS)
throw0(DB_ERROR(lmdb_error("Failed to add leaf: ", result).c_str()));

const auto preprocessed_leaf_tuple = *(fcmp::curve_trees::PreprocessedLeafTuple *)v.mv_data;
const auto preprocessed_leaf_tuple = *(fcmp_pp::curve_trees::PreprocessedLeafTuple *)v.mv_data;
auto leaf = m_curve_trees->leaf_tuple(preprocessed_leaf_tuple);

leaf_tuples_chunk.emplace_back(std::move(leaf));
Expand Down Expand Up @@ -2022,13 +2022,13 @@ bool BlockchainLMDB::audit_tree(const uint64_t expected_n_leaf_tuples) const

// Get the expected leaf chunk hash
const auto leaves = m_curve_trees->flatten_leaves(std::move(leaf_tuples_chunk));
const fcmp::curve_trees::Selene::Chunk chunk{leaves.data(), leaves.size()};
const fcmp_pp::curve_trees::Selene::Chunk chunk{leaves.data(), leaves.size()};

// Hash the chunk of leaves
for (uint64_t i = 0; i < leaves.size(); ++i)
MDEBUG("Hashing " << m_curve_trees->m_c2->to_string(leaves[i]));

const fcmp::curve_trees::Selene::Point chunk_hash = fcmp::curve_trees::get_new_parent(m_curve_trees->m_c2, chunk);
const auto chunk_hash = fcmp_pp::curve_trees::get_new_parent(m_curve_trees->m_c2, chunk);
MDEBUG("chunk_hash " << m_curve_trees->m_c2->to_string(chunk_hash) << " , hash init point: "
<< m_curve_trees->m_c2->to_string(m_curve_trees->m_c2->hash_init_point()) << " (" << leaves.size() << " leaves)");

Expand Down Expand Up @@ -2173,7 +2173,7 @@ bool BlockchainLMDB::audit_layer(const std::unique_ptr<C_CHILD> &c_child,
for (uint64_t i = 0; i < child_scalars.size(); ++i)
MDEBUG("Hashing " << c_parent->to_string(child_scalars[i]));

const auto chunk_hash = fcmp::curve_trees::get_new_parent(c_parent, chunk);
const auto chunk_hash = fcmp_pp::curve_trees::get_new_parent(c_parent, chunk);
MDEBUG("chunk_hash " << c_parent->to_string(chunk_hash) << " , hash init point: "
<< c_parent->to_string(c_parent->hash_init_point()) << " (" << child_scalars.size() << " children)");

Expand All @@ -2194,7 +2194,7 @@ bool BlockchainLMDB::audit_layer(const std::unique_ptr<C_CHILD> &c_child,
chunk_width);
}

std::vector<fcmp::curve_trees::LeafTupleContext> BlockchainLMDB::get_leaf_tuples_at_unlock_block_id(
std::vector<fcmp_pp::curve_trees::LeafTupleContext> BlockchainLMDB::get_leaf_tuples_at_unlock_block_id(
uint64_t block_id)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
Expand All @@ -2207,7 +2207,7 @@ std::vector<fcmp::curve_trees::LeafTupleContext> BlockchainLMDB::get_leaf_tuples
MDB_val v_tuple;

// Get all the locked outputs at the provided block id
std::vector<fcmp::curve_trees::LeafTupleContext> leaf_tuples;
std::vector<fcmp_pp::curve_trees::LeafTupleContext> leaf_tuples;

MDB_cursor_op op = MDB_SET;
while (1)
Expand All @@ -2223,8 +2223,8 @@ std::vector<fcmp::curve_trees::LeafTupleContext> BlockchainLMDB::get_leaf_tuples
if (blk_id != block_id)
throw0(DB_ERROR(("Blk id " + std::to_string(blk_id) + " not the expected" + std::to_string(block_id)).c_str()));

const auto range_begin = ((const fcmp::curve_trees::LeafTupleContext*)v_tuple.mv_data);
const auto range_end = range_begin + v_tuple.mv_size / sizeof(fcmp::curve_trees::LeafTupleContext);
const auto range_begin = ((const fcmp_pp::curve_trees::LeafTupleContext*)v_tuple.mv_data);
const auto range_end = range_begin + v_tuple.mv_size / sizeof(fcmp_pp::curve_trees::LeafTupleContext);

auto it = range_begin;

Expand Down Expand Up @@ -2279,7 +2279,7 @@ BlockchainLMDB::~BlockchainLMDB()
BlockchainLMDB::close();
}

BlockchainLMDB::BlockchainLMDB(bool batch_transactions, std::shared_ptr<fcmp::curve_trees::CurveTreesV1> curve_trees): BlockchainDB()
BlockchainLMDB::BlockchainLMDB(bool batch_transactions, std::shared_ptr<fcmp_pp::curve_trees::CurveTreesV1> curve_trees): BlockchainDB()
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
// initialize folder to something "safe" just in case
Expand Down Expand Up @@ -6836,7 +6836,7 @@ void BlockchainLMDB::migrate_5_6()
}

// Convert the output into a leaf tuple context
fcmp::curve_trees::LeafTupleContext tuple_context;
fcmp_pp::curve_trees::LeafTupleContext tuple_context;
try
{
tuple_context = m_curve_trees->output_to_leaf_context(
Expand Down
24 changes: 12 additions & 12 deletions src/blockchain_db/lmdb/db_lmdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "blockchain_db/blockchain_db.h"
#include "cryptonote_basic/blobdatatype.h" // for type blobdata
#include "fcmp/curve_trees.h"
#include "fcmp_pp/curve_trees.h"
#include "ringct/rctTypes.h"
#include <boost/thread/tss.hpp>

Expand Down Expand Up @@ -194,7 +194,7 @@ struct mdb_txn_safe
class BlockchainLMDB : public BlockchainDB
{
public:
BlockchainLMDB(bool batch_transactions=true, std::shared_ptr<fcmp::curve_trees::CurveTreesV1> curve_trees = fcmp::curve_trees::curve_trees_v1());
BlockchainLMDB(bool batch_transactions=true, std::shared_ptr<fcmp_pp::curve_trees::CurveTreesV1> curve_trees = fcmp_pp::curve_trees::curve_trees_v1());
~BlockchainLMDB();

virtual void open(const std::string& filename, const int mdb_flags=0);
Expand Down Expand Up @@ -368,7 +368,7 @@ class BlockchainLMDB : public BlockchainDB
static int compare_string(const MDB_val *a, const MDB_val *b);

// make private
virtual void grow_tree(std::vector<fcmp::curve_trees::LeafTupleContext> &&new_leaves);
virtual void grow_tree(std::vector<fcmp_pp::curve_trees::LeafTupleContext> &&new_leaves);

virtual void trim_tree(const uint64_t trim_n_leaf_tuples);

Expand All @@ -388,7 +388,7 @@ class BlockchainLMDB : public BlockchainDB
, const uint64_t& coins_generated
, uint64_t num_rct_outs
, const crypto::hash& block_hash
, const std::multimap<uint64_t, fcmp::curve_trees::LeafTupleContext>& leaf_tuples_by_unlock_block
, const std::multimap<uint64_t, fcmp_pp::curve_trees::LeafTupleContext>& leaf_tuples_by_unlock_block
);

virtual void remove_block();
Expand Down Expand Up @@ -420,26 +420,26 @@ class BlockchainLMDB : public BlockchainDB

template<typename C>
void grow_layer(const std::unique_ptr<C> &curve,
const std::vector<fcmp::curve_trees::LayerExtension<C>> &layer_extensions,
const std::vector<fcmp_pp::curve_trees::LayerExtension<C>> &layer_extensions,
const uint64_t c_idx,
const uint64_t layer_idx);

template<typename C>
void trim_layer(const std::unique_ptr<C> &curve,
const fcmp::curve_trees::LayerReduction<C> &layer_reduction,
const fcmp_pp::curve_trees::LayerReduction<C> &layer_reduction,
const uint64_t layer_idx);

virtual uint64_t get_num_leaf_tuples() const;

virtual std::array<uint8_t, 32UL> get_tree_root() const;

fcmp::curve_trees::CurveTreesV1::LastHashes get_tree_last_hashes() const;
fcmp_pp::curve_trees::CurveTreesV1::LastHashes get_tree_last_hashes() const;

fcmp::curve_trees::CurveTreesV1::LastChunkChildrenToTrim get_last_chunk_children_to_trim(
const std::vector<fcmp::curve_trees::TrimLayerInstructions> &trim_instructions) const;
fcmp_pp::curve_trees::CurveTreesV1::LastChunkChildrenToTrim get_last_chunk_children_to_trim(
const std::vector<fcmp_pp::curve_trees::TrimLayerInstructions> &trim_instructions) const;

fcmp::curve_trees::CurveTreesV1::LastHashes get_last_hashes_to_trim(
const std::vector<fcmp::curve_trees::TrimLayerInstructions> &trim_instructions) const;
fcmp_pp::curve_trees::CurveTreesV1::LastHashes get_last_hashes_to_trim(
const std::vector<fcmp_pp::curve_trees::TrimLayerInstructions> &trim_instructions) const;

template<typename C_CHILD, typename C_PARENT>
bool audit_layer(const std::unique_ptr<C_CHILD> &c_child,
Expand All @@ -449,7 +449,7 @@ class BlockchainLMDB : public BlockchainDB
const uint64_t child_chunk_idx,
const uint64_t chunk_width) const;

std::vector<fcmp::curve_trees::LeafTupleContext> get_leaf_tuples_at_unlock_block_id(uint64_t block_id);
std::vector<fcmp_pp::curve_trees::LeafTupleContext> get_leaf_tuples_at_unlock_block_id(uint64_t block_id);

void del_locked_leaf_tuples_at_block_id(uint64_t block_id);

Expand Down
Loading

0 comments on commit d4847f6

Please sign in to comment.