MOVEONLY: Expose BanMapToJson / BanMapFromJson #22848

pull ryanofsky wants to merge 1 commits into bitcoin:master from ryanofsky:pr/ipc-banmap changing 5 files +112 −85
  1. ryanofsky commented at 3:23 pm on August 31, 2021: member

    This PR is part of the process separation project.


    CSubNet serialization code that was removed in #22570 fa4e6afdae7b82df638b60edf37ac36d57a8cb4f was needed by multiprocess code to share ban map between gui and node processes.

    Rather than adding it back, use suggestion from MarcoFalke #10102 (review) to use JSON serialization. This requires making BanMapToJson / BanMapFromJson functions public.

  2. DrahtBot added the label Build system on Aug 31, 2021
  3. DrahtBot added the label P2P on Aug 31, 2021
  4. DrahtBot added the label Refactoring on Aug 31, 2021
  5. ryanofsky added this to the "In progress" column in a project

  6. MarcoFalke removed the label Build system on Aug 31, 2021
  7. MarcoFalke removed the label P2P on Aug 31, 2021
  8. DrahtBot commented at 7:19 am on September 1, 2021: 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:

    • #22762 (Raise InitError when peers.dat is invalid or corrupted by MarcoFalke)
    • #22362 (Drop only invalid entries when reading banlist.json by MarcoFalke)

    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.

  9. DrahtBot added the label Needs rebase on Sep 1, 2021
  10. promag commented at 7:55 am on September 3, 2021: member
    Code review ACK b3f46e9058cfdcb2825ea76ed7d5d3c060486a39, verified move only with git show --color-moved=dimmed_zebra --color-moved-ws=ignore-all-space. Needs rebase.
  11. MOVEONLY: Expose BanMapToJson / BanMapFromJson
    CSubNet serialization code that was removed in
    fa4e6afdae7b82df638b60edf37ac36d57a8cb4f was needed by multiprocess code
    to share ban map between gui and node processes.
    
    Rather than adding it back, use suggestion from MarcoFalke
    <falke.marco@gmail.com>
    https://github.com/bitcoin/bitcoin/pull/10102#discussion_r690922929 to
    use JSON serialization. This requires making BanMapToJson /
    BanMapFromJson functions public.
    6919c823cb
  12. ryanofsky force-pushed on Sep 3, 2021
  13. ryanofsky commented at 3:38 pm on September 3, 2021: member
    Rebased b3f46e9058cfdcb2825ea76ed7d5d3c060486a39 -> 19b23cf07636a87e5eb0742d52e5a8b6a7e53ce6 (pr/ipc-banmap.1 -> pr/ipc-banmap.2, compare) due to conflict with #22849
  14. DrahtBot removed the label Needs rebase on Sep 3, 2021
  15. in src/net_types.h:9 in 19b23cf076 outdated
    5@@ -6,10 +6,55 @@
    6 #define BITCOIN_NET_TYPES_H
    7 
    8 #include <map>
    9+#include <serialize.h>
    


    MarcoFalke commented at 3:43 pm on September 3, 2021:
    why?

    ryanofsky commented at 3:46 pm on September 3, 2021:

    why?

    I must have added it to avoid compile errors before #22849. Probably wasn’t the right place to add the include in any case, though. Will remove

  16. ryanofsky force-pushed on Sep 3, 2021
  17. ryanofsky commented at 5:32 pm on September 3, 2021: member
    Updated 19b23cf07636a87e5eb0742d52e5a8b6a7e53ce6 -> 6919c823cbce92248647880fb1d912828449ae57 (pr/ipc-banmap.2 -> pr/ipc-banmap.3, compare) tweaking include
  18. MarcoFalke requested review from vasild on Sep 5, 2021
  19. promag commented at 10:17 am on September 5, 2021: member
    reACK 6919c823cbce92248647880fb1d912828449ae57.
  20. MarcoFalke merged this on Sep 6, 2021
  21. MarcoFalke closed this on Sep 6, 2021

  22. in src/net_types.h:12 in 6919c823cb
     4@@ -5,11 +5,56 @@
     5 #ifndef BITCOIN_NET_TYPES_H
     6 #define BITCOIN_NET_TYPES_H
     7 
     8+#include <cstdint>
     9 #include <map>
    10 
    11-class CBanEntry;
    12 class CSubNet;
    13+class UniValue;
    


    vasild commented at 8:46 am on September 6, 2021:

    Any reason not to use #include <univalue.h> here instead of class UniValue; (there is no circular dependency in this case)?

    I think by default it should be preferred to include the header instead of doing the forward declaration. And if the forward declaration is really necessary (e.g. circular dependency, compilation speed concerns) then that should be in its own header that is included by “users”. For example, it is annoying to have to change struct Foo to class Foo with forward declarations spilled all over the place.


    ryanofsky commented at 2:40 pm on September 7, 2021:

    Any reason not to use #include <univalue.h> here instead of class UniValue; (there is no circular dependency in this case)?

    I think by default it should be preferred to include the header instead of doing the forward declaration. And if the forward declaration is really necessary (e.g. circular dependency, compilation speed concerns) then that should be in its own header that is included by “users”. For example, it is annoying to have to change struct Foo to class Foo with forward declarations spilled all over the place.

    I have the opposite preference and prefer simple forward declarations whenever possible instead of includes. (Simple forward declarations meaning declarations like class Foo; or struct Foo; enum class Foo; not declarations for templates, typedefs, or std:: types). I don’t think forward declarations are just a workaround for circular dependencies. I think they also are important for keeping build times under control and for eliminating dependencies between modules while allowing them to pass data in an opaque but type safe way (avoiding void*). It’s possible my preference is out of date (it comes from working on projects using IWYU https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhyIWYU.md#why-forward-declare), though, and it probably wouldn’t be a bad idea to have a linter or developer note for more consistency here if you wanted to follow up!


    MarcoFalke commented at 2:53 pm on September 7, 2021:
    I think our compile requirements (both time and space) are still too high. Even if all of the heavy boost was removed, we’d still have our own heavy serialize which is included ~everywhere and thus parsed and compiled each time, even if it isn’t used. I agree with Russ that includes should be kept at a minimum (iwyu) and forward decls are acceptable as well. It would be nice if iwyu (or something similar) was used more regularly in the dev flow, so that oversights such as #22740 (comment) don’t happen in the future.

    vasild commented at 10:29 am on September 9, 2021:

    Alright, https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhyIWYU.md#why-forward-declare mentions some pros and cons of forward declarations and also a workaround of the cons - a ‘forwarding headers’.

    What about this: https://google.github.io/styleguide/cppguide.html#Forward_Declarations

    • Forward declarations can hide a dependency, allowing user code to skip necessary recompilation when headers change.
    • … Replacing an #include with a forward declaration can silently change the meaning of code …

    I think each one of those two is very nasty on its own.

    Did anybody bother to measure the compilation time improvement due to forward declarations? I suspect it may be insignificant.


    ryanofsky commented at 11:26 am on September 9, 2021:
    • Forward declarations can hide a dependency, allowing user code to skip necessary recompilation when headers change.
    • … Replacing an #include with a forward declaration can silently change the meaning of code …

    I think each one of those two is very nasty on its own.

    The first one would just result in link errors instead of compile errors. Not especially nasty as far as I can see. The second one seems like FUD. Is there a realistic example of this happening? Could the example happen accidentally, or would you have to go out of your way to engineer an it like in void* inheritance case? If this could happen accidentally, would basic sentient human code review or use of “grep” catch it?

    There are practical benefits to using simple forward declarations like the non-template non-typedef non-std:: ones I write myself, or the ones created by the IWYU tool. Obviously there are specific situations where forward declarations are bad to use and the google style guide covers them well. But there is no reason to throw out the baby with the bathwater with another one of these “X considered harmful” proclamations. Especially since unlike other X’s, you can’t actually get rid forward includes if you want to write type-safe modular code.

    I will also say that I like the use of forward declarations aesthetically and semantically. An include says “the code in this file depends on this code in this other file”. A forward declaration when it is properly used (something enforceable by IWYU) says “the code in this file does NOT depend on this type, and is just letting code in two other files that do you use the type communicate safely.”

  23. vasild commented at 8:47 am on September 6, 2021: member
    ACK 6919c823cbce92248647880fb1d912828449ae57
  24. sidhujag referenced this in commit 4d1f6f660c on Sep 7, 2021
  25. fanquake moved this from the "In progress" to the "Done" column in a project

  26. DrahtBot locked this on Oct 30, 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-25 06:12 UTC

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