Net: Divide ProcessMessage in smaller functions #9608

pull jtimon wants to merge 1 commits into bitcoin:master from jtimon:2017-01-split-processmessages changing 1 files +218 −122
  1. jtimon commented at 5:51 am on January 21, 2017: contributor

    As in #9579, indentation and further documentation can be done later to avoid further disruption on the same PR. Maybe at different times for different groups of functions. The main goal of this PR ProcessMessage to make it more readable and maintainable (ie, changes to ProcessMessage should in principle be easier to review after this PR). Brings ProcessMessage to 142 lines.

    This should be relatively easy to review.

  2. jtimon force-pushed on Jan 21, 2017
  3. fanquake added the label P2P on Jan 21, 2017
  4. jtimon force-pushed on Jan 21, 2017
  5. jtimon renamed this:
    WIP: split processmessages
    Net: Divide ProcessMessage in smaller functions
    on Jan 21, 2017
  6. gmaxwell commented at 7:31 pm on January 21, 2017: contributor
    This should use a switch statement, not a long if/else cascade. (the extra rescan and whatever checks can be moved inside their respective functions).
  7. sipa commented at 7:35 pm on January 21, 2017: member
    You can’t switch/case on strings.
  8. gmaxwell commented at 7:51 pm on January 21, 2017: contributor
    Well damn, I thought it was an enum now.
  9. gmaxwell commented at 7:53 pm on January 21, 2017: contributor
    I feel like this just obscures the control flow. :-/
  10. rebroad commented at 7:24 am on January 23, 2017: contributor
    What problem is this PR fixing?
  11. dcousens commented at 12:28 pm on January 23, 2017: contributor

    @rebroad algorithmic readability, it is simpler to reason about these algorithms, IMHO, by these smaller functions than it is otherwise.

    concept ACK

    I feel like this just obscures the control flow. :-/

    How so?

  12. jtimon commented at 2:17 pm on January 23, 2017: contributor

    What problem is this PR fixing?

    Right, readability and maintainability (ie ease of review for later changes on ProcessMessage). As noted, this can be indented later (although that obscures the git blame). In other projects, having to read more than X nested control flows in function directly goes against the style and smaller functions can be always a solution to that. Others simply don’t allow functions above N lines

    IMO, before this PR ProcessMessage is both too long and has some lines with too many nestings. It is very hard for me to read this function as it, and I suspect I’m not the only one.

    I feel like this just obscures the control flow. :-/

    Yeah, how so?

  13. sipa commented at 4:54 pm on January 23, 2017: member

    (although that obscures the git blame).

    Use git blame -w.

  14. MarcoFalke added the label Refactoring on Jan 23, 2017
  15. in src/net_processing.cpp: in a7e24f2910 outdated
    2657+    else if (strCommand == NetMsgType::PONG)
    2658+    {
    2659+        return MsgPong(pfrom, vRecv, nTimeReceived);
    2660+    }
    2661+    else if (strCommand == NetMsgType::FILTERLOAD)
    2662+    {
    


    MarcoFalke commented at 6:09 pm on January 23, 2017:
    According to our style guideline all those curly brackets are on the “wrong” line. If we want to stick to the current style guideline, new code should not violate it. If we don’t want to stick with the current style guide, we should weaken in with regard to new lines.

    jtimon commented at 8:43 pm on January 23, 2017:
    You are completely right, I’m happy correcting this.
  16. MarcoFalke commented at 6:09 pm on January 23, 2017: member
    Concept ACK
  17. jtimon force-pushed on Jan 23, 2017
  18. jtimon commented at 9:32 pm on January 23, 2017: contributor
    Added a couple of commits to hopefully squash.
  19. gmaxwell commented at 8:49 am on January 26, 2017: contributor

    How does it obscure the control flow? Because there is only one caller to these functions, and they’re all called in order. But now looking at the function to considering its invariants you can no longer see where they are called from, what threads they run, what orders things happen in… As far as nesting goes… it hardly changes the nesting– just reduces the indentation by one. It doesn’t change the cyclomatic complexity of the code (which is usually the motivation against large functions, avoiding gnarly intertwined functions that are not testable).

    I don’t think it grievously hurts things, but I do not see the improvement and it feels a bit like movement for movement sake to me. No biggie.

  20. jtimon force-pushed on Jan 31, 2017
  21. jtimon commented at 10:55 pm on January 31, 2017: contributor
    Needed rebase. Rebased on top of #9659 some changes to use more const can be made even if the separation is not done.
  22. jtimon force-pushed on Feb 1, 2017
  23. jtimon force-pushed on Feb 7, 2017
  24. jnewbery commented at 3:27 am on March 2, 2017: member
    Concept ACK, as long as you change the function names to ProcessMsg[type](). You’re proposing to refactor SendMessages() in #9579. I’d prefer that function to be split into SendMsg[type]() in that PR if you continue. At the moment you have a function here MsgFeefilter() for processing a received feefilter message and a function in #9579 called MsgFeefilter() for sending a feefilter message. That’s not helpful for code taging and documentation.
  25. jtimon force-pushed on Mar 7, 2017
  26. jtimon commented at 7:58 pm on March 7, 2017: contributor
    Fixed nits ( #9608 (comment) #9579 (review) ) and rebased without needing it.
  27. dcousens approved
  28. dcousens commented at 10:49 pm on March 7, 2017: contributor
    once over utACK 1d7a16f
  29. theuni commented at 4:09 am on March 25, 2017: member

    Concept ACK, but I don’t see this as an improvement without separating control flow and dispatch. I believe that’s part of @gmaxwell’s concern as well?

    Added that here: https://github.com/theuni/bitcoin/commit/f1e4e281e3f1eb884f8010ac941c82752174bdbe (needs tests). This has the advantage of moving the rules for message acceptance into one place. If the message is deemed suitable, it can be dispatched with no ordering/dependency concerns.

  30. jtimon commented at 4:08 pm on March 25, 2017: contributor
    @theuni At a first glance that looks like an improvement in readability. I’m happy with that being done before or after this, probably before is less disruptive.
  31. jtimon force-pushed on Apr 4, 2017
  32. jtimon commented at 3:45 pm on April 4, 2017: contributor
    Needed rebase.
  33. JeremyRubin commented at 1:29 am on April 5, 2017: contributor
    @jtimon can you take a look at #10145 as it now does a similar thing.
  34. jtimon force-pushed on May 18, 2017
  35. jtimon commented at 9:54 pm on May 18, 2017: contributor
    Needed rebase
  36. jtimon force-pushed on Aug 31, 2017
  37. jtimon commented at 2:39 am on August 31, 2017: contributor
    Needed rebase.
  38. jtimon force-pushed on Sep 20, 2017
  39. Net: Divide ProcessMessage into smaller functions 2723925811
  40. jtimon force-pushed on Sep 23, 2017
  41. jtimon commented at 7:15 pm on February 8, 2018: contributor
    I can reopen and rebase if there’s interest, but it seems there has been no interest for a while, so closing.
  42. jtimon closed this on Feb 8, 2018

  43. laanwj referenced this in commit 021dce935a on Aug 25, 2018
  44. PastaPastaPasta referenced this in commit c261173669 on Jan 25, 2020
  45. UdjinM6 referenced this in commit 31066138c0 on Jan 31, 2020
  46. UdjinM6 referenced this in commit e5e3572e9d on Feb 3, 2020
  47. FornaxA referenced this in commit fa74145cee on Jul 6, 2020
  48. ckti referenced this in commit 77002d0909 on Mar 28, 2021
  49. DrahtBot locked this on Sep 8, 2021

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-11-17 18:12 UTC

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