From dcc2d0f5e0495d60fc5efff142793a67c609c42a Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Mon, 28 Jan 2019 20:33:17 +0300 Subject: [PATCH] Calculate votes for local representatives in block_confirm (#1534) * Add recursive_mutex to foreach_representative To prevent node.unlock_search assert Initially part of v17 https://github.com/nanocurrency/raiblocks/pull/1409 * Calculate votes for local representatives in block_confirm * Use vote_generator * Fix * Make vote_generator public * Improve node.unlock_search test * Formatting --- nano/core_test/node.cpp | 4 ++++ nano/node/node.cpp | 5 +++++ nano/node/node.hpp | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 8f7c10e0..3590485b 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -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 lock (system.wallet (0)->store.mutex); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 99acbdc6..4e1a35dc 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -2635,6 +2635,11 @@ void nano::node::block_confirm (std::shared_ptr 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 () diff --git a/nano/node/node.hpp b/nano/node/node.hpp index aa636e6b..e69a8e80 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -433,6 +433,7 @@ public: bool have_blocks (); void process_blocks (); nano::process_return process_one (nano::transaction const &, std::shared_ptr, 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 ()); @@ -454,7 +455,6 @@ private: 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