This commit is contained in:
Piotr Wójcik 2024-10-16 13:01:00 +02:00
commit b9f02254d0
4 changed files with 16 additions and 22 deletions

View file

@ -1398,6 +1398,8 @@ TEST (active_elections, bound_election_winners)
nano::node_config config = system.default_config ();
// Set election winner limit to a low value
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);
// 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);
// 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);
int index = 0;
for (; index < config.active_elections.max_election_winners; ++index)
for (auto const & block : blocks)
{
auto election = node.vote_router.election (blocks[index]->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 ());
auto election = node.vote_router.election (block->hash ());
ASSERT_TRUE (election);
election->force_confirm ();
}

View file

@ -40,13 +40,9 @@ nano::active_elections::active_elections (nano::node & node_a, nano::confirming_
// Notify elections about alternative (forked) blocks
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);
break;
default:
break;
publish (context.block);
}
});
}

View file

@ -48,6 +48,11 @@ void nano::confirming_set::start ()
{
debug_assert (!thread.joinable ());
if (!config.enable)
{
return;
}
thread = std::thread{ [this] () {
nano::thread_role::set (nano::thread_role::name::confirmation_height);
run ();
@ -123,7 +128,7 @@ void nano::confirming_set::run_batch (std::unique_lock<std::mutex> & lock)
std::deque<context> cemented;
std::deque<nano::block_hash> already;
auto batch = next_batch (batch_size);
auto batch = next_batch (config.batch_size);
lock.unlock ();

View file

@ -28,6 +28,9 @@ public:
// TODO: Serialization & deserialization
public:
bool enable{ true };
size_t batch_size{ 256 };
/** Maximum number of dependent blocks to be stored in memory during processing */
size_t max_blocks{ 128 * 1024 };
size_t max_queued_notifications{ 8 };
@ -106,7 +109,5 @@ private:
mutable std::mutex mutex;
std::condition_variable condition;
std::thread thread;
static size_t constexpr batch_size = 256;
};
}