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. --- tests/unit_tests/node_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/unit_tests/node_server.cpp b/tests/unit_tests/node_server.cpp index 58a6fbc4a..e55b43911 100644 --- a/tests/unit_tests/node_server.cpp +++ b/tests/unit_tests/node_server.cpp @@ -56,7 +56,7 @@ public: void set_target_blockchain_height(uint64_t) {} bool init(const boost::program_options::variables_map& vm) {return true ;} bool deinit(){return true;} - bool get_short_chain_history(std::list& ids) const { return true; } + bool get_short_chain_history(std::list& ids, uint64_t& current_height) const { return true; } bool have_block(const crypto::hash& id, int *where = NULL) const {return false;} bool have_block_unlocked(const crypto::hash& id, int *where = NULL) const {return false;} void get_blockchain_top(uint64_t& height, crypto::hash& top_id)const{height=0;top_id=crypto::null_hash;} -- cgit v1.2.3