Skip to content

Commit

Permalink
Pass transaction in to end iterator for future use. (#4761)
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu authored Oct 21, 2024
1 parent 902bc4b commit 483c690
Show file tree
Hide file tree
Showing 74 changed files with 211 additions and 208 deletions.
26 changes: 13 additions & 13 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ TEST (block_store, pending_iterator)
auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants);
ASSERT_TRUE (!store->init_error ());
auto transaction (store->tx_begin_write ());
ASSERT_EQ (store->pending.end (), store->pending.begin (transaction));
ASSERT_EQ (store->pending.end (transaction), store->pending.begin (transaction));
store->pending.put (transaction, nano::pending_key (1, 2), { 2, 3, nano::epoch::epoch_1 });
auto current (store->pending.begin (transaction));
ASSERT_NE (store->pending.end (), current);
ASSERT_NE (store->pending.end (transaction), current);
nano::pending_key key1 (current->first);
ASSERT_EQ (nano::account (1), key1.account);
ASSERT_EQ (nano::block_hash (2), key1.hash);
Expand Down Expand Up @@ -411,7 +411,7 @@ TEST (block_store, empty_accounts)
ASSERT_TRUE (!store->init_error ());
auto transaction (store->tx_begin_read ());
auto begin (store->account.begin (transaction));
auto end (store->account.end ());
auto end (store->account.end (transaction));
ASSERT_EQ (end, begin);
}

Expand Down Expand Up @@ -498,7 +498,7 @@ TEST (block_store, one_account)
store->confirmation_height.put (transaction, account, { 20, nano::block_hash (15) });
store->account.put (transaction, account, { hash, account, hash, 42, 100, 200, nano::epoch::epoch_0 });
auto begin (store->account.begin (transaction));
auto end (store->account.end ());
auto end (store->account.end (transaction));
ASSERT_NE (end, begin);
ASSERT_EQ (account, nano::account (begin->first));
nano::account_info info (begin->second);
Expand Down Expand Up @@ -567,7 +567,7 @@ TEST (block_store, two_account)
store->confirmation_height.put (transaction, account2, { 30, nano::block_hash (20) });
store->account.put (transaction, account2, { hash2, account2, hash2, 84, 200, 400, nano::epoch::epoch_0 });
auto begin (store->account.begin (transaction));
auto end (store->account.end ());
auto end (store->account.end (transaction));
ASSERT_NE (end, begin);
ASSERT_EQ (account1, nano::account (begin->first));
nano::account_info info1 (begin->second);
Expand Down Expand Up @@ -787,7 +787,7 @@ TEST (block_store, large_iteration)
std::unordered_set<nano::account> accounts2;
nano::account previous{};
auto transaction (store->tx_begin_read ());
for (auto i (store->account.begin (transaction, 0)), n (store->account.end ()); i != n; ++i)
for (auto i (store->account.begin (transaction, 0)), n (store->account.end (transaction)); i != n; ++i)
{
nano::account current (i->first);
ASSERT_GT (current.number (), previous.number ());
Expand All @@ -798,7 +798,7 @@ TEST (block_store, large_iteration)
// Reverse iteration
std::unordered_set<nano::account> accounts3;
previous = std::numeric_limits<nano::uint256_t>::max ();
for (auto i (store->account.rbegin (transaction)), n (store->account.end ()); i != n; --i)
for (auto i (store->account.rbegin (transaction)), n (store->account.end (transaction)); i != n; --i)
{
nano::account current (i->first);
ASSERT_LT (current.number (), previous.number ());
Expand Down Expand Up @@ -1253,20 +1253,20 @@ TEST (block_store, online_weight)
{
auto transaction (store->tx_begin_write ());
ASSERT_EQ (0, store->online_weight.count (transaction));
ASSERT_EQ (store->online_weight.end (), store->online_weight.begin (transaction));
ASSERT_EQ (store->online_weight.end (), store->online_weight.rbegin (transaction));
ASSERT_EQ (store->online_weight.end (transaction), store->online_weight.begin (transaction));
ASSERT_EQ (store->online_weight.end (transaction), store->online_weight.rbegin (transaction));
store->online_weight.put (transaction, 1, 2);
store->online_weight.put (transaction, 3, 4);
}
{
auto transaction (store->tx_begin_write ());
ASSERT_EQ (2, store->online_weight.count (transaction));
auto item (store->online_weight.begin (transaction));
ASSERT_NE (store->online_weight.end (), item);
ASSERT_NE (store->online_weight.end (transaction), item);
ASSERT_EQ (1, item->first);
ASSERT_EQ (2, item->second.number ());
auto item_last (store->online_weight.rbegin (transaction));
ASSERT_NE (store->online_weight.end (), item_last);
ASSERT_NE (store->online_weight.end (transaction), item_last);
ASSERT_EQ (3, item_last->first);
ASSERT_EQ (4, item_last->second.number ());
store->online_weight.del (transaction, 1);
Expand All @@ -1276,8 +1276,8 @@ TEST (block_store, online_weight)
}
auto transaction (store->tx_begin_read ());
ASSERT_EQ (0, store->online_weight.count (transaction));
ASSERT_EQ (store->online_weight.end (), store->online_weight.begin (transaction));
ASSERT_EQ (store->online_weight.end (), store->online_weight.rbegin (transaction));
ASSERT_EQ (store->online_weight.end (transaction), store->online_weight.begin (transaction));
ASSERT_EQ (store->online_weight.end (transaction), store->online_weight.rbegin (transaction));
}

TEST (block_store, pruned_blocks)
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5464,7 +5464,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb)

