Use temporary expression ledger transactions to avoid long-running and recursive transaction opening.

In this algorithm the receivable_iterator was not incremented so the stored transaction was not used.
The outer loop already re-opens the transaction in order to get an up-to-date view of the ledger.
This commit is contained in:
Colin LeMahieu 2024-04-13 11:47:43 +01:00
commit e1cabb31e2
No known key found for this signature in database
GPG key ID: 43708520C8DFB938

View file

@ -134,9 +134,8 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc
uint64_t attempts (0);
for (auto i (accounts_list.get<modified_tag> ().begin ()), n (accounts_list.get<modified_tag> ().end ()); i != n && attempts < upgrade_batch_size && attempts < count_limit && !stopped; ++i)
{
auto transaction (store.tx_begin_read ());
nano::account const & account (i->account);
auto info = ledger.account_info (transaction, account);
auto info = ledger.account_info (ledger.store.tx_begin_read (), account);
if (info && info->epoch () < epoch_a)
{
++attempts;
@ -210,11 +209,10 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc
std::atomic<uint64_t> upgraded_pending (0);
uint64_t workers (0);
uint64_t attempts (0);
auto transaction = store.tx_begin_read ();
for (auto current = ledger.receivable_upper_bound (transaction, 0), end = ledger.receivable_end (); current != end && attempts < upgrade_batch_size && attempts < count_limit && !stopped;)
for (auto current = ledger.receivable_upper_bound (ledger.store.tx_begin_read (), 0), end = ledger.receivable_end (); current != end && attempts < upgrade_batch_size && attempts < count_limit && !stopped;)
{
auto const & [key, info] = *current;
if (!store.account.exists (transaction, key.account))
if (!store.account.exists (ledger.store.tx_begin_read (), key.account))
{
if (info.epoch < epoch_a)
{
@ -257,7 +255,7 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc
}
}
// Move to next pending item
current = ledger.receivable_upper_bound (transaction, key.account, key.hash);
current = ledger.receivable_upper_bound (ledger.store.tx_begin_read (), key.account, key.hash);
}
else
{
@ -268,7 +266,7 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc
}
else
{
current = ledger.receivable_upper_bound (transaction, key.account);
current = ledger.receivable_upper_bound (ledger.store.tx_begin_read (), key.account);
}
}
}