Skip to content

Conversation

@jtimon
Copy link
Contributor

@jtimon jtimon commented Jan 19, 2015

Moving some code, including main.h from qt/peertablemodel.h and wallet.h can be avoided.
Also, main.h doesn't need to include many things that can be included in main.cpp.
After that, using the compiler to make sure only files that depend on main.h include it, many missing includes show up.
Many files should require less memory for being compiled after this.

@theuni
Copy link
Member

theuni commented Jan 20, 2015

Very nice, I've been meaning to take a look at this as well. Great to see it was relatively non-invasive.
I've verified that fd10da8cae79a15d2ac23a17120cb2d62e8a28e2 and b46dd0f3f53ec20035660aaca07484f898df1fc5 are read-only. From a quick eye-ball (and since Travis is happy), the includes changes look good too.

utAck.

@laanwj
Copy link
Member

laanwj commented Jan 20, 2015

ACK. Looks like a definite improvement to me, and low-risk due to (mostly) move only.

It becomes kind of apparent from this how much is exported in main.h that

  • a) initialization/shutdown purposes (InitBlockIndex/LoadBlockIndex/UnloadBlockIndex/ThreadScriptCheck at least).
  • b) only used lnternally (WriteBlockToDisk, ProcessMessages, GetMinRelayFee at least), but see c - possibly this means they need tests
  • c) exported only for testing and could be static/internal otherwise (CScriptCheck)
  • d) pure utility (AreInputsStandard, GetLegacySigOpCount, IsStandardTx, GetP2SHSigOpCount)

(a) could be reduced by factoring the initialization and shutdown sequences from init.cpp and moving them with what is initiialized
(b) could be removed from the header, or tests added
(c) is always thorny, you need to expose them but only to tests, could have a special "test interface"
(d) could be moved to a standard.cpp/standard.h

@sipa may want to weigh in here too as he has specific ideas about refactoring main.

@jtimon
Copy link
Contributor Author

jtimon commented Jan 20, 2015

For b and c, maybe a half-solution that just comes to mind, is just leaving the definitions in main.cpp but expose them with an independent header like main_test.h or something. Just a random thought.

I'm basically focusing on consensus and policy checks. Trying to take advantage of potential similarities between their dependencies. Right now it's kind of a mess that doesn't even pass the tests, but if you're curious, here's my latest branch on that: https://github.com/jtimon/bitcoin/commits/consensus_policy
I guess it mostly falls into the "d" category, with a little bit of "a" as you move constants and globals out.
This (and therefore #5669 and the longest branch) needed rebase.
I'm also trying to isolate a good small base for policy to use as an example and confirm what I think @luke-jr and I (and hopefully everyone) can agree on.

@Diapolo
Copy link

Diapolo commented Jan 20, 2015

Pretty cool, that you are following the ordering style still ^^. Does this also speedup compilation times, did you benchmark it?

@jtimon
Copy link
Contributor Author

jtimon commented Jan 21, 2015

@Diapolo thanks for double-checking the include alphabetical order.
I believe it does speedup compilation times, but I haven't benchmarked it. Some benchmarks would be great if you want to do them.

@jtimon
Copy link
Contributor Author

jtimon commented Jan 23, 2015

I left the final commit cleaning up the includes for later.
It is the hardest to review. The remaining commits are practically move-only. The only change is creating CMainSignals& GetMainSignals() for accessing g_signals from main. So the PR becomes trivial to review and it's much less likely to need rebases.
On the other hand the cleaning up commit is likely to need frequent rebase and would likely break many open PRs so I've created #5697 which builds on top of this as well as on other useful and trivial preparations for consensus and policy code movements (#5696).

@jtimon jtimon changed the title Refactor: Don't include main.h from any other header MOVEONLY-ish: Preparations to not include main.h from any other header Jan 23, 2015
@jtimon
Copy link
Contributor Author

jtimon commented Feb 3, 2015

Needed rebase.

@jtimon jtimon changed the title MOVEONLY-ish: Preparations to not include main.h from any other header MOVEONLY-ish: Do not include main.h from any other header Feb 5, 2015
@jtimon
Copy link
Contributor Author

jtimon commented Feb 5, 2015

Needed rebase. I added a commit to not include main.h from any other header again, but it's not a big and exhaustive cleanup as it was at the beginning. I still leave that for #5697 after more code movements.

@theuni
Copy link
Member

theuni commented Feb 5, 2015

ut ACK, assuming travis is happy tomorrow. Verified that the MOVEONLY commits are still move only.

@theuni
Copy link
Member

theuni commented Feb 19, 2015

ACK. Could you please give this a quick bump for travis, though? There were some caching issues that have been long-fixed.

@jtimon
Copy link
Contributor Author

jtimon commented Feb 20, 2015

Changed the last commit's id to give travis another try as demanded by @theuni

@theuni
Copy link
Member

theuni commented Feb 20, 2015

s/demanded by/humbly requested by/ :)

