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

Use a read transaction for non-final vote generator. #4321

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
25 changes: 18 additions & 7 deletions nano/node/voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,21 @@ nano::vote_generator::~vote_generator ()
stop ();
}

void nano::vote_generator::process (store::write_transaction const & transaction, nano::root const & root_a, nano::block_hash const & hash_a)
void nano::vote_generator::process (std::optional<store::write_transaction> & final_write, std::optional<store::read_transaction> & non_final_read, nano::root const & root_a, nano::block_hash const & hash_a)
{
bool should_vote = false;
if (is_final)
{
auto block (ledger.store.block.get (transaction, hash_a));
should_vote = block != nullptr && ledger.dependents_confirmed (transaction, *block) && ledger.store.final_vote.put (transaction, block->qualified_root (), hash_a);
debug_assert (final_write);
auto block (ledger.store.block.get (*final_write, hash_a));
should_vote = block != nullptr && ledger.dependents_confirmed (*final_write, *block) && ledger.store.final_vote.put (*final_write, block->qualified_root (), hash_a);
debug_assert (block == nullptr || root_a == block->root ());
}
else
{
auto block (ledger.store.block.get (transaction, hash_a));
should_vote = block != nullptr && ledger.dependents_confirmed (transaction, *block);
debug_assert (non_final_read);
auto block (ledger.store.block.get (*non_final_read, hash_a));
should_vote = block != nullptr && ledger.dependents_confirmed (*non_final_read, *block);
}
if (should_vote)
{
Expand Down Expand Up @@ -241,11 +243,20 @@ void nano::vote_generator::add (const root & root, const block_hash & hash)

void nano::vote_generator::process_batch (std::deque<queue_entry_t> & batch)
{
auto transaction = ledger.store.tx_begin_write ({ tables::final_votes });
std::optional<store::write_transaction> final_write;
std::optional<store::read_transaction> non_final_read;
if (is_final)
{
final_write = ledger.store.tx_begin_write ({ tables::final_votes });
}
else
{
non_final_read = ledger.store.tx_begin_read ();
}

for (auto & [root, hash] : batch)
{
process (transaction, root, hash);
process (final_write, non_final_read, root, hash);
}
}

Expand Down
2 changes: 1 addition & 1 deletion nano/node/voting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class vote_generator final
* Check if block is eligible for vote generation, then generates a vote or broadcasts votes already in cache
* @param transaction : needs `tables::final_votes` lock
*/
void process (store::write_transaction const &, nano::root const &, nano::block_hash const &);
void process (std::optional<store::write_transaction> & final_write, std::optional<store::read_transaction> & non_final_read, nano::root const &, nano::block_hash const &);

private:
std::function<void (std::shared_ptr<nano::vote> const &, std::shared_ptr<nano::transport::channel> &)> reply_action; // must be set only during initialization by using set_reply_action
Expand Down
Loading