Skip to content

Conversation

@Empact
Copy link
Contributor

@Empact Empact commented Jul 1, 2018

AppInitMain goes from ~650 lines to ~500. This also replaces constructs like
while(false) and using break vs return with a simple bool result for more
explicit operation.

Prompted by looking into #13577

Suggest: git diff --color-moved=dimmed_zebra --color-moved-ws=allow-indentation-change head^ to aid review.

@Empact Empact force-pushed the app-init-load-block-index branch 2 times, most recently from 8426636 to e93569a Compare July 1, 2018 20:30
@Empact Empact force-pushed the app-init-load-block-index branch 3 times, most recently from 6bb58a2 to c913c77 Compare July 2, 2018 06:13
@fanquake
Copy link
Member

fanquake commented Jul 2, 2018

Both Windows builds failed with:

In file included from /home/travis/build/bitcoin/bitcoin/depends/i686-w64-mingw32/share/../include/boost/thread/win32/condition_variable.hpp:9:0,
                 from /home/travis/build/bitcoin/bitcoin/depends/i686-w64-mingw32/share/../include/boost/thread/condition_variable.hpp:14,
                 from ./util.h:35,
                 from ./init.h:11,
                 from init.cpp:10:
/home/travis/build/bitcoin/bitcoin/depends/i686-w64-mingw32/share/../include/boost/thread/win32/thread_primitives.hpp:177:55: warning: conflicts with previous declaration 'void* boost::detail::win32::GetModuleHandleA(const char*)'
                 __declspec(dllimport) void* __stdcall GetModuleHandleA(char const*);
                                                       ^~~~~~~~~~~~~~~~
In file included from /usr/share/mingw-w64/include/windows.h:71:0,
                 from /usr/share/mingw-w64/include/winsock2.h:23,
                 from ./compat.h:39,
                 from ./util.h:17,
                 from ./init.h:11,
                 from init.cpp:10:
init.cpp:1245:5: error: expected identifier before numeric constant
     ERROR = 2,
     ^
init.cpp:1245:5: error: expected '}' before numeric constant
init.cpp:1245:5: error: expected unqualified-id before numeric constant
init.cpp:1246:1: error: expected declaration before '}' token
 };
 ^
make[2]: *** [libbitcoin_server_a-init.o] Error 1
Makefile:5820: recipe for target 'libbitcoin_server_a-init.o' failed

@Empact Empact force-pushed the app-init-load-block-index branch from c913c77 to 67ed865 Compare July 2, 2018 07:26
@Empact
Copy link
Contributor Author

Empact commented Jul 2, 2018

Renamed ERROR to FATAL to avoid windows conflict. Note this was in an enum class so seems Windows is applying an ERROR macro or the like.

@jimpo
Copy link
Contributor

jimpo commented Jul 2, 2018

utACK 67ed865.

Nice refactor. Personally, I find the enum a bit heavy and think it would be simpler to return a bool and an additional bool fatal_err outparam, but I don't feel too strongly. Check in the false return case could just be

if (fShutdownRequested) {
} else if (success) {
} else if (fReset || fatal_err) {
   return InitError( );
} else {
}

@Empact Empact force-pushed the app-init-load-block-index branch from 67ed865 to fb28c7f Compare July 2, 2018 20:07
@Empact
Copy link
Contributor Author

Empact commented Jul 2, 2018

Thanks for the review @jimpo. I see what you mean - switched to a boolean return, and made fReset an out arg as it was already being used to trigger the retry behavior, so now it can be toggled within the function to disable retry. Lmk if you have thoughts on that.

@jimpo
Copy link
Contributor

jimpo commented Jul 2, 2018

utACK fb28c7f5cf903c0c21f823b2e179a39bd69c9549

Yes, I like this approach more.

@Empact Empact force-pushed the app-init-load-block-index branch from fb28c7f to b3a01bd Compare July 5, 2018 15:50
@Empact
Copy link
Contributor Author

Empact commented Jul 5, 2018

Rebased for #13235

@laanwj
Copy link
Member

laanwj commented Jul 5, 2018

Needs rebase for #13577

@Empact Empact force-pushed the app-init-load-block-index branch from b3a01bd to 463994c Compare July 6, 2018 04:16
@Empact
Copy link
Contributor Author

Empact commented Jul 6, 2018

Rebased for #13577

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 6, 2018

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #15329 (Fix InitError() and InitWarning() content by hebasto)
  • #15218 (validation: Flush state after initial sync by andrewtoth)
  • #12980 (Allow quicker shutdowns during LoadBlockIndex() by jonasschnelli)

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.

@Empact Empact force-pushed the app-init-load-block-index branch 2 times, most recently from 262a3f2 to 4c0ea2e Compare July 9, 2018 03:39
@Empact
Copy link
Contributor Author

Empact commented Jul 9, 2018

Switched to using function-try-block. If people aren't into that, maybe we should discourage them in the developer-notes?
https://en.cppreference.com/w/cpp/language/function-try-block

@promag
Copy link
Contributor

promag commented Jul 9, 2018

Travis failed with unrelated error, restarted.

Regarding function-try-block I'm -0 if the reasoning is just to save one level of indentation in the function body.

@Empact Empact force-pushed the app-init-load-block-index branch from 4c0ea2e to a2dbe2a Compare July 9, 2018 14:57
@Empact
Copy link
Contributor Author

Empact commented Jul 9, 2018

Yeah, on second thought, switched back to regular try/catch. The framing of the function body and the consistent treatment help with the reading of the function IMO.

@promag
Copy link
Contributor

promag commented Jul 16, 2018

utACK a2dbe2a.

@Empact
Copy link
Contributor Author

Empact commented Nov 10, 2018

Rebased for #14437

@Empact
Copy link
Contributor Author

Empact commented Nov 10, 2018

Appveyor failure looks unrelated

@Empact Empact force-pushed the app-init-load-block-index branch from 64f9c90 to d1a0c39 Compare January 17, 2019 12:49
@Empact
Copy link
Contributor Author

Empact commented Jan 17, 2019

Reworked to minimize git diff --color-moved=dimmed_zebra --color-moved-ws=allow-indentation-change head^. Now is a minimal extraction.

@Empact Empact force-pushed the app-init-load-block-index branch from d1a0c39 to 44c7789 Compare March 9, 2019 15:29
@Empact
Copy link
Contributor Author

Empact commented Mar 9, 2019

Rebase for #15402

@Empact Empact force-pushed the app-init-load-block-index branch 2 times, most recently from f37aeea to 6dd65f8 Compare March 9, 2019 18:29
AppInitMain goes from ~650 lines to ~500. This also replaces
constructs like `while(false)` and using `break` vs `return` with
more explicit operation.
@Empact Empact force-pushed the app-init-load-block-index branch from 6dd65f8 to c95a277 Compare May 17, 2019 19:06
@Empact
Copy link
Contributor Author

Empact commented May 17, 2019

Rebased

// If the loaded chain has a wrong genesis, bail out immediately
// (we're likely using a testnet datadir, or the other way around).
if (!mapBlockIndex.empty() && !LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) {
fReset = true; // don't retry
Copy link
Contributor

Choose a reason for hiding this comment

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

was this added? I don't see it in the original block. not saying it's wrong, but just wondering.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's that way because there were 2 ways to exit the prior codeblock: break and return. This is special handling for the one return case.

@DrahtBot
Copy link
Contributor

Needs rebase

@Empact
Copy link
Contributor Author

Empact commented May 28, 2019

Closing as rebasing this is too much a chore. :P

@Empact Empact closed this May 28, 2019
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 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.

10 participants