mirror of
https://github.com/monero-project/monero.git
synced 2025-09-27 06:20:55 -04:00
implement db->audit_tree, and flesh out db test to init/extend tree
This commit is contained in:
parent
1ffde095c8
commit
6045357f6a
6 changed files with 315 additions and 22 deletions
|
@ -342,20 +342,9 @@ TYPED_TEST(BlockchainDBTest, RetrieveBlockData)
|
|||
ASSERT_HASH_EQ(get_block_hash(this->m_blocks[1].first), hashes[1]);
|
||||
}
|
||||
|
||||
// TODO: implement this in curve_trees.cpp, consider removing CurveTreesUnitTest class
|
||||
TYPED_TEST(BlockchainDBTest, GrowCurveTrees)
|
||||
{
|
||||
boost::filesystem::path tempPath = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
|
||||
std::string dirPath = tempPath.string();
|
||||
|
||||
this->set_prefix(dirPath);
|
||||
|
||||
// make sure open does not throw
|
||||
ASSERT_NO_THROW(this->m_db->open(dirPath));
|
||||
this->get_filenames();
|
||||
this->init_hard_fork();
|
||||
|
||||
db_wtxn_guard guard(this->m_db);
|
||||
|
||||
Helios helios;
|
||||
Selene selene;
|
||||
|
||||
|
@ -365,10 +354,73 @@ TYPED_TEST(BlockchainDBTest, GrowCurveTrees)
|
|||
HELIOS_CHUNK_WIDTH,
|
||||
SELENE_CHUNK_WIDTH);
|
||||
|
||||
// Grow tree by 1 leaf
|
||||
ASSERT_NO_THROW(this->m_db->grow_tree(curve_trees, generate_random_leaves(curve_trees, 1)));
|
||||
// Number of leaves for which x number of layers is required
|
||||
const std::size_t NEED_1_LAYER = SELENE_CHUNK_WIDTH;
|
||||
const std::size_t NEED_2_LAYERS = NEED_1_LAYER * HELIOS_CHUNK_WIDTH;
|
||||
const std::size_t NEED_3_LAYERS = NEED_2_LAYERS * SELENE_CHUNK_WIDTH;
|
||||
|
||||
// TODO: Validate the tree
|
||||
const std::vector<std::size_t> N_LEAVES{
|
||||
// Basic tests
|
||||
1,
|
||||
2,
|
||||
|
||||
// Test with number of leaves {-1,0,+1} relative to chunk width boundaries
|
||||
NEED_1_LAYER-1,
|
||||
NEED_1_LAYER,
|
||||
NEED_1_LAYER+1,
|
||||
|
||||
NEED_2_LAYERS-1,
|
||||
NEED_2_LAYERS,
|
||||
NEED_2_LAYERS+1,
|
||||
|
||||
NEED_3_LAYERS,
|
||||
};
|
||||
|
||||
for (const std::size_t init_leaves : N_LEAVES)
|
||||
{
|
||||
for (const std::size_t ext_leaves : N_LEAVES)
|
||||
{
|
||||
// Only test 3rd layer once because it's a huge test
|
||||
if (init_leaves > 1 && ext_leaves == NEED_3_LAYERS)
|
||||
continue;
|
||||
if (ext_leaves > 1 && init_leaves == NEED_3_LAYERS)
|
||||
continue;
|
||||
|
||||
boost::filesystem::path tempPath = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
|
||||
std::string dirPath = tempPath.string();
|
||||
|
||||
this->set_prefix(dirPath);
|
||||
|
||||
ASSERT_NO_THROW(this->m_db->open(dirPath));
|
||||
|
||||
this->get_filenames();
|
||||
auto hardfork = HardFork(*this->m_db, 1, 0);
|
||||
this->m_db->set_hard_fork(&hardfork);
|
||||
|
||||
{
|
||||
db_wtxn_guard guard(this->m_db);
|
||||
|
||||
LOG_PRINT_L0("Adding " << init_leaves << " leaves to tree, then extending by " << ext_leaves << " leaves");
|
||||
|
||||
ASSERT_NO_THROW(this->m_db->grow_tree(curve_trees, generate_random_leaves(curve_trees, init_leaves)));
|
||||
ASSERT_TRUE(this->m_db->audit_tree(curve_trees));
|
||||
|
||||
MDEBUG("Successfully added initial " << init_leaves << " leaves to tree, extending tree by "
|
||||
<< ext_leaves << " leaves");
|
||||
|
||||
ASSERT_NO_THROW(this->m_db->grow_tree(curve_trees, generate_random_leaves(curve_trees, ext_leaves)));
|
||||
ASSERT_TRUE(this->m_db->audit_tree(curve_trees));
|
||||
|
||||
MDEBUG("Successfully extended by " << ext_leaves << " leaves");
|
||||
}
|
||||
|
||||
ASSERT_NO_THROW(this->m_db->close());
|
||||
this->remove_files();
|
||||
this->m_db = new BlockchainLMDB();
|
||||
// WARNING: this->m_hardfork is now referencing a freed m_db
|
||||
// TODO: make a cleaner test in curve_trees.cpp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue