Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit test bootstrap_processor.lazy_pruning_missing_block #4575

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,6 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build ();
node1->process_active (send1);

// send from genesis to key2
auto send2 = builder
Expand All @@ -1340,7 +1339,6 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (send1->hash ()))
.build ();
node1->process_active (send2);

// open account key1
auto open = builder
Expand All @@ -1351,7 +1349,6 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
.sign (key1.prv, key1.pub)
.work (*system.work.generate (key1.pub))
.build ();
node1->process_active (open);

// open account key2
auto state_open = builder
Expand All @@ -1365,11 +1362,13 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
.work (*system.work.generate (key2.pub))
.build ();

node1->process_active (state_open);
ASSERT_TIMELY (5s, node1->block (state_open->hash ()) != nullptr);
// Confirm last block to prune previous
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1, send2, open, state_open }, true));
ASSERT_TIMELY (5s, nano::test::confirmed (*node1, { send2, open, state_open }));
// add the blocks without starting elections because elections publish blocks
// and the publishing would interefere with the testing
std::vector<std::shared_ptr<nano::block>> const blocks{ send1, send2, open, state_open };
ASSERT_TRUE (nano::test::process (*node1, blocks));
ASSERT_TIMELY (5s, nano::test::exists (*node1, blocks));
nano::test::force_confirm (node1->ledger, blocks);
ASSERT_TIMELY (5s, nano::test::confirmed (*node1, blocks));
ASSERT_EQ (5, node1->ledger.block_count ());
ASSERT_EQ (5, node1->ledger.cemented_count ());

Expand Down
6 changes: 6 additions & 0 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,3 +1594,9 @@ std::unique_ptr<nano::container_info_component> nano::ledger::collect_container_
composite->add_component (cache.rep_weights.collect_container_info ("rep_weights"));
return composite;
}

void nano::ledger::force_confirm (secure::write_transaction const & transaction, nano::block const & block)
{
release_assert (*constants.genesis == *constants.nano_dev_genesis);
confirm (transaction, block);
}
3 changes: 3 additions & 0 deletions nano/secure/ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,8 @@ class ledger final
std::optional<std::pair<nano::pending_key, nano::pending_info>> receivable_lower_bound (secure::transaction const & tx, nano::account const & account, nano::block_hash const & hash) const;
void initialize (nano::generate_cache_flags const &);
void confirm (secure::write_transaction const & transaction, nano::block const & block);

public: // Only used in tests
void force_confirm (secure::write_transaction const & transaction, nano::block const & block);
};
}
8 changes: 8 additions & 0 deletions nano/test_common/testutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ bool nano::test::exists (nano::node & node, std::vector<std::shared_ptr<nano::bl
return exists (node, blocks_to_hashes (blocks));
}

void nano::test::force_confirm (nano::ledger & ledger, std::vector<std::shared_ptr<nano::block>> const blocks)
{
for (auto const block : blocks)
{
ledger.force_confirm (ledger.tx_begin_write (), *block);
}
}

bool nano::test::block_or_pruned_all_exists (nano::node & node, std::vector<nano::block_hash> hashes)
{
auto transaction = node.ledger.tx_begin_read ();
Expand Down
6 changes: 6 additions & 0 deletions nano/test_common/testutil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ namespace test
* @return true if all blocks are fully processed and inserted in the ledger, false otherwise
*/
bool exists (nano::node & node, std::vector<std::shared_ptr<nano::block>> blocks);
/*
* Convenience function to confirm/cement a block in the ledger by setting the confirmation
* height of the account to be the height of the block.
* The blocks are confirmed in the order that they are given.
*/
void force_confirm (nano::ledger & ledger, std::vector<std::shared_ptr<nano::block>> const blocks);
/*
* Convenience function to check whether *all* of the hashes exists in node ledger or in the pruned table.
* @return true if all blocks are fully processed and inserted in the ledger, false otherwise
Expand Down
Loading