net, refactor: net_processing, add ProcessCompactBlockTxns #26969

pull brunoerg wants to merge 1 commits into bitcoin:master from brunoerg:2023-01-netprocessing-txn changing 1 files +95 −92
  1. brunoerg commented at 9:11 pm on January 25, 2023: contributor

    When processing CMPCTBLOCK message, at some moments we can need to process compact block txns / BLOCKTXN, since all messages are handled by ProcessMessage, so we call ProcessMessage all over again. https://github.com/bitcoin/bitcoin/blob/ab98673f058853e00c310afad57925f54c1ecfae/src/net_processing.cpp#L4331-L4348

    This PR creates a function called ProcessCompactBlockTxns to process it to avoid calling ProcessMessage for it - this function is also called when processing BLOCKTXN msg.

  2. DrahtBot commented at 9:11 pm on January 25, 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 instagibbs, ajtowns, achow101
    Concept ACK Sjors
    Stale ACK dergoegge

    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:

    • #27826 (validation: log which peer sent us a header by Sjors)

    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 Jan 25, 2023
  4. dergoegge commented at 9:23 pm on January 25, 2023: member
    Concept ACK
  5. in src/net_processing.cpp:4425 in aa816de19c outdated
    4421@@ -4343,7 +4422,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
    4422         } // cs_main
    4423 
    4424         if (fProcessBLOCKTXN) {
    4425-            return ProcessMessage(pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, time_received, interruptMsgProc);
    4426+            return ProcessBlockTxnMessage(pfrom, blockTxnMsg, *peer, msgMaker);
    


    ajtowns commented at 0:18 am on January 26, 2023:

    This isn’t really processing a BLOCKTXN message though – it’s completing the block immediately because a BLOCKTXN message wasn’t necessary?

    Wouldn’t it be better to call it ProcessCompactBlockTxns and pass in the BlockTransactions directly, rather than serializing then unserializing it?


    brunoerg commented at 3:54 pm on January 26, 2023:

    Wouldn’t it be better to call it ProcessCompactBlockTxns and pass in the BlockTransactions directly, rather than serializing then unserializing it?

    I think you’re right, it would be better to pass BlockTransactions directly and not deal with serialization.

  6. brunoerg renamed this:
    net: net_processing, add `ProcessBlockTxnMessage`
    net: net_processing, add `ProcessCompactBlockTxns `
    on Jan 26, 2023
  7. brunoerg renamed this:
    net: net_processing, add `ProcessCompactBlockTxns `
    net: net_processing, add `ProcessCompactBlockTxns`
    on Jan 26, 2023
  8. brunoerg commented at 4:01 pm on January 26, 2023: contributor
    Force-pushed addressing @ajtowns’s suggestion.
  9. brunoerg force-pushed on Jan 26, 2023
  10. in src/net_processing.cpp:4486 in c17e71bdfb outdated
    4459@@ -4386,77 +4460,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
    4460 
    4461     if (msg_type == NetMsgType::BLOCKTXN)
    4462     {
    4463-        // Ignore blocktxn received while importing
    


    maflcko commented at 4:19 pm on January 26, 2023:
    It would be good to explain whether you are modifying the behavior or if this is a refactor. Currently your change forces nodes to de serialize BLOCKTXN messages fully before throwing them away. Previously the message was thrown away early.

    brunoerg commented at 4:59 pm on January 26, 2023:

    Nice point, I think it makes sense to not let ProcessCompactBlockTxns check if we received blocktxnwhile importing, we can leave it for ProcessMessage. E.g.:

     0@@ -3153,12 +3153,6 @@ void PeerManagerImpl::ProcessBlock(CNode& node, const std::shared_ptr<const CBlo
     1 void PeerManagerImpl::ProcessCompactBlockTxns(CNode& pfrom, BlockTransactions& block_transactions, Peer& peer,
     2                                              const CNetMsgMaker& msg_maker)
     3 {
     4-    // Ignore blocktxn received while importing
     5-    if (fImporting || fReindex) {
     6-        LogPrint(BCLog::NET, "Unexpected blocktxn message received from peer %d\n", pfrom.GetId());
     7-        return;
     8-    }
     9-
    10     std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
    11     bool fBlockRead = false;
    12     {
    13@@ -4460,6 +4454,10 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
    14 
    15     if (msg_type == NetMsgType::BLOCKTXN)
    16     {
    17+        if (fImporting || fReindex) {
    18+            LogPrint(BCLog::NET, "Unexpected blocktxn message received from peer %d\n", pfrom.GetId());
    19+            return;
    20+        }
    21         BlockTransactions resp;
    22         vRecv >> resp;
    

    brunoerg commented at 5:15 pm on January 26, 2023:
    Done it in last force-pushed.
  11. brunoerg force-pushed on Jan 26, 2023
  12. DrahtBot added the label Needs rebase on Jan 27, 2023
  13. brunoerg force-pushed on Jan 27, 2023
  14. brunoerg commented at 6:06 pm on January 27, 2023: contributor
    Rebased
  15. DrahtBot removed the label Needs rebase on Jan 27, 2023
  16. in src/net_processing.cpp:4418 in fd27f29d83 outdated
    4420@@ -4353,7 +4421,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
    4421         } // cs_main
    4422 
    4423         if (fProcessBLOCKTXN) {
    4424-            return ProcessMessage(pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, time_received, interruptMsgProc);
    4425+            return ProcessCompactBlockTxns(pfrom, txn, *peer, msgMaker);
    


    naumenkogs commented at 7:11 am on February 2, 2023:
    Can’t this call be moved up where fProcessBLOCKTXN=true, and this variable removed altogether, in a pure refactoring way?

    brunoerg commented at 6:22 pm on February 2, 2023:
    I don’t think so. fProcessBLOCKTXN exists to call ProcessMessage out of cs_main block, but do you think we could call ProcessCompactBlockTxns there?

    naumenkogs commented at 7:31 am on February 6, 2023:
    ahhhh you’re right, it’s the cs_main thing. An easy refactoring (splitting ProcessBlock out of ProcessCompactBlockTxns) would allow avoid one unlock/lock operation, but I’m not sure it’s worth it.
  17. in src/net_processing.cpp:923 in fd27f29d83 outdated
    907@@ -908,6 +908,10 @@ class PeerManagerImpl final : public PeerManager
    908     /** Process a new block. Perform any post-processing housekeeping */
    909     void ProcessBlock(CNode& node, const std::shared_ptr<const CBlock>& block, bool force_processing, bool min_pow_checked);
    910 
    911+    /** Process compact block txns  */
    912+    void ProcessCompactBlockTxns(CNode& pfrom, BlockTransactions& block_transactions, Peer& peer, const CNetMsgMaker& msg_maker)
    913+        EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex, !m_most_recent_block_mutex);
    


    naumenkogs commented at 7:13 am on February 2, 2023:
    should have !cs_main, no?

    brunoerg commented at 5:50 pm on March 2, 2023:
    why?

    naumenkogs commented at 11:48 am on March 6, 2023:
    nevermind.
  18. in src/net_processing.cpp:3231 in fd27f29d83 outdated
    3187+            return;
    3188+        } else if (status == READ_STATUS_FAILED) {
    3189+            // Might have collided, fall back to getdata now :(
    3190+            std::vector<CInv> invs;
    3191+            invs.push_back(CInv(MSG_BLOCK | GetFetchFlags(peer), block_transactions.blockhash));
    3192+            m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::GETDATA, invs));
    


    naumenkogs commented at 7:19 am on February 2, 2023:
    if you add a return here, I think you can get rid of fBlockRead and do ProcessBlock unconditionally (!fBlockRead would be equivalent to leaving this function already).

    brunoerg commented at 2:34 pm on February 2, 2023:
    I agree, will address it.
  19. brunoerg renamed this:
    net: net_processing, add `ProcessCompactBlockTxns`
    net, refactor: net_processing, add `ProcessCompactBlockTxns`
    on Feb 2, 2023
  20. brunoerg force-pushed on Feb 2, 2023
  21. brunoerg force-pushed on Feb 2, 2023
  22. in src/net_processing.cpp:912 in 3cd45782f8 outdated
    907@@ -908,6 +908,10 @@ class PeerManagerImpl final : public PeerManager
    908     /** Process a new block. Perform any post-processing housekeeping */
    909     void ProcessBlock(CNode& node, const std::shared_ptr<const CBlock>& block, bool force_processing, bool min_pow_checked);
    910 
    911+    /** Process compact block txns  */
    912+    void ProcessCompactBlockTxns(CNode& pfrom, BlockTransactions& block_transactions, Peer& peer, const CNetMsgMaker& msg_maker)
    


    dergoegge commented at 12:24 pm on March 1, 2023:
    0    void ProcessBlockTxns(CNode& pfrom, const Peer& peer, const BlockTransactions& block_transactions)
    

    Just create a new CNetMsgMaker, no need to pass it.


    brunoerg commented at 5:50 pm on March 2, 2023:
    Done, thanks!
  23. brunoerg force-pushed on Mar 2, 2023
  24. brunoerg commented at 5:51 pm on March 2, 2023: contributor
    Force-pushed addressing #26969 (review) (@dergoegge)
  25. DrahtBot added the label Needs rebase on Mar 21, 2023
  26. brunoerg force-pushed on Mar 21, 2023
  27. brunoerg commented at 8:32 pm on March 21, 2023: contributor
    Rebased
  28. DrahtBot removed the label Needs rebase on Mar 21, 2023
  29. DrahtBot added the label Needs rebase on May 10, 2023
  30. brunoerg force-pushed on May 10, 2023
  31. brunoerg commented at 8:08 pm on May 10, 2023: contributor
    Rebased
  32. DrahtBot removed the label Needs rebase on May 10, 2023
  33. fanquake commented at 3:23 pm on May 18, 2023: member
    @instagibbs this conflicts with #27626, thoughts?
  34. instagibbs commented at 4:01 pm on May 18, 2023: member

    At first glance, this doesn’t seem to interfere in any meaningful way with #27626

    I promise to review this as a follow-up cleanup :pray:

  35. fanquake commented at 4:02 pm on May 18, 2023: member

    I promise to review this as a follow-up cleanup 🙏

    Ok. This could be drafted for now / rebased on top of #27626?

  36. DrahtBot marked this as a draft on May 18, 2023
  37. DrahtBot added the label Needs rebase on May 24, 2023
  38. brunoerg force-pushed on May 24, 2023
  39. brunoerg force-pushed on May 24, 2023
  40. DrahtBot added the label CI failed on May 24, 2023
  41. DrahtBot removed the label Needs rebase on May 24, 2023
  42. brunoerg force-pushed on May 24, 2023
  43. brunoerg marked this as ready for review on May 24, 2023
  44. instagibbs commented at 5:13 pm on May 24, 2023: member
  45. instagibbs commented at 5:51 pm on May 24, 2023: member

    Code review ACK https://github.com/bitcoin/bitcoin/pull/26969/commits/355bc6098a7373feb1d59f9651a79e1477d22243

    reviewed with git diff master --color-moved-ws=ignore-all-space --color-moved=dimmed-zebra. very straight forward set of changes.

    We have a small bug that you could do in a fixup commit as well perhaps: #27626 (review)

  46. brunoerg commented at 5:53 pm on May 24, 2023: contributor

    We have a small bug that you could do in a fixup commit as well perhaps: #27626 (review)

    Gonna address it, thanks.

  47. instagibbs commented at 5:58 pm on May 24, 2023: member
    Upon further consultation by @fanquake , I’ve been advised to just PR the change straight. keep this PR as is.
  48. Sjors commented at 6:07 pm on May 24, 2023: member
    Concept ACK. Light preference for splitting this commit into a pure move-only and the (much smaller) change of calling ProcessCompactBlockTxns instead of ProcessMessage. In the future that makes it easier to follow the history of changes.
  49. DrahtBot removed the label CI failed on May 25, 2023
  50. ajtowns commented at 8:02 pm on June 6, 2023: contributor
    ACK 355bc6098a7373feb1d59f9651a79e1477d22243
  51. in src/net_processing.cpp:923 in 355bc6098a outdated
    918@@ -919,6 +919,10 @@ class PeerManagerImpl final : public PeerManager
    919     /** Process a new block. Perform any post-processing housekeeping */
    920     void ProcessBlock(CNode& node, const std::shared_ptr<const CBlock>& block, bool force_processing, bool min_pow_checked);
    921 
    922+    /** Process compact block txns  */
    923+    void ProcessCompactBlockTxns(CNode& pfrom, BlockTransactions& block_transactions, Peer& peer)
    


    dergoegge commented at 1:21 pm on June 7, 2023:
    0    void ProcessCompactBlockTxns(CNode& pfrom, Peer& peer, const BlockTransactions& block_transactions)
    

    I would prefer this order of the params (matches the other methods) and the BlockTransactions should be marked const.


    brunoerg commented at 2:46 pm on June 7, 2023:
    Make sense. I’m going to address it
  52. brunoerg force-pushed on Jun 7, 2023
  53. instagibbs commented at 2:46 pm on June 7, 2023: member

    re ACK https://github.com/bitcoin/bitcoin/pull/26969/commits/686629d2be5545ef59cf0e97f4f3a74c6cde2efa

    only differences beyond rebase is suggested changes for ProcessCompactBlockTxns argument ordering and const-ness of BlockTransactions arg.

  54. DrahtBot requested review from ajtowns on Jun 7, 2023
  55. brunoerg commented at 2:46 pm on June 7, 2023: contributor
    Force-pushed addressing #26969 (review)
  56. ajtowns commented at 0:04 am on June 8, 2023: contributor
    re ACK 686629d2be5545ef59cf0e97f4f3a74c6cde2efa
  57. DrahtBot removed review request from ajtowns on Jun 8, 2023
  58. dergoegge approved
  59. dergoegge commented at 10:17 am on June 8, 2023: member
    Code review ACK 686629d2be5545ef59cf0e97f4f3a74c6cde2efa
  60. DrahtBot added the label Needs rebase on Jun 12, 2023
  61. brunoerg force-pushed on Jun 12, 2023
  62. brunoerg commented at 1:30 pm on June 12, 2023: contributor
    Rebased
  63. DrahtBot requested review from ajtowns on Jun 12, 2023
  64. DrahtBot requested review from dergoegge on Jun 12, 2023
  65. DrahtBot removed the label Needs rebase on Jun 12, 2023
  66. in src/net_processing.cpp:4371 in 89478af481 outdated
    4371-        // message we typically jump to the BLOCKTXN handling code, with a
    4372-        // dummy (empty) BLOCKTXN message, to re-use the logic there in
    4373-        // completing processing of the putative block (without cs_main).
    4374         bool fProcessBLOCKTXN = false;
    4375-        CDataStream blockTxnMsg(SER_NETWORK, PROTOCOL_VERSION);
    4376+        BlockTransactions txn;
    


    ajtowns commented at 1:23 am on June 15, 2023:
    Shouldn’t this be declared and initialized just prior to calling ProcessCompactBlockTxns ?

    brunoerg commented at 3:11 pm on June 15, 2023:
    Sounds good, gonna address it.
  67. ajtowns commented at 8:09 am on June 15, 2023: contributor
    reACK 89478af481b2e6d4652b2fe50ff5fe5b92cbd69e
  68. net: net_processing, add `ProcessCompactBlockTxns`
    When processing `CMPCTBLOCK` message, at some moments
    we can need to process cmpct block txns, since all messages
    are handled by ProcessMessage, we call ProcessMessage
    all over again. For this reason, it creates a function called
    `ProcessCompactBlockTxns` to process it.
    77d6d89d43
  69. brunoerg force-pushed on Jun 15, 2023
  70. brunoerg commented at 3:24 pm on June 15, 2023: contributor
    Force-pushed addressing #26969 (review)
  71. instagibbs commented at 3:50 pm on June 15, 2023: member
    reACK 77d6d89d43cc5969c98d9b4b56a1e877b473e731
  72. DrahtBot requested review from ajtowns on Jun 15, 2023
  73. ajtowns commented at 2:28 pm on June 23, 2023: contributor
    utACK 77d6d89d43cc5969c98d9b4b56a1e877b473e731
  74. DrahtBot removed review request from ajtowns on Jun 23, 2023
  75. achow101 commented at 10:10 pm on June 23, 2023: member

    ACK 77d6d89d43cc5969c98d9b4b56a1e877b473e731

    Verified diff is primarily a moveonly that removes the recursion for BLOCKTXN.

  76. achow101 merged this on Jun 23, 2023
  77. achow101 closed this on Jun 23, 2023

  78. sidhujag referenced this in commit 52016db9d8 on Jun 25, 2023
  79. bitcoin locked this on Jun 22, 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-07-01 19:13 UTC

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