Fix test
This commit is contained in:
parent
e456b2282b
commit
b9f02254d0
4 changed files with 16 additions and 22 deletions
|
|
@ -1398,6 +1398,8 @@ TEST (active_elections, bound_election_winners)
|
||||||
nano::node_config config = system.default_config ();
|
nano::node_config config = system.default_config ();
|
||||||
// Set election winner limit to a low value
|
// Set election winner limit to a low value
|
||||||
config.active_elections.max_election_winners = 5;
|
config.active_elections.max_election_winners = 5;
|
||||||
|
// Large batch size would complicate this testcase
|
||||||
|
config.confirming_set.batch_size = 1;
|
||||||
auto & node = *system.add_node (config);
|
auto & node = *system.add_node (config);
|
||||||
|
|
||||||
// Start elections for a couple of blocks, number of elections is larger than the election winner set limit
|
// Start elections for a couple of blocks, number of elections is larger than the election winner set limit
|
||||||
|
|
@ -1411,22 +1413,12 @@ TEST (active_elections, bound_election_winners)
|
||||||
auto guard = node.ledger.tx_begin_write (nano::store::writer::testing);
|
auto guard = node.ledger.tx_begin_write (nano::store::writer::testing);
|
||||||
|
|
||||||
// Ensure that when the number of election winners reaches the limit, AEC vacancy reflects that
|
// Ensure that when the number of election winners reaches the limit, AEC vacancy reflects that
|
||||||
|
// Confirming more elections should make the vacancy negative
|
||||||
ASSERT_TRUE (node.active.vacancy (nano::election_behavior::priority) > 0);
|
ASSERT_TRUE (node.active.vacancy (nano::election_behavior::priority) > 0);
|
||||||
|
|
||||||
int index = 0;
|
for (auto const & block : blocks)
|
||||||
for (; index < config.active_elections.max_election_winners; ++index)
|
|
||||||
{
|
{
|
||||||
auto election = node.vote_router.election (blocks[index]->hash ());
|
auto election = node.vote_router.election (block->hash ());
|
||||||
ASSERT_TRUE (election);
|
|
||||||
election->force_confirm ();
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT_TIMELY_EQ (5s, node.active.vacancy (nano::election_behavior::priority), 0);
|
|
||||||
|
|
||||||
// Confirming more elections should make the vacancy negative
|
|
||||||
for (; index < blocks.size (); ++index)
|
|
||||||
{
|
|
||||||
auto election = node.vote_router.election (blocks[index]->hash ());
|
|
||||||
ASSERT_TRUE (election);
|
ASSERT_TRUE (election);
|
||||||
election->force_confirm ();
|
election->force_confirm ();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,9 @@ nano::active_elections::active_elections (nano::node & node_a, nano::confirming_
|
||||||
|
|
||||||
// Notify elections about alternative (forked) blocks
|
// Notify elections about alternative (forked) blocks
|
||||||
block_processor.block_processed.add ([this] (auto const & result, auto const & context) {
|
block_processor.block_processed.add ([this] (auto const & result, auto const & context) {
|
||||||
switch (result)
|
if (result == nano::block_status::fork)
|
||||||
{
|
{
|
||||||
case nano::block_status::fork:
|
|
||||||
publish (context.block);
|
publish (context.block);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,11 @@ void nano::confirming_set::start ()
|
||||||
{
|
{
|
||||||
debug_assert (!thread.joinable ());
|
debug_assert (!thread.joinable ());
|
||||||
|
|
||||||
|
if (!config.enable)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
thread = std::thread{ [this] () {
|
thread = std::thread{ [this] () {
|
||||||
nano::thread_role::set (nano::thread_role::name::confirmation_height);
|
nano::thread_role::set (nano::thread_role::name::confirmation_height);
|
||||||
run ();
|
run ();
|
||||||
|
|
@ -123,7 +128,7 @@ void nano::confirming_set::run_batch (std::unique_lock<std::mutex> & lock)
|
||||||
std::deque<context> cemented;
|
std::deque<context> cemented;
|
||||||
std::deque<nano::block_hash> already;
|
std::deque<nano::block_hash> already;
|
||||||
|
|
||||||
auto batch = next_batch (batch_size);
|
auto batch = next_batch (config.batch_size);
|
||||||
|
|
||||||
lock.unlock ();
|
lock.unlock ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,9 @@ public:
|
||||||
// TODO: Serialization & deserialization
|
// TODO: Serialization & deserialization
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
bool enable{ true };
|
||||||
|
size_t batch_size{ 256 };
|
||||||
|
|
||||||
/** Maximum number of dependent blocks to be stored in memory during processing */
|
/** Maximum number of dependent blocks to be stored in memory during processing */
|
||||||
size_t max_blocks{ 128 * 1024 };
|
size_t max_blocks{ 128 * 1024 };
|
||||||
size_t max_queued_notifications{ 8 };
|
size_t max_queued_notifications{ 8 };
|
||||||
|
|
@ -106,7 +109,5 @@ private:
|
||||||
mutable std::mutex mutex;
|
mutable std::mutex mutex;
|
||||||
std::condition_variable condition;
|
std::condition_variable condition;
|
||||||
std::thread thread;
|
std::thread thread;
|
||||||
|
|
||||||
static size_t constexpr batch_size = 256;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue