From d8d3cf97300480b9d3942c667978dd4860b76feb Mon Sep 17 00:00:00 2001 From: j-berman Date: Thu, 11 Dec 2025 21:32:23 -0800 Subject: p2p: fix race causing dropped connections during sync Without this commit: 1) read height from DB 2) add block to chain in separate thread 3) read chain for block id's and request them from peer 4) ERR in handle_response_chain_entry, peer's first block is the one that was added to the chain, which has block idx=height from step 1. This commit reads the chain for height and highest block id's in one go while holding the m_blockchain_lock to avoid the race. --- src/cryptonote_core/cryptonote_core.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cryptonote_core/cryptonote_core.cpp') diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 300fb2553..d30bc72a7 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -1536,9 +1536,9 @@ namespace cryptonote return m_mempool.get_pool_for_rpc(tx_infos, key_image_infos); } //----------------------------------------------------------------------------------------------- - bool core::get_short_chain_history(std::list& ids) const + bool core::get_short_chain_history(std::list& ids, uint64_t& current_height) const { - return m_blockchain_storage.get_short_chain_history(ids); + return m_blockchain_storage.get_short_chain_history(ids, current_height); } //----------------------------------------------------------------------------------------------- bool core::handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NOTIFY_RESPONSE_GET_OBJECTS::request& rsp, cryptonote_connection_context& context) -- cgit v1.2.3