diff --git a/nano/node/voting.cpp b/nano/node/voting.cpp index b8f1dba707..0024bd734d 100644 --- a/nano/node/voting.cpp +++ b/nano/node/voting.cpp @@ -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 & final_write, std::optional & 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) { @@ -241,11 +243,20 @@ void nano::vote_generator::add (const root & root, const block_hash & hash) void nano::vote_generator::process_batch (std::deque & batch) { - auto transaction = ledger.store.tx_begin_write ({ tables::final_votes }); + std::optional final_write; + std::optional 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); } } diff --git a/nano/node/voting.hpp b/nano/node/voting.hpp index 13f113b106..d06614021b 100644 --- a/nano/node/voting.hpp +++ b/nano/node/voting.hpp @@ -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 & final_write, std::optional & non_final_read, nano::root const &, nano::block_hash const &); private: std::function const &, std::shared_ptr &)> reply_action; // must be set only during initialization by using set_reply_action