Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make confirm_back () non-recursive #1754

Merged
merged 3 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::milliseconds> (std::chrono::system_clock::now ().time_since_epoch ());
Expand All @@ -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<nano::block_hash> hashes = { status.winner->previous (), status.winner->source (), status.winner->link () };
for (auto & hash : hashes)
std::deque<nano::block_hash> 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 ());
}
}
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class election_vote_result
class election : public std::enable_shared_from_this<nano::election>
{
std::function<void(std::shared_ptr<nano::block>)> 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<nano::block>, std::function<void(std::shared_ptr<nano::block>)> const &);
Expand Down