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

Don't escalate confirmed previous/source for elections #2048

Merged
merged 5 commits into from
Jun 1, 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
14 changes: 10 additions & 4 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,31 +133,37 @@ void nano::active_transactions::request_confirm (std::unique_lock<std::mutex> &
if there are less than 100 active elections */
if (election_l->announcements % announcement_long == 1 && roots_size < 100 && !node.network_params.network.is_test_network ())
{
bool escalated (false);
std::shared_ptr<nano::block> previous;
auto previous_hash (election_l->status.winner->previous ());
if (!previous_hash.is_zero ())
{
previous = node.store.block_get (transaction, previous_hash);
if (previous != nullptr)
if (previous != nullptr && blocks.find (previous_hash) == blocks.end () && !node.block_confirmed_or_being_confirmed (transaction, previous_hash))
{
add (std::move (previous));
escalated = true;
}
}
/* If previous block not existing/not commited yet, block_source can cause segfault for state blocks
So source check can be done only if previous != nullptr or previous is 0 (open account) */
if (previous_hash.is_zero () || previous != nullptr)
{
auto source_hash (node.ledger.block_source (transaction, *election_l->status.winner));
if (!source_hash.is_zero ())
if (!source_hash.is_zero () && source_hash != previous_hash && blocks.find (source_hash) == blocks.end ())
{
auto source (node.store.block_get (transaction, source_hash));
if (source != nullptr)
if (source != nullptr && !node.block_confirmed_or_being_confirmed (transaction, source_hash))
{
add (std::move (source));
escalated = true;
}
}
}
election_l->update_dependent ();
if (escalated)
{
election_l->update_dependent ();
}
}
}
if (election_l->announcements < announcement_long || election_l->announcements % announcement_long == could_fit_delay)
Expand Down
6 changes: 0 additions & 6 deletions nano/node/confirmation_height_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ void nano::confirmation_height_processor::add (nano::block_hash const & hash_a)
condition.notify_one ();
}

// This only check top-level blocks having their confirmation height sets, not anything below
bool nano::confirmation_height_processor::is_processing_block (nano::block_hash const & hash_a)
{
return pending_confirmations.is_processing_block (hash_a);
}

/**
* For all the blocks below this height which have been implicitly confirmed check if they
* are open/receive blocks, and if so follow the source blocks and iteratively repeat to genesis.
Expand Down
1 change: 0 additions & 1 deletion nano/node/confirmation_height_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class confirmation_height_processor final
~confirmation_height_processor ();
void add (nano::block_hash const &);
void stop ();
bool is_processing_block (nano::block_hash const &);

/** The maximum amount of accounts to iterate over while writing */
static uint64_t constexpr batch_write_size = 2048;
Expand Down
2 changes: 1 addition & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ void nano::node::block_confirm (std::shared_ptr<nano::block> block_a)

bool nano::node::block_confirmed_or_being_confirmed (nano::transaction const & transaction_a, nano::block_hash const & hash_a)
{
return ledger.block_confirmed (transaction_a, hash_a) || confirmation_height_processor.is_processing_block (hash_a);
return ledger.block_confirmed (transaction_a, hash_a) || pending_confirmation_height.is_processing_block (hash_a);
}

nano::uint128_t nano::node::delta () const
Expand Down
4 changes: 2 additions & 2 deletions nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6122,7 +6122,7 @@ TEST (rpc, block_confirmed)
node->process_active (send);
node->block_processor.flush ();
system.deadline_set (10s);
while (!node->confirmation_height_processor.is_processing_block (send->hash ()))
while (!node->pending_confirmation_height.is_processing_block (send->hash ()))
{
ASSERT_NO_ERROR (system.poll ());
}
Expand All @@ -6141,7 +6141,7 @@ TEST (rpc, block_confirmed)
}

// Should no longer be processing the block after confirmation is set
ASSERT_FALSE (node->confirmation_height_processor.is_processing_block (send->hash ()));
ASSERT_FALSE (node->pending_confirmation_height.is_processing_block (send->hash ()));

// Requesting confirmation for this should now succeed
request.put ("hash", send->hash ().to_string ());
Expand Down