All green now, thanks.

@jtimon
Copy link
Contributor Author

jtimon commented Feb 20, 2015

Sure, humbly requested, thanks for the review and ack.

@jtimon
Copy link
Contributor Author

jtimon commented Mar 11, 2015

ping

@sipa
Copy link
Member

sipa commented Mar 11, 2015

The first commit doesn't make sense to me: CNodeStateStats is statistics of CNodeState, which is a main-specific data structure. Moving it up to a higher layer (net) seems wrong.

@jtimon
Copy link
Contributor Author

jtimon commented Mar 11, 2015

How is net.o is higher level than main.o? main.cpp depends on net and not the other way around...

@sipa
Copy link
Member

sipa commented Mar 12, 2015

Maybe my terminology is confused. I mean main is a client of net, building on top of it. Net should not know anything about what its clients do. CNodeStateStats is stats about CNodeState, the message processing specific data structure about nodes. Message processing is done in main, so this data structure definition belongs there and nowhere else.

Don't get me wrong: the current placing of code in main and net is terrible, but we shouldn't hack around that. Message processing needs to be split up, and moved out to separate modules, and the related data structures with it.

@jtimon
Copy link
Contributor Author

jtimon commented Mar 13, 2015

Rebased without the first commit as suggested by @sipa

Copy link
Member

Choose a reason for hiding this comment

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

That's sad, we should move that elsewhere (not a criticism on your PR, just noticing).

@sipa
Copy link
Member

sipa commented Mar 13, 2015

Untested ACK.

@theuni
Copy link
Member

theuni commented Mar 15, 2015

utACK. I'd like to see the node info moved out as well, but that makes sense to do separately.

@jtimon
Copy link
Contributor Author

jtimon commented Mar 24, 2015

Needed rebase, I also slightly improved the includes.
The commit that was criticized was already removed before needing the latest rebase.
This is quite uncontroversial, it has been reviewed, it has been open for long...is there any specific reason not to merge this?

@laanwj
Copy link
Member

laanwj commented Mar 24, 2015

@jtimon No specific reason, just a overload of pulls caused me to lose track of this one for a while, sorry for that.

@laanwj laanwj merged commit 8a893c9 into bitcoin:master Mar 24, 2015
laanwj added a commit that referenced this pull request Mar 24, 2015
8a893c9 Includes: Do not include main.h from any other header (Jorge Timón)
eca0b1e Includes: MOVEONLY: move more method definitions out of wallet.h (Jorge Timón)
26c16d9 Includes: Refactor: Move CValidationInterface and CMainSignals out of main (Jorge Timón)
laanwj added a commit that referenced this pull request Mar 24, 2015
fanquake added a commit to fanquake/bitcoin that referenced this pull request Mar 29, 2015
laanwj added a commit that referenced this pull request Mar 30, 2015
63e4c9c Fix clang compile warnings intriduced in #5681 (Michael Ford)
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants