From c46a4a17183f4d9e6294bbfa927c59a6ecdc91a6 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Thu, 10 Jan 2019 19:56:41 +0300 Subject: [PATCH] Limit recursive confirm_back () (#1570) --- nano/node/node.cpp | 15 +++++++++------ nano/node/node.hpp | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 759577e29..e3bb30d1f 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -2980,8 +2980,9 @@ void nano::election::compute_rep_votes (nano::transaction const & transaction_a) } } -void nano::election::confirm_once (nano::transaction const & transaction_a) +void nano::election::confirm_once (nano::transaction const & transaction_a, uint8_t & depth_a) { + depth_a++; if (!confirmed.exchange (true)) { status.election_end = std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()); @@ -2993,21 +2994,22 @@ void nano::election::confirm_once (nano::transaction const & transaction_a) node_l->process_confirmed (winner_l); confirmation_action_l (winner_l); }); - confirm_back (transaction_a); + confirm_back (transaction_a, depth_a); } } -void nano::election::confirm_back (nano::transaction const & transaction_a) +void nano::election::confirm_back (nano::transaction const & transaction_a, uint8_t & depth_a) { std::vector hashes = { status.winner->previous (), status.winner->source (), status.winner->link () }; for (auto & hash : hashes) { - if (!hash.is_zero () && !node.ledger.is_epoch_link (hash)) + // Depth is limited to 200 + if (!hash.is_zero () && !node.ledger.is_epoch_link (hash) && depth_a < 200) { 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); + existing->second->confirm_once (transaction_a, depth_a); } } } @@ -3077,7 +3079,8 @@ void nano::election::confirm_if_quorum (nano::transaction const & transaction_a) { log_votes (tally_l); } - confirm_once (transaction_a); + uint8_t depth (0); + confirm_once (transaction_a, depth); } } diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 13bf27b5d..2a161a7b9 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -50,8 +50,8 @@ public: class election : public std::enable_shared_from_this { std::function)> confirmation_action; - void confirm_once (nano::transaction const &); - void confirm_back (nano::transaction const &); + void confirm_once (nano::transaction const &, uint8_t &); + void confirm_back (nano::transaction const &, uint8_t &); public: election (nano::node &, std::shared_ptr, std::function)> const &);