diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 8952904e84..cf15cbae00 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -3036,9 +3036,8 @@ void nano::election::compute_rep_votes (nano::transaction const & transaction_a) } } -void nano::election::confirm_once (nano::transaction const & transaction_a, uint8_t & depth_a) +void nano::election::confirm_once (nano::transaction const & transaction_a, bool confirmed_back) { - depth_a++; if (!confirmed.exchange (true)) { status.election_end = std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()); @@ -3050,22 +3049,30 @@ void nano::election::confirm_once (nano::transaction const & transaction_a, uint node_l->process_confirmed (winner_l); confirmation_action_l (winner_l); }); - confirm_back (transaction_a, depth_a); + if (!confirmed_back) + { + confirm_back (transaction_a); + } } } -void nano::election::confirm_back (nano::transaction const & transaction_a, uint8_t & depth_a) +void nano::election::confirm_back (nano::transaction const & transaction_a) { - std::vector hashes = { status.winner->previous (), status.winner->source (), status.winner->link () }; - for (auto & hash : hashes) + std::deque hashes = { status.winner->previous (), status.winner->source (), status.winner->link () }; + while (!hashes.empty ()) { - // Depth is limited to 200 - if (!hash.is_zero () && !node.ledger.is_epoch_link (hash) && depth_a < 200) + auto hash (hashes.front ()); + hashes.pop_front (); + if (!hash.is_zero () && !node.ledger.is_epoch_link (hash)) { auto existing (node.active.blocks.find (hash)); if (existing != node.active.blocks.end () && !existing->second->confirmed && !existing->second->stopped && existing->second->blocks.size () == 1) { - existing->second->confirm_once (transaction_a, depth_a); + release_assert (existing->second->status.winner->hash () == hash); + existing->second->confirm_once (transaction_a, true); // Avoid recursive actions + hashes.push_back (existing->second->status.winner->previous ()); + hashes.push_back (existing->second->status.winner->source ()); + hashes.push_back (existing->second->status.winner->link ()); } } } @@ -3135,8 +3142,7 @@ void nano::election::confirm_if_quorum (nano::transaction const & transaction_a) { log_votes (tally_l); } - uint8_t depth (0); - confirm_once (transaction_a, depth); + confirm_once (transaction_a); } } diff --git a/nano/node/node.hpp b/nano/node/node.hpp index c25c170fca..c627e8188a 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -64,8 +64,8 @@ class election_vote_result class election : public std::enable_shared_from_this { std::function)> confirmation_action; - void confirm_once (nano::transaction const &, uint8_t &); - void confirm_back (nano::transaction const &, uint8_t &); + void confirm_once (nano::transaction const &, bool = false); + void confirm_back (nano::transaction const &); public: election (nano::node &, std::shared_ptr, std::function)> const &);