Skip to content

Conversation

ryanofsky
Copy link
Contributor

@ryanofsky ryanofsky commented Aug 31, 2021

This PR is part of the process separation project.


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

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

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 1, 2021

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.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK b3f46e9, verified move only with git show --color-moved=dimmed_zebra --color-moved-ws=ignore-all-space. Needs rebase.

CSubNet serialization code that was removed in
fa4e6af 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>
bitcoin#10102 (comment) to
use JSON serialization. This requires making BanMapToJson /
BanMapFromJson functions public.
@ryanofsky
Copy link
Contributor Author

Rebased b3f46e9 -> 19b23cf (pr/ipc-banmap.1 -> pr/ipc-banmap.2, compare) due to conflict with #22849

@ryanofsky
Copy link
Contributor Author

Updated 19b23cf -> 6919c82 (pr/ipc-banmap.2 -> pr/ipc-banmap.3, compare) tweaking include

@maflcko maflcko requested a review from vasild September 5, 2021 09:39
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reACK 6919c82.

@maflcko maflcko merged commit 2c6707b into bitcoin:master Sep 6, 2021
Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 6919c82

class CSubNet;
class UniValue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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."

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 7, 2021
@bitcoin bitcoin locked and limited conversation to collaborators Oct 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

Successfully merging this pull request may close these issues.

5 participants