wallet2: fix task lifetime during parsed block processing

(cherry picked from commit a09eb5cf4aefa6c351acf898ad4e3be4a67ad860)
This commit is contained in:
selsta
2026-10-04 18:50:23 -04:00
committed by such-gitea
parent 81d781a965
commit 552aea4a7d
+12 -10
View File
@@ -3274,7 +3274,6 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector<cry
THROW_WALLET_EXCEPTION_IF(!m_blockchain.is_in_bounds(current_index), error::out_of_hashchain_bounds_error);
tools::threadpool& tpool = tools::threadpool::getInstanceForCompute();
tools::threadpool::waiter waiter(tpool);
size_t num_txes = 0;
std::vector<tx_cache_data> tx_cache_data;
@@ -3282,6 +3281,7 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector<cry
num_txes += 1 + parsed_blocks[i].txes.size();
tx_cache_data.resize(num_txes);
size_t txidx = 0;
tools::threadpool::waiter cache_waiter(tpool);
for (size_t i = 0; i < blocks.size(); ++i)
{
THROW_WALLET_EXCEPTION_IF(parsed_blocks[i].txes.size() != parsed_blocks[i].block.tx_hashes.size(),
@@ -3292,16 +3292,16 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector<cry
continue;
}
if (m_refresh_type != RefreshNoCoinbase)
tpool.submit(&waiter, [&, i, txidx](){ cache_tx_data(parsed_blocks[i].block.miner_tx, get_transaction_hash(parsed_blocks[i].block.miner_tx), tx_cache_data[txidx]); });
tpool.submit(&cache_waiter, [&, i, txidx](){ cache_tx_data(parsed_blocks[i].block.miner_tx, get_transaction_hash(parsed_blocks[i].block.miner_tx), tx_cache_data[txidx]); });
++txidx;
for (size_t idx = 0; idx < parsed_blocks[i].txes.size(); ++idx)
{
tpool.submit(&waiter, [&, i, idx, txidx](){ cache_tx_data(parsed_blocks[i].txes[idx], parsed_blocks[i].block.tx_hashes[idx], tx_cache_data[txidx]); });
tpool.submit(&cache_waiter, [&, i, idx, txidx](){ cache_tx_data(parsed_blocks[i].txes[idx], parsed_blocks[i].block.tx_hashes[idx], tx_cache_data[txidx]); });
++txidx;
}
}
THROW_WALLET_EXCEPTION_IF(txidx != num_txes, error::wallet_internal_error, "txidx does not match tx_cache_data size");
THROW_WALLET_EXCEPTION_IF(!waiter.wait(), error::wallet_internal_error, "Exception in thread pool");
THROW_WALLET_EXCEPTION_IF(!cache_waiter.wait(), error::wallet_internal_error, "Exception in thread pool");
hw::device &hwdev = m_account.get_device();
hw::reset_mode rst(hwdev);
@@ -3317,11 +3317,12 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector<cry
}
};
tools::threadpool::waiter derivation_waiter(tpool);
for (size_t i = 0; i < tx_cache_data.size(); ++i)
{
if (tx_cache_data[i].empty())
continue;
tpool.submit(&waiter, [&gender, &tx_cache_data, i]() {
tpool.submit(&derivation_waiter, [&gender, &tx_cache_data, i]() {
auto &slot = tx_cache_data[i];
for (auto &iod: slot.primary)
gender(iod);
@@ -3329,7 +3330,7 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector<cry
gender(iod);
}, true);
}
THROW_WALLET_EXCEPTION_IF(!waiter.wait(), error::wallet_internal_error, "Exception in thread pool");
THROW_WALLET_EXCEPTION_IF(!derivation_waiter.wait(), error::wallet_internal_error, "Exception in thread pool");
auto geniod = [&](const cryptonote::transaction &tx, size_t n_vouts, size_t txidx) {
for (size_t k = 0; k < n_vouts; ++k)
@@ -3361,6 +3362,7 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector<cry
std::vector<geniod_params> geniods;
geniods.reserve(num_txes);
tools::threadpool::waiter output_waiter(tpool);
txidx = 0;
uint8_t hf_version_view_tags = get_view_tag_fork();
for (size_t i = 0; i < blocks.size(); ++i)
@@ -3381,7 +3383,7 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector<cry
if (parsed_blocks[i].block.major_version >= hf_version_view_tags)
geniods.push_back(geniod_params{ tx, n_vouts, txidx });
else
tpool.submit(&waiter, [&, n_vouts, txidx](){ geniod(tx, n_vouts, txidx); }, true);
tpool.submit(&output_waiter, [&, n_vouts, txidx](){ geniod(tx, n_vouts, txidx); }, true);
}
}
++txidx;
@@ -3391,7 +3393,7 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector<cry
if (parsed_blocks[i].block.major_version >= hf_version_view_tags)
geniods.push_back(geniod_params{ parsed_blocks[i].txes[j], parsed_blocks[i].txes[j].vout.size(), txidx });
else
tpool.submit(&waiter, [&, i, j, txidx](){ geniod(parsed_blocks[i].txes[j], parsed_blocks[i].txes[j].vout.size(), txidx); }, true);
tpool.submit(&output_waiter, [&, i, j, txidx](){ geniod(parsed_blocks[i].txes[j], parsed_blocks[i].txes[j].vout.size(), txidx); }, true);
++txidx;
}
}
@@ -3410,7 +3412,7 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector<cry
{
size_t batch_end = std::min(batch_start + GENIOD_BATCH_SIZE, geniods.size());
THROW_WALLET_EXCEPTION_IF(batch_end < batch_start, error::wallet_internal_error, "Thread batch end overflow");
tpool.submit(&waiter, [&geniods, &geniod, batch_start, batch_end]() {
tpool.submit(&output_waiter, [&geniods, &geniod, batch_start, batch_end]() {
for (size_t i = batch_start; i < batch_end; ++i)
{
const geniod_params &gp = geniods[i];
@@ -3422,7 +3424,7 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector<cry
}
THROW_WALLET_EXCEPTION_IF(num_batch_txes != geniods.size(), error::wallet_internal_error, "txes batched for thread pool did not reach expected value");
}
THROW_WALLET_EXCEPTION_IF(!waiter.wait(), error::wallet_internal_error, "Exception in thread pool");
THROW_WALLET_EXCEPTION_IF(!output_waiter.wait(), error::wallet_internal_error, "Exception in thread pool");
hwdev.set_mode(hw::device::NONE);