Skip to content

Commit

Permalink
Calculate votes for local representatives in block_confirm (#1534)
Browse files Browse the repository at this point in the history
* Add recursive_mutex to foreach_representative

To prevent node.unlock_search assert

Initially part of v17 #1409

* Calculate votes for local representatives in block_confirm

* Use vote_generator

* Fix

* Make vote_generator public

* Improve node.unlock_search test

* Formatting
  • Loading branch information
SergiySW authored Jan 28, 2019
1 parent 4e4b597 commit dcc2d0f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ TEST (node, unlock_search)
{
ASSERT_NO_ERROR (system.poll ());
}
while (!system.nodes[0]->active.roots.empty ())
{
ASSERT_NO_ERROR (system.poll ());
}
system.wallet (0)->insert_adhoc (key2.prv);
{
std::lock_guard<std::recursive_mutex> lock (system.wallet (0)->store.mutex);
Expand Down
5 changes: 5 additions & 0 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2635,6 +2635,11 @@ void nano::node::block_confirm (std::shared_ptr<nano::block> block_a)
{
active.start (block_a);
network.broadcast_confirm_req (block_a);
// Calculate votes for local representatives
if (config.enable_voting && active.active (*block_a))
{
block_processor.generator.add (block_a->hash ());
}
}

nano::uint128_t nano::node::delta ()
Expand Down
2 changes: 1 addition & 1 deletion nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ class block_processor
bool have_blocks ();
void process_blocks ();
nano::process_return process_one (nano::transaction const &, std::shared_ptr<nano::block>, std::chrono::steady_clock::time_point = std::chrono::steady_clock::now (), bool = false);
nano::vote_generator generator;

private:
void queue_unchecked (nano::transaction const &, nano::block_hash const &, std::chrono::steady_clock::time_point = std::chrono::steady_clock::time_point ());
Expand All @@ -454,7 +455,6 @@ class block_processor
static size_t const rolled_back_max = 1024;
std::condition_variable condition;
nano::node & node;
nano::vote_generator generator;
std::mutex mutex;
};
class node : public std::enable_shared_from_this<nano::node>
Expand Down

0 comments on commit dcc2d0f

Please sign in to comment.