ASSERT_TRUE (rocksdb_store.pending.get (rocksdb_transaction, nano::pending_key (nano::dev::genesis_key.pub, send->hash ())));

for (auto i = rocksdb_store.online_weight.begin (rocksdb_transaction); i != rocksdb_store.online_weight.end (); ++i)
for (auto i = rocksdb_store.online_weight.begin (rocksdb_transaction); i != rocksdb_store.online_weight.end (rocksdb_transaction); ++i)
{
ASSERT_EQ (i->first, 100);
ASSERT_EQ (i->second, 2);
Expand Down
8 changes: 4 additions & 4 deletions nano/core_test/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ TEST (system, DISABLED_generate_send_new)
{
auto transaction (node1.store.tx_begin_read ());
auto iterator1 (node1.store.account.begin (transaction));
ASSERT_NE (node1.store.account.end (), iterator1);
ASSERT_NE (node1.store.account.end (transaction), iterator1);
++iterator1;
ASSERT_EQ (node1.store.account.end (), iterator1);
ASSERT_EQ (node1.store.account.end (transaction), iterator1);
}
nano::keypair stake_preserver;
auto send_block (system.wallet (0)->send_action (nano::dev::genesis_key.pub, stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true));
Expand Down Expand Up @@ -130,13 +130,13 @@ TEST (system, DISABLED_generate_send_new)
new_account = iterator2->first;
}
++iterator2;
ASSERT_NE (system.wallet (0)->store.end (), iterator2);
ASSERT_NE (system.wallet (0)->store.end (transaction), iterator2);
if (iterator2->first != nano::dev::genesis_key.pub)
{
new_account = iterator2->first;
}
++iterator2;
ASSERT_EQ (system.wallet (0)->store.end (), iterator2);
ASSERT_EQ (system.wallet (0)->store.end (transaction), iterator2);
ASSERT_FALSE (new_account.is_zero ());
}
ASSERT_TIMELY (10s, node1.balance (new_account) != 0);
Expand Down
16 changes: 8 additions & 8 deletions nano/core_test/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ TEST (wallet, empty_iteration)
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
auto i (wallet.begin (transaction));
auto j (wallet.end ());
auto j (wallet.end (transaction));
ASSERT_EQ (i, j);
}

Expand All @@ -119,7 +119,7 @@ TEST (wallet, one_item_iteration)
ASSERT_FALSE (init);
nano::keypair key1;
wallet.insert_adhoc (transaction, key1.prv);
for (auto i (wallet.begin (transaction)), j (wallet.end ()); i != j; ++i)
for (auto i (wallet.begin (transaction)), j (wallet.end (transaction)); i != j; ++i)
{
ASSERT_EQ (key1.pub, nano::uint256_union (i->first));
nano::raw_key password;
Expand Down Expand Up @@ -147,7 +147,7 @@ TEST (wallet, two_item_iteration)
ASSERT_FALSE (init);
wallet.insert_adhoc (transaction, key1.prv);
wallet.insert_adhoc (transaction, key2.prv);
for (auto i (wallet.begin (transaction)), j (wallet.end ()); i != j; ++i)
for (auto i (wallet.begin (transaction)), j (wallet.end (transaction)); i != j; ++i)
{
pubs.insert (i->first);
nano::raw_key password;
Expand Down Expand Up @@ -266,7 +266,7 @@ TEST (wallet, find_none)
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
nano::account account (1000);
ASSERT_EQ (wallet.end (), wallet.find (transaction, account));
ASSERT_EQ (wallet.end (transaction), wallet.find (transaction, account));
}

TEST (wallet, find_existing)
Expand All @@ -283,9 +283,9 @@ TEST (wallet, find_existing)
wallet.insert_adhoc (transaction, key1.prv);
ASSERT_TRUE (wallet.exists (transaction, key1.pub));
auto existing (wallet.find (transaction, key1.pub));
ASSERT_NE (wallet.end (), existing);
ASSERT_NE (wallet.end (transaction), existing);
++existing;
ASSERT_EQ (wallet.end (), existing);
ASSERT_EQ (wallet.end (transaction), existing);
}

TEST (wallet, rekey)
Expand Down Expand Up @@ -487,8 +487,8 @@ TEST (wallet, serialize_json_empty)
ASSERT_EQ (wallet1.salt (transaction), wallet2.salt (transaction));
ASSERT_EQ (wallet1.check (transaction), wallet2.check (transaction));
ASSERT_EQ (wallet1.representative (transaction), wallet2.representative (transaction));
ASSERT_EQ (wallet1.end (), wallet1.begin (transaction));
ASSERT_EQ (wallet2.end (), wallet2.begin (transaction));
ASSERT_EQ (wallet1.end (transaction), wallet1.begin (transaction));
ASSERT_EQ (wallet2.end (transaction), wallet2.begin (transaction));
}

TEST (wallet, serialize_json_one)
Expand Down
12 changes: 6 additions & 6 deletions nano/nano_node/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ int main (int argc, char * const * argv)
auto inactive_node = nano::default_inactive_node (data_path, vm);
auto transaction = inactive_node->node->store.tx_begin_read ();
auto i = inactive_node->node->store.block.begin (transaction);
auto end = inactive_node->node->store.block.end ();
auto end = inactive_node->node->store.block.end (transaction);
for (; i != end; ++i)
{
nano::block_hash hash = i->first;
Expand Down Expand Up @@ -435,7 +435,7 @@ int main (int argc, char * const * argv)
auto current (node->online_reps.trended ());
std::cout << boost::str (boost::format ("Trended Weight %1%\n") % current);
auto transaction (node->store.tx_begin_read ());
for (auto i (node->store.online_weight.begin (transaction)), n (node->store.online_weight.end ()); i != n; ++i)
for (auto i (node->store.online_weight.begin (transaction)), n (node->store.online_weight.end (transaction)); i != n; ++i)
{
using time_point = std::chrono::system_clock::time_point;
time_point ts (std::chrono::duration_cast<time_point::duration> (std::chrono::nanoseconds (i->first)));
Expand Down Expand Up @@ -471,7 +471,7 @@ int main (int argc, char * const * argv)
// Cache the account heads to make searching quicker against unchecked keys.
auto transaction (node->store.tx_begin_read ());
std::unordered_set<nano::block_hash> frontier_hashes;
for (auto i (node->store.account.begin (transaction)), n (node->store.account.end ()); i != n; ++i)
for (auto i (node->store.account.begin (transaction)), n (node->store.account.end (transaction)); i != n; ++i)
{
frontier_hashes.insert (i->second.head);
}
Expand Down Expand Up @@ -1669,7 +1669,7 @@ int main (int argc, char * const * argv)
}
size_t const accounts_deque_overflow (32 * 1024);
auto transaction = node->ledger.tx_begin_read ();
for (auto i (node->store.account.begin (transaction)), n (node->store.account.end ()); i != n; ++i)
for (auto i (node->store.account.begin (transaction)), n (node->store.account.end (transaction)); i != n; ++i)
{
{
nano::unique_lock<nano::mutex> lock{ mutex };
Expand Down Expand Up @@ -1780,7 +1780,7 @@ int main (int argc, char * const * argv)
start_threads (check_pending, pending);

size_t const pending_deque_overflow (64 * 1024);
for (auto i (node->store.pending.begin (transaction)), n (node->store.pending.end ()); i != n; ++i)
for (auto i (node->store.pending.begin (transaction)), n (node->store.pending.end (transaction)); i != n; ++i)
{
{
nano::unique_lock<nano::mutex> lock{ mutex };
Expand Down Expand Up @@ -1837,7 +1837,7 @@ int main (int argc, char * const * argv)
auto transaction = source_node->ledger.tx_begin_read ();
block_count = source_node->ledger.block_count ();
std::cout << boost::str (boost::format ("Performing bootstrap emulation, %1% blocks in ledger...") % block_count) << std::endl;
for (auto i (source_node->store.account.begin (transaction)), n (source_node->store.account.end ()); i != n; ++i)
for (auto i (source_node->store.account.begin (transaction)), n (source_node->store.account.end (transaction)); i != n; ++i)
{
nano::account const & account (i->first);
nano::account_info const & info (i->second);
Expand Down
2 changes: 1 addition & 1 deletion nano/nano_wallet/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class wallet_daemon final
{
auto transaction (wallet->wallets.tx_begin_write ());
auto existing (wallet->store.begin (transaction));
if (existing != wallet->store.end ())
if (existing != wallet->store.end (transaction))
{
wallet_config.account = existing->first;
}
Expand Down
2 changes: 1 addition & 1 deletion nano/node/backlog_population.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void nano::backlog_population::populate_backlog (nano::unique_lock<nano::mutex>
auto transaction = ledger.tx_begin_read ();

auto it = ledger.store.account.begin (transaction, next);
auto const end = ledger.store.account.end ();
auto const end = ledger.store.account.end (transaction);

auto should_refresh = [&transaction] () {
auto cutoff = std::chrono::steady_clock::now () - 100ms; // TODO: Make this configurable
Expand Down
6 changes: 3 additions & 3 deletions nano/node/bootstrap/bootstrap_frontier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void nano::frontier_req_client::next ()
{
std::size_t max_size (128);
auto transaction (node->store.tx_begin_read ());
for (auto i (node->store.account.begin (transaction, current.number () + 1)), n (node->store.account.end ()); i != n && accounts.size () != max_size; ++i)
for (auto i (node->store.account.begin (transaction, current.number () + 1)), n (node->store.account.end (transaction)); i != n && accounts.size () != max_size; ++i)
{
nano::account_info const & info (i->second);
nano::account const & account (i->first);
Expand Down Expand Up @@ -381,7 +381,7 @@ void nano::frontier_req_server::next ()
auto transaction (node->store.tx_begin_read ());
if (!send_confirmed ())
{
for (auto i (node->store.account.begin (transaction, current.number () + 1)), n (node->store.account.end ()); i != n && accounts.size () != max_size; ++i)
for (auto i (node->store.account.begin (transaction, current.number () + 1)), n (node->store.account.end (transaction)); i != n && accounts.size () != max_size; ++i)
{
nano::account_info const & info (i->second);
if (disable_age_filter || (now - info.modified) <= request->age)
Expand All @@ -393,7 +393,7 @@ void nano::frontier_req_server::next ()
}
else
{
for (auto i (node->store.confirmation_height.begin (transaction, current.number () + 1)), n (node->store.confirmation_height.end ()); i != n && accounts.size () != max_size; ++i)
for (auto i (node->store.confirmation_height.begin (transaction, current.number () + 1)), n (node->store.confirmation_height.end (transaction)); i != n && accounts.size () != max_size; ++i)
{
nano::confirmation_height_info const & info (i->second);
nano::block_hash const & confirmed_frontier (info.frontier);
Expand Down
2 changes: 1 addition & 1 deletion nano/node/bootstrap/bootstrap_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (secure::transaction const &
response.type = nano::asc_pull_type::frontiers;

nano::asc_pull_ack::frontiers_payload response_payload{};
for (auto it = store.account.begin (transaction, request.start), end = store.account.end (); it != end && response_payload.frontiers.size () < request.count; ++it)
for (auto it = store.account.begin (transaction, request.start), end = store.account.end (transaction); it != end && response_payload.frontiers.size () < request.count; ++it)
{
response_payload.frontiers.emplace_back (it->first, it->second.head);
}
Expand Down
6 changes: 3 additions & 3 deletions nano/node/bootstrap_ascending/database_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ std::deque<nano::account> nano::bootstrap_ascending::account_database_iterator::
std::deque<nano::account> result;

auto it = ledger.store.account.begin (transaction, next);
auto const end = ledger.store.account.end ();
auto const end = ledger.store.account.end (transaction);

for (size_t count = 0; it != end && count < batch_size; ++it, ++count)
{
Expand Down Expand Up @@ -115,7 +115,7 @@ std::deque<nano::account> nano::bootstrap_ascending::pending_database_iterator::
std::deque<nano::account> result;

auto it = ledger.store.pending.begin (transaction, next);
auto const end = ledger.store.pending.end ();
auto const end = ledger.store.pending.end (transaction);

// TODO: This pending iteration heuristic should be encapsulated in a pending_iterator class and reused across other components
// The heuristic is to advance the iterator sequentially until we reach a new account or perform a fresh lookup if the account has too many pending blocks
Expand Down Expand Up @@ -164,4 +164,4 @@ std::deque<nano::account> nano::bootstrap_ascending::pending_database_iterator::
bool nano::bootstrap_ascending::pending_database_iterator::warmed_up () const
{
return completed > 0;
}
}
6 changes: 3 additions & 3 deletions nano/node/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
nano::raw_key seed;
existing->second->store.seed (seed, transaction);
std::cout << boost::str (boost::format ("Seed: %1%\n") % seed.to_string ());
for (auto i (existing->second->store.begin (transaction)), m (existing->second->store.end ()); i != m; ++i)
for (auto i (existing->second->store.begin (transaction)), m (existing->second->store.end (transaction)); i != m; ++i)
{
nano::account const & account (i->first);
nano::raw_key key;
Expand Down Expand Up @@ -1201,7 +1201,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
{
std::cout << boost::str (boost::format ("Wallet ID: %1%\n") % i->first.to_string ());
auto transaction (i->second->wallets.tx_begin_read ());
for (auto j (i->second->store.begin (transaction)), m (i->second->store.end ()); j != m; ++j)
for (auto j (i->second->store.begin (transaction)), m (i->second->store.end (transaction)); j != m; ++j)
{
std::cout << nano::account (j->first).to_account () << '\n';
}
Expand All @@ -1224,7 +1224,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
{
auto transaction (wallet->second->wallets.tx_begin_write ());
auto account (wallet->second->store.find (transaction, account_id));
if (account != wallet->second->store.end ())
if (account != wallet->second->store.end (transaction))
{
wallet->second->store.erase (transaction, account_id);
}
Expand Down
2 changes: 1 addition & 1 deletion nano/node/epoch_upgrader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc
{
auto transaction (store.tx_begin_read ());
// Collect accounts to upgrade
for (auto i (store.account.begin (transaction)), n (store.account.end ()); i != n && accounts_list.size () < count_limit; ++i)
for (auto i (store.account.begin (transaction)), n (store.account.end (transaction)); i != n && accounts_list.size () < count_limit; ++i)
{
nano::account const & account (i->first);
nano::account_info const & info (i->second);
Expand Down
Loading

0 comments on commit 483c690

Please sign in to comment.