Refactor: Move consts to their correct translation units #17383

pull jnewbery wants to merge 4 commits into bitcoin:master from jnewbery:2019-11-net-processing-consts changing 4 files +79 −88
  1. jnewbery commented at 8:12 pm on November 5, 2019: member

    Following the main.cpp split, there are still some constants in the wrong places, eg net_processing constants in validation.h. Move them all to their rightful homes. At the same time, make them constexpr.

    Also move all const declarations to the top of their files, and ensure that they all have doxygen comments.

  2. DrahtBot commented at 8:19 pm on November 5, 2019: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #18725 ([WIP] Expand CPFP “carve-out” rule from N=1 to N=100 by instagibbs)
    • #18642 (Use std::chrono for the time to rotate destination of addr messages + tests by naumenkogs)
    • #18261 (Erlay: bandwidth-efficient transaction relay protocol by naumenkogs)

    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. MarcoFalke commented at 8:24 pm on November 5, 2019: member
    I don’t know if it makes sense to move the consts to init. Just because the parsing code for most modules is thrown into init, I don’t think this is the right place long term. We might want to have modules weakly integrated into Bitcoin Core (like the wallet or the gui), in which case the parsing code should stay in those modules (along with the defaults)
  4. fanquake added the label Refactoring on Nov 5, 2019
  5. jnewbery commented at 8:40 pm on November 5, 2019: member

    We might want to have modules weakly integrated into Bitcoin Core (like the wallet or the gui), in which case the parsing code should stay in those modules (along with the defaults)

    Concept ACK. I think it would make sense longer-term if modules managed their own arguments, but for now, that’s not the case so init.cpp is the right place for them. If you take a look at the constants I’ve moved init init.cpp, you’ll see:

    • DEFAULT_TXINDEX (was in validation but is part of the index module)
    • DEFAULT_BLOCKFILTERINDEX (was in validation but is part of the index module)
    • DEFAULT_PERSIST_MEMPOOL (was in validation. Is perhaps part of validation, but all the mempool loading/dumping code is in init.cpp)
    • DEFAULT_PEERBLOOMFILTERS (was in net_processing, but is part of the net module)
  6. practicalswift commented at 9:26 pm on November 5, 2019: contributor

    Concept ACK

    Could do s/const /constexpr /g on the touched lines where it makes sense? :)

  7. laanwj commented at 11:59 am on November 6, 2019: member

    Concept ACK

    I don’t know if it makes sense to move the consts to init

    Yes, I think there’s two ideas in conflict here. One is to move the defaults to implementation files (instead of having them clutter headers), which is a good thing in itself, and the other is to do parsing where the values are needed instead of having init.cpp be a busy hive of unrelated parsing (and merge conflicts).

    I think it’s ok to do this first.

  8. promag commented at 3:05 pm on November 6, 2019: member
    Concept ACK.
  9. jnewbery commented at 3:12 pm on November 6, 2019: member

    do parsing where the values are needed instead of having init.cpp be a busy hive of unrelated parsing (and merge conflicts).

    Nicely put. Definite concept ACK on doing this (in future PRs)

  10. promag commented at 3:15 pm on November 6, 2019: member

    do parsing where the values are needed instead of having init.cpp be a busy hive of unrelated parsing (and merge conflicts).

    Nicely put. Definite concept ACK on doing this (in future PRs)

    I thought the benefit of the current approach is to fail as soon as possible?

  11. MarcoFalke commented at 3:19 pm on November 6, 2019: member

    I thought the benefit of the current approach is to fail as soon as possible?

    Moving the parsing code to another module doesn’t mean it can’t fail on init (see e.g. the wallet init parsing)

  12. promag commented at 3:22 pm on November 6, 2019: member

    where the values are needed

    Ah ok, my comment was because of this bit. Breaking the initialization sounds good to me.

  13. jnewbery commented at 3:24 pm on November 6, 2019: member
    Are we supposed to care about AppVeyor failures? Is there a way to rerun them when they fail?
  14. jnewbery commented at 3:26 pm on November 6, 2019: member

    Could do s/const /constexpr /g on the touched lines where it makes sense? :)

    I don’t want scope to creep too much. It made sense to me to change const to constexpr when moving a constant from the header file to the implementation file, but for the simple moves within files I kept the definitions the same. (slightly arbitrary, but I had to draw the line somewhere)

  15. MarcoFalke commented at 3:29 pm on November 6, 2019: member
    I suggest ignoring the appveyor result until #17384 (comment) is merged
  16. promag commented at 3:32 pm on November 6, 2019: member

    Are we supposed to care about AppVeyor failures? Is there a way to rerun them when they fail?

    I’ve restarted. There’s a Rebuild PR button there (maybe if you have permissions?).

  17. laanwj commented at 3:58 pm on November 6, 2019: member

    Ah ok, my comment was because of this bit. Breaking the initialization sounds good to me.

    Yesss I agree I didn’t literally mean where the values are needed, but the module where the values are needed, Of course it’s better to do as much of parsing upfront as possible. Failing on argument parsing when threads have already been spun up is inconvenient. It’s exactly what is wrong at the moment, why parsing can’t fail in ParseBool and ParseInt but have to return something no matter how little sense their input makes.

  18. DrahtBot added the label Needs rebase on Nov 7, 2019
  19. jnewbery force-pushed on Nov 7, 2019
  20. jnewbery commented at 7:11 pm on November 7, 2019: member
    rebased
  21. jnewbery removed the label Needs rebase on Nov 7, 2019
  22. DrahtBot added the label Needs rebase on Jan 29, 2020
  23. jnewbery commented at 8:55 pm on March 13, 2020: member
    rebased on master
  24. jnewbery force-pushed on Mar 13, 2020
  25. practicalswift commented at 10:23 pm on March 13, 2020: contributor
    ACK 3ba3f119c7c3aacf1646747550dfa81f9f903f2econst is great and patch looks good :)
  26. DrahtBot removed the label Needs rebase on Mar 13, 2020
  27. DrahtBot added the label Needs rebase on Mar 17, 2020
  28. [net processing] Move net processing consts to net_processing.cpp b8580cacc7
  29. [validation] Move validation-only consts to validation.cpp 0109622b08
  30. [validation] Move all const declarations to top of validation.h 507b36dd1b
  31. [net processing] Move all const declarations to top of net_processing.cpp e9ea95a30d
  32. jnewbery force-pushed on Apr 23, 2020
  33. jnewbery commented at 5:01 pm on April 23, 2020: member

    I’ve simplified this PR to remove any moves to init.cpp. I think the discussion above about start-up and separating components is interesting, but wasn’t really the point of this PR. This PR now only does the following:

    • move constants that are only used in net processing to net_processing.cpp
    • move constants that are only used in validation to validation.cpp
    • move all constants in net_processing.cpp and validation.cpp to the top of the files.

    I’ve also removed changing const to constexpr and adding doxygen comments.

    Reviewing this PR should be trivial:

    • review each diff with git diff --color-moved=zebra and observe that all moves are from header files to implementation files, or within implementation files.
    • verify that the code still builds.
  34. DrahtBot removed the label Needs rebase on Apr 23, 2020
  35. MarcoFalke commented at 6:44 pm on April 23, 2020: member

    Reviewing this PR should be trivial

    I disagree that review of this is trivial. Let’s take a look at the first move (PING_TIMEOUT): ping and timeout are tightly coupled. (The timeout will start to count after the ping was sent). Ripping the constants away from each other is making the code harder to read.

    Also, I don’t really understand the motivation to move compile time constants of trivial types from the header to the cpp file. This has no effect on compile time and it shouldn’t matter where they live.

    Not to mention that this (potentially silently) conflicts with open pull requests.

  36. MarcoFalke commented at 6:48 pm on April 23, 2020: member
    ACK on moving net_processing consts from validation to net_processing. Not sure about the rest.
  37. jnewbery commented at 0:05 am on April 24, 2020: member

    Let’s take a look at the first move (PING_TIMEOUT): ping and timeout are tightly coupled.

    No, the second value is a timeout on any socket activity, not just pings. It should live in net. PING is an application-level message and exists in net_processing.

    Also, I don’t really understand the motivation to move compile time constants of trivial types from the header to the cpp file.

    The header file is the interface. The .cpp file is the implementation. Constants that are only needed in the implementation should live in the .cpp file, and the interface should be kept as minimal as possible. I don’t see why this is controversial in any way.

    Not to mention that this (potentially silently) conflicts with open pull requests.

    One reason that we have merge conflicts is that there’s very tight coupling between files in this repo. If symbols were declared in the tightest possible scope there would be far fewer conflicts.

    I picked this PR up again because I’m making a branch in net_processing and found myself touching files in validation and net. That shouldn’t happen!

    Please read the other comments on this PR. You’re the only person who’s objected to this. I’ve pared this down and down to satisfy you by removing the changes in init.cpp, removing doxygen comments, and changing constexprs back to consts so this is now just move only.

  38. MarcoFalke commented at 0:17 am on April 24, 2020: member
    Fair enough, Concept ACK
  39. practicalswift commented at 1:33 pm on April 24, 2020: contributor
    ACK e9ea95a30d3c0f62b0df0b29744fb5d68687f97f – patch looks correct
  40. MarcoFalke commented at 12:36 pm on April 25, 2020: member

    ACK e9ea95a30d3c0f62b0df0b29744fb5d68687f97f 🚉

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3ACK e9ea95a30d3c0f62b0df0b29744fb5d68687f97f 🚉
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUigiwv+NZXoqdH0Elf0l5k1w3q8pkNuTK5sx34HgU9JbfVzKrGUHh1Y7Qa3y5/F
     81fxN4j/2C8TVXD1vy76FL0B6ABDxzxfX9OU+24h4md2Ih4KVWUj0voBgaPlQCIE0
     9sb32Kzr1/BdNBaeeMerzh7YsgGv8ZPJSMGuuYFZwsdzKkDuJeSTSr/HMkeKhj29i
    10DPQWxTdoqwtxB3VP0GuxtfuFERSOoDnc8yN2RXUBlZF9GB5Sbht+dJ5hfVjUsTyg
    11QI7akwFnbYYORHVoAD4jp4sMDOhcjI28H+v/LhOM2vJCf8OhNK+ZgoylijYLSjn0
    12sHSTJKQw8NtXJ4vRXHJ6iIRriwySh9TcrUJDZWGWHfc3e1ghdiynUfj74lnQ/2nN
    13Ej81uTOmW2QbshOd0VAYGEz4ihz0aXUS5A2MZLffH6pPbL7QOB9/NkHhK1SJc27U
    14L9ahCd6tJK3tho8UX+gza+K+6lDRzBKiz2hjAiPPdTrZoiH/3KU0Wso0NMWu/odt
    153CQC3Zyb
    16=aYki
    17-----END PGP SIGNATURE-----
    

    Timestamp of file with hash 374504941291a821e498997fb9108c5ce706230380ce58b924f1c892d5b70134 -

  41. MarcoFalke merged this on Apr 25, 2020
  42. MarcoFalke closed this on Apr 25, 2020

  43. sidhujag referenced this in commit 1d131fd5fe on Apr 25, 2020
  44. domob1812 referenced this in commit 706975cc86 on Apr 27, 2020
  45. Fabcien referenced this in commit 53f4c34f57 on Jan 20, 2021
  46. Fabcien referenced this in commit 6b3bb60ac3 on Jan 20, 2021
  47. deadalnix referenced this in commit 66491023ca on Jan 20, 2021
  48. deadalnix referenced this in commit efb9f4d807 on Jan 20, 2021
  49. kittywhiskers referenced this in commit 06788d6a48 on Aug 5, 2021
  50. kittywhiskers referenced this in commit 62d061ab78 on Aug 5, 2021
  51. kittywhiskers referenced this in commit 3d5832a426 on Aug 5, 2021
  52. kittywhiskers referenced this in commit 91c84492a1 on Aug 9, 2021
  53. UdjinM6 referenced this in commit 7aebf156e9 on Aug 10, 2021
  54. 5tefan referenced this in commit cc8e6d31d2 on Aug 12, 2021
  55. DrahtBot locked this on Feb 15, 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: 2024-12-26 06:12 UTC

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