p2p: use header time for compact block recency #36055

pull xternet wants to merge 1 commits into bitcoin:master from xternet:cmpctblock-header-recency changing 2 files +26 −9
  1. xternet commented at 7:50 PM on August 21, 2026: none

    Summary

    • use the announced block header's timestamp to check unsolicited compact-block recency
    • preserve the existing 20-target-spacing cutoff
    • leave CanDirectFetch() and its other callers unchanged
    • add regression coverage for compact-block relay when the active tip is stale

    CanDirectFetch() checks the active tip's timestamp. After 20 target spacings without a block, this causes a recent unsolicited compact block from a high-bandwidth peer to be ignored.

    This change uses the announced block header's timestamp for that local check instead. Although header timestamps are miner-selected, this only affects whether reconstruction is attempted; existing proof-of-work, chain-work, peer, resource, and block-validation checks still apply.

    Fixes #33578

    Test coverage

    The functional test keeps the active tip stale and verifies that:

    • an old unsolicited compact block is ignored
    • a distinct compact block with a recent header triggers GETBLOCKTXN
    • mock time is restored after the test

    Validation

    test/functional/p2p_compactblocks.py

  2. DrahtBot added the label P2P on Aug 21, 2026
  3. DrahtBot commented at 7:50 PM on August 21, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36055.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. p2p: use header time for compact block recency ce51893c5c
  5. xternet force-pushed on Aug 22, 2026
  6. xternet marked this as ready for review on Aug 22, 2026
  7. in src/net_processing.cpp:4895 in ce51893c5c
    4890 | @@ -4891,8 +4891,8 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
    4891 |              return;
    4892 |          }
    4893 |  
    4894 | -        // If we're not close to tip yet, give up and let parallel block fetch work its magic
    4895 | -        if (!already_in_flight && !CanDirectFetch()) {
    4896 | +        // If this is not a recent block, give up and let parallel block fetch work its magic
    4897 | +        if (!already_in_flight && pindex->Time() <= NodeClock::now() - m_chainparams.GetConsensus().PowTargetSpacing() * 20) {
    


    vicjuma commented at 8:53 PM on August 23, 2026:

    Is this even necessary? The essence is to avoid depending on inbound data. Using the already validated time is crucial.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-08-23 23:50 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me