Convenience function for block_or_pruned_exists (#4393)
Convenience function for block_or_pruned_exists
This commit is contained in:
parent
92ef79ed54
commit
afcbde1928
5 changed files with 62 additions and 41 deletions
|
@ -1126,10 +1126,7 @@ TEST (bootstrap_processor, DISABLED_lazy_unclear_state_link)
|
|||
node2->bootstrap_initiator.bootstrap_lazy (receive->hash ());
|
||||
// Check processed blocks
|
||||
ASSERT_TIMELY (10s, !node2->bootstrap_initiator.in_progress ());
|
||||
ASSERT_TIMELY (5s, node2->ledger.block_or_pruned_exists (send1->hash ()));
|
||||
ASSERT_TIMELY (5s, node2->ledger.block_or_pruned_exists (send2->hash ()));
|
||||
ASSERT_TIMELY (5s, node2->ledger.block_or_pruned_exists (open->hash ()));
|
||||
ASSERT_TIMELY (5s, node2->ledger.block_or_pruned_exists (receive->hash ()));
|
||||
ASSERT_TIMELY (5s, nano::test::block_or_pruned_all_exists (*node2, { send1, send2, open, receive }));
|
||||
ASSERT_EQ (0, node2->stats.count (nano::stat::type::bootstrap, nano::stat::detail::bulk_pull_failed_account, nano::stat::dir::in));
|
||||
}
|
||||
|
||||
|
@ -1185,9 +1182,7 @@ TEST (bootstrap_processor, lazy_unclear_state_link_not_existing)
|
|||
node2->bootstrap_initiator.bootstrap_lazy (send2->hash ());
|
||||
// Check processed blocks
|
||||
ASSERT_TIMELY (15s, !node2->bootstrap_initiator.in_progress ());
|
||||
ASSERT_TIMELY (5s, node2->ledger.block_or_pruned_exists (send1->hash ()));
|
||||
ASSERT_TIMELY (5s, node2->ledger.block_or_pruned_exists (open->hash ()));
|
||||
ASSERT_TIMELY (5s, node2->ledger.block_or_pruned_exists (send2->hash ()));
|
||||
ASSERT_TIMELY (15s, nano::test::block_or_pruned_all_exists (*node2, { send1, open, send2 }));
|
||||
ASSERT_EQ (1, node2->stats.count (nano::stat::type::bootstrap, nano::stat::detail::bulk_pull_failed_account, nano::stat::dir::in));
|
||||
}
|
||||
|
||||
|
@ -1254,10 +1249,7 @@ TEST (bootstrap_processor, DISABLED_lazy_destinations)
|
|||
node2->bootstrap_initiator.bootstrap_lazy (send2->hash ());
|
||||
// Check processed blocks
|
||||
ASSERT_TIMELY (10s, !node2->bootstrap_initiator.in_progress ());
|
||||
ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send1->hash ()));
|
||||
ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send2->hash ()));
|
||||
ASSERT_TRUE (node2->ledger.block_or_pruned_exists (open->hash ()));
|
||||
ASSERT_TRUE (node2->ledger.block_or_pruned_exists (state_open->hash ()));
|
||||
ASSERT_TRUE (nano::test::block_or_pruned_all_exists (*node2, { send1, send2, open, state_open }));
|
||||
}
|
||||
|
||||
TEST (bootstrap_processor, lazy_pruning_missing_block)
|
||||
|
@ -1329,10 +1321,7 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
|
|||
node1->ledger_pruning (2, false);
|
||||
ASSERT_EQ (5, node1->ledger.cache.block_count);
|
||||
ASSERT_EQ (1, node1->ledger.cache.pruned_count);
|
||||
ASSERT_TRUE (node1->ledger.block_or_pruned_exists (send1->hash ())); // true for pruned
|
||||
ASSERT_TRUE (node1->ledger.block_or_pruned_exists (send2->hash ()));
|
||||
ASSERT_TRUE (node1->ledger.block_or_pruned_exists (open->hash ()));
|
||||
ASSERT_TRUE (node1->ledger.block_or_pruned_exists (state_open->hash ()));
|
||||
ASSERT_TRUE (nano::test::block_or_pruned_all_exists (*node1, { send1, send2, open, state_open }));
|
||||
// Start lazy bootstrap with last block in sender chain
|
||||
config.peering_port = system.get_available_port ();
|
||||
auto node2 (std::make_shared<nano::node> (system.io_ctx, nano::unique_path (), config, system.work, node_flags, 1));
|
||||
|
@ -1345,10 +1334,7 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
|
|||
// Some blocks cannot be retrieved from pruned node
|
||||
node2->block_processor.flush ();
|
||||
ASSERT_EQ (1, node2->ledger.cache.block_count);
|
||||
ASSERT_FALSE (node2->ledger.block_or_pruned_exists (send1->hash ()));
|
||||
ASSERT_FALSE (node2->ledger.block_or_pruned_exists (send2->hash ()));
|
||||
ASSERT_FALSE (node2->ledger.block_or_pruned_exists (open->hash ()));
|
||||
ASSERT_FALSE (node2->ledger.block_or_pruned_exists (state_open->hash ()));
|
||||
ASSERT_TRUE (nano::test::block_or_pruned_none_exists (*node2, { send1, send2, open, state_open }));
|
||||
{
|
||||
auto transaction (node2->store.tx_begin_read ());
|
||||
ASSERT_TRUE (node2->unchecked.exists (nano::unchecked_key (send2->root ().as_block_hash (), send2->hash ())));
|
||||
|
@ -1359,10 +1345,8 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
|
|||
ASSERT_TIMELY (5s, !node2->bootstrap_initiator.in_progress ());
|
||||
node2->block_processor.flush ();
|
||||
ASSERT_EQ (3, node2->ledger.cache.block_count);
|
||||
ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send1->hash ()));
|
||||
ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send2->hash ()));
|
||||
ASSERT_FALSE (node2->ledger.block_or_pruned_exists (open->hash ()));
|
||||
ASSERT_FALSE (node2->ledger.block_or_pruned_exists (state_open->hash ()));
|
||||
ASSERT_TRUE (nano::test::block_or_pruned_all_exists (*node2, { send1, send2 }));
|
||||
ASSERT_TRUE (nano::test::block_or_pruned_none_exists (*node2, { open, state_open }));
|
||||
node2->stop ();
|
||||
}
|
||||
|
||||
|
@ -2034,9 +2018,7 @@ TEST (bulk, DISABLED_genesis_pruning)
|
|||
node1->ledger_pruning (2, false);
|
||||
ASSERT_EQ (2, node1->ledger.cache.pruned_count);
|
||||
ASSERT_EQ (4, node1->ledger.cache.block_count);
|
||||
ASSERT_TRUE (node1->ledger.block_or_pruned_exists (send1->hash ())); // true for pruned
|
||||
ASSERT_TRUE (node1->ledger.block_or_pruned_exists (send2->hash ())); // true for pruned
|
||||
ASSERT_TRUE (node1->ledger.block_or_pruned_exists (send3->hash ()));
|
||||
ASSERT_TRUE (nano::test::block_or_pruned_all_exists (*node2, { send1, send2, send3 }));
|
||||
// Bootstrap with missing blocks for node2
|
||||
node2->bootstrap_initiator.bootstrap (node1->network.endpoint (), false);
|
||||
node2->network.merge_peer (node1->network.endpoint ());
|
||||
|
|
|
@ -816,16 +816,14 @@ TEST (node, fork_multi_flip)
|
|||
ASSERT_NE (nullptr, election1);
|
||||
ASSERT_EQ (1, election1->votes ().size ());
|
||||
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (publish1.block->hash ()));
|
||||
ASSERT_TRUE (node2.ledger.block_or_pruned_exists (publish2.block->hash ()));
|
||||
ASSERT_TRUE (node2.ledger.block_or_pruned_exists (publish3.block->hash ()));
|
||||
ASSERT_TRUE (nano::test::block_or_pruned_all_exists (node2, { publish2.block, publish3.block }));
|
||||
ASSERT_TIMELY (10s, node2.ledger.block_or_pruned_exists (publish1.block->hash ()));
|
||||
auto winner (*election1->tally ().begin ());
|
||||
ASSERT_EQ (*publish1.block, *winner.second);
|
||||
ASSERT_EQ (nano::dev::constants.genesis_amount - 100, winner.first);
|
||||
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (publish1.block->hash ()));
|
||||
ASSERT_TRUE (node2.ledger.block_or_pruned_exists (publish1.block->hash ()));
|
||||
ASSERT_FALSE (node2.ledger.block_or_pruned_exists (publish2.block->hash ()));
|
||||
ASSERT_FALSE (node2.ledger.block_or_pruned_exists (publish3.block->hash ()));
|
||||
ASSERT_TRUE (nano::test::block_or_pruned_none_exists (node2, { publish2.block, publish3.block }));
|
||||
}
|
||||
|
||||
// Blocks that are no longer actively being voted on should be able to be evicted through bootstrapping.
|
||||
|
@ -4180,9 +4178,7 @@ TEST (node, pruning_automatic)
|
|||
ASSERT_EQ (1, node1.ledger.cache.pruned_count);
|
||||
ASSERT_EQ (3, node1.ledger.cache.block_count);
|
||||
|
||||
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (nano::dev::genesis->hash ()));
|
||||
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (send1->hash ()));
|
||||
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (send2->hash ()));
|
||||
ASSERT_TRUE (nano::test::block_or_pruned_all_exists (node1, { nano::dev::genesis, send1, send2 }));
|
||||
}
|
||||
|
||||
TEST (node, pruning_age)
|
||||
|
@ -4241,9 +4237,7 @@ TEST (node, pruning_age)
|
|||
ASSERT_EQ (1, node1.ledger.cache.pruned_count);
|
||||
ASSERT_EQ (3, node1.ledger.cache.block_count);
|
||||
|
||||
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (nano::dev::genesis->hash ()));
|
||||
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (send1->hash ()));
|
||||
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (send2->hash ()));
|
||||
ASSERT_TRUE (nano::test::block_or_pruned_all_exists (node1, { nano::dev::genesis, send1, send2 }));
|
||||
}
|
||||
|
||||
// Test that a node configured with `enable_pruning` will
|
||||
|
@ -4304,9 +4298,7 @@ TEST (node, pruning_depth)
|
|||
ASSERT_EQ (1, node1.ledger.cache.pruned_count);
|
||||
ASSERT_EQ (3, node1.ledger.cache.block_count);
|
||||
|
||||
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (nano::dev::genesis->hash ()));
|
||||
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (send1->hash ()));
|
||||
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (send2->hash ()));
|
||||
ASSERT_TRUE (nano::test::block_or_pruned_all_exists (node1, { nano::dev::genesis, send1, send2 }));
|
||||
}
|
||||
|
||||
TEST (node_config, node_id_private_key_persistence)
|
||||
|
|
|
@ -6502,8 +6502,7 @@ TEST (rpc, account_lazy_start)
|
|||
|
||||
// needs timed assert because the writing (put) operation is done by a different
|
||||
// thread, it might not get done before DB get operation.
|
||||
ASSERT_TIMELY (10s, node2->ledger.block_or_pruned_exists (send1->hash ()));
|
||||
ASSERT_TIMELY (10s, node2->ledger.block_or_pruned_exists (open->hash ()));
|
||||
ASSERT_TIMELY (15s, nano::test::block_or_pruned_all_exists (*node2, { send1, open }));
|
||||
}
|
||||
|
||||
TEST (rpc, receive)
|
||||
|
|
|
@ -115,6 +115,34 @@ bool nano::test::exists (nano::node & node, std::vector<std::shared_ptr<nano::bl
|
|||
return exists (node, blocks_to_hashes (blocks));
|
||||
}
|
||||
|
||||
bool nano::test::block_or_pruned_all_exists (nano::node & node, std::vector<nano::block_hash> hashes)
|
||||
{
|
||||
auto transaction = node.store.tx_begin_read ();
|
||||
return std::all_of (hashes.begin (), hashes.end (),
|
||||
[&] (const auto & hash) {
|
||||
return node.ledger.block_or_pruned_exists (transaction, hash);
|
||||
});
|
||||
}
|
||||
|
||||
bool nano::test::block_or_pruned_all_exists (nano::node & node, std::vector<std::shared_ptr<nano::block>> blocks)
|
||||
{
|
||||
return block_or_pruned_all_exists (node, blocks_to_hashes (blocks));
|
||||
}
|
||||
|
||||
bool nano::test::block_or_pruned_none_exists (nano::node & node, std::vector<nano::block_hash> hashes)
|
||||
{
|
||||
auto transaction = node.store.tx_begin_read ();
|
||||
return std::none_of (hashes.begin (), hashes.end (),
|
||||
[&] (const auto & hash) {
|
||||
return node.ledger.block_or_pruned_exists (transaction, hash);
|
||||
});
|
||||
}
|
||||
|
||||
bool nano::test::block_or_pruned_none_exists (nano::node & node, std::vector<std::shared_ptr<nano::block>> blocks)
|
||||
{
|
||||
return block_or_pruned_none_exists (node, blocks_to_hashes (blocks));
|
||||
}
|
||||
|
||||
bool nano::test::activate (nano::node & node, std::vector<nano::block_hash> hashes)
|
||||
{
|
||||
for (auto & hash : hashes)
|
||||
|
|
|
@ -300,6 +300,26 @@ 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 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
|
||||
*/
|
||||
bool block_or_pruned_all_exists (nano::node & node, std::vector<nano::block_hash> hashes);
|
||||
/*
|
||||
* Convenience function to check whether *all* of the blocks exists in node ledger or their hash exists in the pruned table.
|
||||
* @return true if all blocks are fully processed and inserted in the ledger, false otherwise
|
||||
*/
|
||||
bool block_or_pruned_all_exists (nano::node & node, std::vector<std::shared_ptr<nano::block>> blocks);
|
||||
/*
|
||||
* Convenience function to check whether *none* of the hashes exists in node ledger or in the pruned table.
|
||||
* @return true if none of the blocks are processed and inserted in the ledger, false otherwise
|
||||
*/
|
||||
bool block_or_pruned_none_exists (nano::node & node, std::vector<nano::block_hash> hashes);
|
||||
/*
|
||||
* Convenience function to check whether *none* of the blocks exists in node ledger or their hash exists in the pruned table.
|
||||
* @return true if none of the blocks are processed and inserted in the ledger, false otherwise
|
||||
*/
|
||||
bool block_or_pruned_none_exists (nano::node & node, std::vector<std::shared_ptr<nano::block>> blocks);
|
||||
/*
|
||||
* Convenience function to start elections for a list of hashes. Blocks are loaded from ledger.
|
||||
* @return true if all blocks exist and were queued to election scheduler
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue