aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/blockchain.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2020-08-12 22:13:29 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2020-09-01 14:33:33 +0000
commit6a37da837e1c936200f8d71a142973cc60b17b32 (patch)
tree922c9eff10660a49a16249781b05e5b8e1b5fc97 /src/cryptonote_core/blockchain.cpp
parentMerge pull request #6586 (diff)
downloadmonero-6a37da837e1c936200f8d71a142973cc60b17b32.tar.xz
threadpool: guard against exceptions in jobs, and armour plating
Those would, if uncaught, exit run and leave the waiter to wait indefinitely for the number of active jobs to reach 0
Diffstat (limited to 'src/cryptonote_core/blockchain.cpp')
-rw-r--r--src/cryptonote_core/blockchain.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 7851b0f6a..636c6963c 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -3250,8 +3250,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
results.resize(tx.vin.size(), 0);
tools::threadpool& tpool = tools::threadpool::getInstance();
- tools::threadpool::waiter waiter;
- const auto waiter_guard = epee::misc_utils::create_scope_leave_handler([&]() { waiter.wait(&tpool); });
+ tools::threadpool::waiter waiter(tpool);
int threads = tpool.get_max_concurrency();
uint64_t max_used_block_height = 0;
@@ -3321,7 +3320,8 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
sig_index++;
}
if (tx.version == 1 && threads > 1)
- waiter.wait(&tpool);
+ if (!waiter.wait())
+ return false;
// enforce min output age
if (hf_version >= HF_VERSION_ENFORCE_MIN_AGE)
@@ -4845,7 +4845,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
{
m_blocks_longhash_table.clear();
uint64_t thread_height = height;
- tools::threadpool::waiter waiter;
+ tools::threadpool::waiter waiter(tpool);
m_prepare_height = height;
m_prepare_nblocks = blocks_entry.size();
m_prepare_blocks = &blocks;
@@ -4858,7 +4858,8 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
thread_height += nblocks;
}
- waiter.wait(&tpool);
+ if (!waiter.wait())
+ return false;
m_prepare_height = 0;
if (m_cancel)
@@ -4992,14 +4993,15 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
if (threads > 1 && amounts.size() > 1)
{
- tools::threadpool::waiter waiter;
+ tools::threadpool::waiter waiter(tpool);
for (size_t i = 0; i < amounts.size(); i++)
{
uint64_t amount = amounts[i];
tpool.submit(&waiter, boost::bind(&Blockchain::output_scan_worker, this, amount, std::cref(offset_map[amount]), std::ref(tx_map[amount])), true);
}
- waiter.wait(&tpool);
+ if (!waiter.wait())
+ return false;
}
else
{