Make confirm_back () non-recursive (#1754)
This commit is contained in:
parent
c0356a4e21
commit
42bc83742c
2 changed files with 19 additions and 13 deletions
|
@ -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 ());
|
||||
|
@ -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 ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,8 +64,8 @@ public:
|
|||
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 &);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue