aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2018-12-31 15:28:25 -0600
committerluigi1111 <luigi1111w@gmail.com>2018-12-31 15:28:25 -0600
commit6d3caaff70a135a060a5bcb9bbb7e6c560d7ee90 (patch)
tree15ea94f09c4845a6baee87dc793d954ba0cb4339 /src
parentMerge pull request #4898 (diff)
parentblockchain: fix race between two external mining threads (diff)
downloadmonero-6d3caaff70a135a060a5bcb9bbb7e6c560d7ee90.tar.xz
Merge pull request #4928
affff94 blockchain: fix race between two external mining threads (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r--src/cryptonote_core/blockchain.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index c6a3c6180..0aeeac5e3 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -1269,7 +1269,9 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m
uint64_t already_generated_coins;
uint64_t pool_cookie;
- CRITICAL_REGION_BEGIN(m_blockchain_lock);
+ m_tx_pool.lock();
+ const auto unlock_guard = epee::misc_utils::create_scope_leave_handler([&]() { m_tx_pool.unlock(); });
+ CRITICAL_REGION_LOCAL(m_blockchain_lock);
height = m_db->height();
if (m_btc_valid) {
// The pool cookie is atomic. The lack of locking is OK, as if it changes
@@ -1305,8 +1307,6 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m
median_weight = m_current_block_cumul_weight_limit / 2;
already_generated_coins = m_db->get_block_already_generated_coins(height - 1);
- CRITICAL_REGION_END();
-
size_t txs_weight;
uint64_t fee;
if (!m_tx_pool.fill_block_template(b, median_weight, already_generated_coins, txs_weight, fee, expected_reward, m_hardfork->get_current_version()))
@@ -1317,7 +1317,6 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m
#if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
size_t real_txs_weight = 0;
uint64_t real_fee = 0;
- CRITICAL_REGION_BEGIN(m_tx_pool.m_transactions_lock);
for(crypto::hash &cur_hash: b.tx_hashes)
{
auto cur_res = m_tx_pool.m_transactions.find(cur_hash);
@@ -1361,7 +1360,6 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m
{
LOG_ERROR("Creating block template: error: wrongly calculated fee");
}
- CRITICAL_REGION_END();
MDEBUG("Creating block template: height " << height <<
", median weight " << median_weight <<
", already generated coins " << already_generated_coins <<