diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 1158417..4b69dd8 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -13,6 +13,8 @@ on: workflow_dispatch: + workflow_call: + jobs: build-alpine-static: diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 827a71a..63379ba 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -13,6 +13,8 @@ on: workflow_dispatch: + workflow_call: + jobs: clang-tidy: runs-on: ubuntu-latest diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml index 3d8af87..0d1b02b 100644 --- a/.github/workflows/cppcheck.yml +++ b/.github/workflows/cppcheck.yml @@ -13,6 +13,8 @@ on: workflow_dispatch: + workflow_call: + jobs: cppcheck-ubuntu: diff --git a/.github/workflows/test-sync-macos.yml b/.github/workflows/test-sync-macos.yml index 5d5f6db..9fe22bd 100644 --- a/.github/workflows/test-sync-macos.yml +++ b/.github/workflows/test-sync-macos.yml @@ -14,7 +14,17 @@ on: workflow_dispatch: jobs: + clang-tidy: + uses: ./.github/workflows/clang-tidy.yml + + cppcheck: + uses: ./.github/workflows/cppcheck.yml + + c-cpp-ci: + uses: ./.github/workflows/c-cpp.yml + sync-test-macos: + needs: [clang-tidy, cppcheck, c-cpp-ci] timeout-minutes: 120 runs-on: ${{ matrix.config.os }} diff --git a/.github/workflows/test-sync-ubuntu.yml b/.github/workflows/test-sync-ubuntu.yml index 80c9066..41d494e 100644 --- a/.github/workflows/test-sync-ubuntu.yml +++ b/.github/workflows/test-sync-ubuntu.yml @@ -14,8 +14,17 @@ on: workflow_dispatch: jobs: - sync-test-ubuntu-tsan: + clang-tidy: + uses: ./.github/workflows/clang-tidy.yml + cppcheck: + uses: ./.github/workflows/cppcheck.yml + + c-cpp-ci: + uses: ./.github/workflows/c-cpp.yml + + sync-test-ubuntu-tsan: + needs: [clang-tidy, cppcheck, c-cpp-ci] timeout-minutes: 60 runs-on: ubuntu-22.04 diff --git a/.github/workflows/test-sync-windows.yml b/.github/workflows/test-sync-windows.yml index 41c845c..f440a25 100644 --- a/.github/workflows/test-sync-windows.yml +++ b/.github/workflows/test-sync-windows.yml @@ -14,7 +14,17 @@ on: workflow_dispatch: jobs: + clang-tidy: + uses: ./.github/workflows/clang-tidy.yml + + cppcheck: + uses: ./.github/workflows/cppcheck.yml + + c-cpp-ci: + uses: ./.github/workflows/c-cpp.yml + sync-test-windows-debug-asan: + needs: [clang-tidy, cppcheck, c-cpp-ci] timeout-minutes: 60 runs-on: windows-2022 diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index 7611594..cfd3816 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -1657,7 +1657,10 @@ void P2PServer::download_missing_blocks() } // Send remaining batch requests - for (auto& [client, batch] : batch_requests) { + for (auto& entry : batch_requests) { + P2PClient* client = entry.first; + std::vector& batch = entry.second; + if (batch.empty()) { continue; } @@ -3178,10 +3181,10 @@ bool P2PServer::P2PClient::on_block_batch_response(const uint8_t* buf, uint32_t const uint64_t received_timestamp = microseconds_since_epoch(); const uint8_t* p = buf + 1; - const uint8_t* end = buf + size; + const uint8_t* buf_end = buf + size; for (uint8_t i = 0; i < count; ++i) { - if (p + sizeof(uint32_t) > end) { + if (p + sizeof(uint32_t) > buf_end) { LOGWARN(4, "peer " << static_cast(m_addrString) << " sent truncated BLOCK_BATCH_RESPONSE"); return false; } @@ -3200,7 +3203,7 @@ bool P2PServer::P2PClient::on_block_batch_response(const uint8_t* buf, uint32_t continue; } - if (p + block_size > end) { + if (p + block_size > buf_end) { LOGWARN(4, "peer " << static_cast(m_addrString) << " sent truncated block in BLOCK_BATCH_RESPONSE"); return false; } diff --git a/src/side_chain.cpp b/src/side_chain.cpp index e53f352..d55bef9 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -630,6 +630,12 @@ bool SideChain::add_external_block(PoolBlock& block, std::vector& missing_ LOGWARN(3, "add_external_block mined by " << block.m_minerWallet << ": wrong mainchain height " << block.m_txinGenHeight << ", expected " << data.height + 1); return false; } + // Hash is known but difficulty for this height may still be missing from cache. + // get_shares() needs it; fetch proactively so verification doesn't stall. + difficulty_type tmp_diff; + if (!m_pool->get_difficulty_at_height(block.m_txinGenHeight, tmp_diff) && is_main_thread()) { + m_pool->fetch_mainchain_block(block.m_txinGenHeight); + } } else { LOGWARN(3, "add_external_block: block is built on top of an unknown mainchain block " << block.m_prevId << ", mainchain reorg might've happened, fetching mainchain height " << block.m_txinGenHeight); @@ -651,8 +657,6 @@ bool SideChain::add_external_block(PoolBlock& block, std::vector& missing_ return false; } - LOGINFO(6, "DEBUG get_pow_hash: seed=" << block.m_seed << " txinGenHeight=" << block.m_txinGenHeight); - if (!block.get_pow_hash(m_pool->hasher(), block.m_txinGenHeight, block.m_seed, block.m_powHash)) { LOGWARN(3, "add_external_block: couldn't get PoW hash for height = " << block.m_sidechainHeight << ", mainchain height " << block.m_txinGenHeight << ". Ignoring it."); forget_incoming_block(block); @@ -676,8 +680,6 @@ bool SideChain::add_external_block(PoolBlock& block, std::vector& missing_ } } - LOGINFO(6, "DEBUG PoW check: sidechainHeight=" << block.m_sidechainHeight << " m_difficulty.lo=" << block.m_difficulty.lo << " m_difficulty.hi=" << block.m_difficulty.hi << " m_powHash=" << block.m_powHash); - if (!block.m_difficulty.check_pow(block.m_powHash)) { LOGWARN(3, "add_external_block mined by " << block.m_minerWallet << @@ -903,16 +905,6 @@ const PoolBlock* SideChain::get_block_blob(const hash& id, std::vector& } blob = block->serialize_mainchain_data(); - { - std::string hex; - size_t start = 43; // approximate outputs offset - for (size_t i = start; i < std::min(start + 64, blob.size()); ++i) { - char buf[4]; - snprintf(buf, sizeof(buf), "%02x", blob[i]); - hex += buf; - } - LOGINFO(6, "DEBUG get_block_blob outputs area (64 bytes from offset 43): " << hex); - } const std::vector sidechain_data = block->serialize_sidechain_data(); blob.insert(blob.end(), sidechain_data.begin(), sidechain_data.end());