[net] Don't return an optional from TransportDeserializer::GetMessage() #22735

pull jnewbery wants to merge 2 commits into bitcoin:master from jnewbery:2021-08-20364-rebased changing 3 files +35 −36
  1. jnewbery commented at 12:55 PM on August 18, 2021: member

    Also, access mapRecvBytesPerMsgCmd with at() not find(). This throws an error if COMMAND_OTHER doesn't exist, which should never happen. find() instead just accessed the last element, which could make debugging more difficult.

    Resolves review comments from PR19107:

  2. jnewbery commented at 12:56 PM on August 18, 2021: member

    This is #20364, rebased on master.

    Requesting rereview from @ryanofsky @MarcoFalke and @ajtowns, who reviewed the original PR.

  3. fanquake added the label P2P on Aug 18, 2021
  4. DrahtBot commented at 8:37 AM on August 19, 2021: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

  5. DrahtBot cross-referenced this on Aug 19, 2021 from issue net/net_processing: Convert net std::list buffers to std::forward_list by JeremyRubin
  6. [net] Don't return an optional from TransportDeserializer::GetMessage()
    Also, access mapRecvBytesPerMsgCmd with `at()` not `find()`. This
    throws an error if COMMAND_OTHER doesn't exist, which should never
    happen. `find()` instead just accessed the last element, which could make
    debugging more difficult.
    
    Resolves review comments from PR19107:
    
    - https://github.com/bitcoin/bitcoin/pull/19107#discussion_r478718436
    - https://github.com/bitcoin/bitcoin/pull/19107#discussion_r478714497
    8c96008ab1
  7. [net] Replace GetID() with id in TransportDeserializer constructor f3e451bebf
  8. jnewbery force-pushed on Aug 19, 2021
  9. practicalswift commented at 9:32 PM on August 19, 2021: contributor

    Concept ACK

  10. in src/test/fuzz/p2p_transport_serialization.cpp:73 in 8c96008ab1 outdated
      75 | -                assert(result->m_raw_message_size <= mutable_msg_bytes.size());
      76 | -                assert(result->m_raw_message_size == CMessageHeader::HEADER_SIZE + result->m_message_size);
      77 | -                assert(result->m_time == m_time);
      78 | +            bool reject_message{false};
      79 | +            CNetMessage msg = deserializer.GetMessage(m_time, reject_message);
      80 | +            assert(msg.m_command.size() <= CMessageHeader::COMMAND_SIZE);
    


    theStack commented at 11:29 AM on August 20, 2021:

    Just to get sure, is it intended that the block following the GetMessage is now not conditional any more? (i.e. within a if (!reject_message) { ... })


    jnewbery commented at 9:16 AM on September 30, 2021:

    Yes, it's essentially reverting the change here: https://github.com/bitcoin/bitcoin/commit/890b1d7c2b8312d41d048d2db124586c5dbc8a49#diff-7f9b91d8cb2eaad7b4c0e1a9a4650d9a089c0908faa0502703f3b13a920558afR37, when the return type of GetMessage() was changed to an optional.

  11. theStack commented at 11:30 AM on August 20, 2021: contributor

    Concept ACK

  12. theStack approved
  13. theStack commented at 8:36 PM on October 5, 2021: contributor

    Code-review ACK f3e451bebfe2e2d8de901d8ac29c064a51d3b746

    Also rebased on master + verified that the build is clean and all tests pass.

  14. in src/net.cpp:3010 in f3e451bebf
    3006 | @@ -3007,7 +3007,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
    3007 |          LogPrint(BCLog::NET, "Added connection peer=%d\n", id);
    3008 |      }
    3009 |  
    3010 | -    m_deserializer = std::make_unique<V1TransportDeserializer>(V1TransportDeserializer(Params(), GetId(), SER_NETWORK, INIT_PROTO_VERSION));
    3011 | +    m_deserializer = std::make_unique<V1TransportDeserializer>(V1TransportDeserializer(Params(), id, SER_NETWORK, INIT_PROTO_VERSION));
    


    MarcoFalke commented at 8:24 AM on October 11, 2021:

    f3e451bebfe2e2d8de901d8ac29c064a51d3b746:

    Seem redundant to construct the type twice, fist by calling the constructor, then by calling the copy constructor.


    jnewbery commented at 11:05 AM on October 11, 2021:

    Definitely true, but unrelated to this PR. Very happy to open/review a PR that changes the initialization of these members. They could also be const and initialized in the initializer list, and made private.

  15. ryanofsky approved
  16. ryanofsky commented at 8:48 PM on November 1, 2021: contributor

    Code review ACK f3e451bebfe2e2d8de901d8ac29c064a51d3b746. Changes since last review in #20364#pullrequestreview-534369904 were simplifying by dropping the third commit, rebasing, and cleaning up some style & comments in the first commit.

    The cleanups here are all small and straightforward, but I think the best one is getting rid of the unchecked map.find iterator dereference, and getting rid of the redundant & sometimes initialized out_err_raw_size output parameter.

  17. MarcoFalke merged this on Nov 2, 2021
  18. MarcoFalke closed this on Nov 2, 2021

  19. jnewbery deleted the branch on Nov 2, 2021
  20. sidhujag referenced this in commit 62dfca15f3 on Nov 2, 2021
  21. dhruv cross-referenced this on Nov 4, 2021 from issue Alter the ChaCha20Poly1305@Bitcoin AEAD to the new specification by jonasschnelli
  22. stratospher cross-referenced this on Nov 5, 2021 from issue BIP324: Add encrypted p2p transport {de}serializer by dhruv
  23. bitcoin locked this on Nov 2, 2022

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-05-20 06:53 UTC