p2p: Avoid prematurely clearing download state for other peers #27608

pull sdaftuar wants to merge 1 commits into bitcoin:master from sdaftuar:2023-05-download-bug changing 1 files +22 −8
  1. sdaftuar commented at 5:37 pm on May 9, 2023: member

    Avoid letting one peer send us data that clears out the download request (and related timers etc) from another peer.

    The exception is if a block is definitely stored to disk, in which case we’ll clear the download state (just as we do for compact blocks).

  2. DrahtBot commented at 5:37 pm on May 9, 2023: contributor

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK jamesob, instagibbs, fjahr, mzumsande

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #26969 (net, refactor: net_processing, add ProcessCompactBlockTxns by brunoerg)
    • #25572 (refactor: Introduce EvictionManager and use it for the inbound eviction logic by dergoegge)
    • #25268 (refactor: Introduce EvictionManager by dergoegge)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. DrahtBot added the label P2P on May 9, 2023
  4. in src/net_processing.cpp:890 in 6857b1be52 outdated
    883@@ -884,7 +884,7 @@ class PeerManagerImpl final : public PeerManager
    884      *  - the block has been received from a peer
    885      *  - the request for the block has timed out
    886      */
    887-    void RemoveBlockRequest(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
    888+    void RemoveBlockRequest(const uint256& hash, std::optional<NodeId> from_peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
    


    instagibbs commented at 5:45 pm on May 9, 2023:
    should describe what the argument does and when it should be used

    sdaftuar commented at 6:12 pm on May 9, 2023:
    Consider it done.
  5. sdaftuar force-pushed on May 9, 2023
  6. DrahtBot added the label CI failed on May 9, 2023
  7. p2p: Avoid prematurely clearing download state for other peers 52e52071e0
  8. sdaftuar force-pushed on May 9, 2023
  9. jamesob commented at 5:56 pm on May 9, 2023: member
    Concept ACK. Will start running this when CI checks out.
  10. instagibbs commented at 6:00 pm on May 9, 2023: member

    first glance, looks right to me. I was literally writing the same code as part of as learn-as-I-go resurrection of #10984

    this would be required for any parallel download implementation as well

  11. jamesob referenced this in commit 93f220f466 on May 9, 2023
  12. jamesob approved
  13. jamesob commented at 6:42 pm on May 9, 2023: member

    ACK 52e52071e01f4e98d87a47e1d5f3c5c3cc6dbaf4 (jamesob/ackr/27608.1.sdaftuar.p2p_avoid_prematurely_cl)

    Built, reviewed code locally. Deployed to b-02.slug on https://bmon.info; all metrics there look normal (peer count, tip connection).

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3ACK 52e52071e01f4e98d87a47e1d5f3c5c3cc6dbaf4 ([`jamesob/ackr/27608.1.sdaftuar.p2p_avoid_prematurely_cl`](https://github.com/jamesob/bitcoin/tree/ackr/27608.1.sdaftuar.p2p_avoid_prematurely_cl))
     4
     5Built, reviewed code locally. Deployed to b-02.slug on https://bmon.info; all
     6metrics there look normal (peer count, tip connection).
     7
     8-----BEGIN PGP SIGNATURE-----
     9
    10iQIzBAEBCgAdFiEEGNRVI1NPYuZCSIrGepNdrbLETwUFAmRalB8ACgkQepNdrbLE
    11TwXObg//dcajHcXotfGB5mdQGv0a+jXDv1mjXlXr551R1Lv+rhXMbyipB80GNdmu
    12IqOXGauUUeqnK2dwxwMMgYlJDa92ErQzAOB7vm44m1iNuSStGh9aqupbznl3D2WK
    131D3DMiO5+ZfPmMRhGgVPHwr8ydsuJJ3suna6I5SEF4cbET0x6aLfkMrJ0NK11TfY
    14IUz+1XFpxMNiosUxWroUSUKlkZMI83LqjP9JFFyTwCNrfO3jEYTQRT+BABbTC2yk
    15k7OWkWBNdoeCSEgVyJ0fOWS5Fr438sL7xpNbWx3MOvU6EC6fV0oLxlE/R6TovQzN
    16U/s28D/Z/BlEGFYZbW/dB5JkMfllF8sj8SGOL9b/3u7AC6zJI5i3Q6/89f20lhVK
    178iD1eo+iM7hdwUnQkgkd4D6Gh3e3GVf1643pVI3ioqWrDRpDrCzThSW4mUKic2vJ
    180xDEuqHO/RWsUCoL+6uV3Rw7henmAZsaHzmV6Qf0G4T1apeBq21U7z8YjJmfLDvg
    193q1rmvwYciGJzVkLdBHACgdLPpyL+aMDAY22mM3XQqafnNI2hG5qbB/ScueDF0H3
    20WLHdHkcsymY1pMUVyJc2CX9AiuckxW4vJX/t/D7RawsgO4KW78vkx/igBOI/QJYG
    21hMDyOm4kKIRhdXbqSZphxDwaFxcX+8wc6WJAUkEB5DbLN0tYx0g=
    22=6fob
    23-----END PGP SIGNATURE-----
    
  14. DrahtBot removed the label CI failed on May 9, 2023
  15. instagibbs approved
  16. instagibbs commented at 7:22 pm on May 9, 2023: member
    ACK 52e52071e01f4e98d87a47e1d5f3c5c3cc6dbaf4
  17. in src/net_processing.cpp:3170 in 52e52071e0
    3163@@ -3155,6 +3164,11 @@ void PeerManagerImpl::ProcessBlock(CNode& node, const std::shared_ptr<const CBlo
    3164     m_chainman.ProcessNewBlock(block, force_processing, min_pow_checked, &new_block);
    3165     if (new_block) {
    3166         node.m_last_block_time = GetTime<std::chrono::seconds>();
    3167+        // In case this block came from a different peer than we requested
    3168+        // from, we can erase the block request now anyway (as we just stored
    3169+        // this block to disk).
    3170+        LOCK(cs_main);
    


    fjahr commented at 9:18 pm on May 9, 2023:
    nit: Could have moved the lock outside the if..else and removed the duplicate line in the else below.
  18. fjahr commented at 10:54 pm on May 9, 2023: contributor
    Code review ACK 52e52071e01f4e98d87a47e1d5f3c5c3cc6dbaf4
  19. in src/net_processing.cpp:1137 in 52e52071e0
    1131@@ -1129,6 +1132,12 @@ void PeerManagerImpl::RemoveBlockRequest(const uint256& hash)
    1132     }
    1133 
    1134     auto [node_id, list_it] = it->second;
    1135+
    1136+    if (from_peer && node_id != *from_peer) {
    1137+        // Block was requested by another peer
    


    mzumsande commented at 11:00 pm on May 9, 2023:
    nit: requested from another peer

    sdaftuar commented at 1:37 pm on May 10, 2023:
    Oops – will fix in a followup. Thanks for catching.

    jamesob commented at 3:12 pm on May 10, 2023:
    “by another peer” reads fine to me?

    instagibbs commented at 3:14 pm on May 10, 2023:
    peer didn’t request, WE requested that peer

    instagibbs commented at 3:15 pm on May 10, 2023:

    ah right, suggested text is also ambiguous….

    “Block was requested by us from another peer” ?

  20. mzumsande commented at 11:39 pm on May 9, 2023: contributor
    Code Review ACK 52e52071e01f4e98d87a47e1d5f3c5c3cc6dbaf4
  21. fanquake merged this on May 10, 2023
  22. fanquake closed this on May 10, 2023

  23. fanquake referenced this in commit 9a23079df3 on May 10, 2023
  24. sidhujag referenced this in commit 3fea42891a on May 10, 2023
  25. in src/net_processing.cpp:4417 in 52e52071e0
    4413@@ -4400,7 +4414,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
    4414                 // process from some other peer.  We do this after calling
    4415                 // ProcessNewBlock so that a malleated cmpctblock announcement
    4416                 // can't be used to interfere with block relay.
    4417-                RemoveBlockRequest(pblock->GetHash());
    4418+                RemoveBlockRequest(pblock->GetHash(), std::nullopt);
    


    instagibbs commented at 3:06 pm on May 10, 2023:
    Is this block required anymore now that ProcessBlock will call it for us the first time when it’s new?

    Sjors commented at 2:34 pm on May 11, 2023:
    Can’t we have a race condition where the block is not new? In any case this function is extremely fast if called twice.
  26. in src/net_processing.cpp:1175 in 52e52071e0
    1172@@ -1164,7 +1173,7 @@ bool PeerManagerImpl::BlockRequested(NodeId nodeid, const CBlockIndex& block, st
    1173     }
    1174 
    1175     // Make sure it's not listed somewhere already.
    


    Sjors commented at 9:39 am on May 11, 2023:

    This comment could be improved:

    0// When processing block related messages from our peers,
    1// we treat requested blocks different from unsolicited ones.
    2// When making this distinction we only keep track of the
    3// last peer we requested from.
    
  27. fanquake referenced this in commit ce8f812b0a on May 11, 2023
  28. dergoegge commented at 10:54 am on May 11, 2023: member
    post-merge Code review ACK 52e52071e01f4e98d87a47e1d5f3c5c3cc6dbaf4
  29. fanquake referenced this in commit ec7cd33c9c on May 11, 2023
  30. Sjors commented at 2:41 pm on May 11, 2023: member
    utACK 52e52071e01f4e98d87a47e1d5f3c5c3cc6dbaf4
  31. achow101 referenced this in commit ac5b9f37de on May 11, 2023
  32. fanquake referenced this in commit 8996da626d on May 11, 2023
  33. fanquake referenced this in commit 2e9fc2e353 on May 12, 2023
  34. dergoegge referenced this in commit 86ed05d350 on Feb 2, 2024
  35. dergoegge referenced this in commit c3952bc0a5 on Feb 2, 2024
  36. dergoegge referenced this in commit bdca94aad0 on Feb 6, 2024
  37. dergoegge referenced this in commit 9e27f86c3f on Feb 6, 2024
  38. dergoegge referenced this in commit 6546bcd15b on Feb 8, 2024
  39. dergoegge referenced this in commit 2b2cc96a7b on Feb 8, 2024
  40. dergoegge referenced this in commit 1f0afbc544 on Feb 8, 2024
  41. dergoegge referenced this in commit 5f27c9be7a on Feb 8, 2024
  42. dergoegge referenced this in commit 6de52101e5 on Feb 22, 2024
  43. dergoegge referenced this in commit e2d1eb2e20 on Feb 22, 2024
  44. 0xB10C referenced this in commit 96fdbd2d4a on Feb 23, 2024
  45. 0xB10C referenced this in commit 51d818c1d0 on Feb 23, 2024
  46. 0xB10C referenced this in commit a2d7d20ff9 on Feb 23, 2024
  47. 0xB10C referenced this in commit 8552e0dd3d on Feb 23, 2024
  48. dergoegge referenced this in commit 66933b3b8d on Feb 23, 2024
  49. dergoegge referenced this in commit e46829f091 on Feb 23, 2024
  50. dergoegge referenced this in commit 49257c0304 on Feb 27, 2024
  51. dergoegge referenced this in commit 5bf4f5ba32 on Feb 27, 2024
  52. achow101 referenced this in commit 2649e655b9 on Feb 28, 2024
  53. glozow referenced this in commit 24736350e9 on Mar 5, 2024
  54. glozow referenced this in commit 0c5c5962cb on Mar 5, 2024
  55. achow101 referenced this in commit 8cc4b24c74 on Mar 5, 2024
  56. achow101 referenced this in commit de97ecf14f on Mar 5, 2024
  57. glozow referenced this in commit c33e83a53a on Mar 11, 2024
  58. kevkevinpal referenced this in commit abc8186867 on Mar 13, 2024
  59. kevkevinpal referenced this in commit faffa6fe0c on Mar 13, 2024
  60. kevkevinpal referenced this in commit 331b4d8908 on Mar 13, 2024
  61. kevkevinpal referenced this in commit 766231a9f1 on Mar 13, 2024
  62. fanquake referenced this in commit d5bad0d2d1 on Mar 22, 2024
  63. janus referenced this in commit d12ecccbc0 on Apr 6, 2024
  64. bitcoin locked this on May 10, 2024

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: 2024-12-22 00:12 UTC

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