Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move DB lock guard to later stage #8383

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cryptonote_core/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,7 @@ bool Blockchain::create_block_template(block& b, const crypto::hash *from_block,
seed_hash = crypto::null_hash;

m_tx_pool.lock();
db_rtxn_guard rtxn_guard(m_db);
const auto unlock_guard = epee::misc_utils::create_scope_leave_handler([&]() { m_tx_pool.unlock(); });
CRITICAL_REGION_LOCAL(m_blockchain_lock);
if (m_btc_valid && !from_block) {
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/core_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,7 @@ namespace cryptonote
return false;
}

// TODO: move next_height, next_seed_hash under the protection of locks in Blockchain::create_block_template to guarantee consistent data
uint64_t next_height;
crypto::rx_seedheights(height, &seed_height, &next_height);
if (next_height != seed_height)
Expand Down Expand Up @@ -1877,7 +1878,6 @@ namespace cryptonote
return false;
}
}
db_rtxn_guard rtxn_guard(&m_core.get_blockchain_storage().get_db());
crypto::hash seed_hash, next_seed_hash;
if (!get_block_template(info.address, req.prev_block.empty() ? NULL : &prev_block, blob_reserve, reserved_offset, wdiff, res.height, res.expected_reward, b, res.seed_height, seed_hash, next_seed_hash, error_resp))
return false;
Expand Down