Skip to content

Conversation

Empact
Copy link
Contributor

@Empact Empact commented May 15, 2018

Most includers just wanted to react to pending shutdown.

This isolates access to fRequestShutdown and limits access to the shutdown api functions, including the new CancelShutdown for setting it to false.

@Empact
Copy link
Contributor Author

Empact commented May 15, 2018

Prompted by #13228

@fanquake
Copy link
Member

Failures in bench_bitcoin in a few of the Travis builds:

  CXXLD    bench/bench_bitcoin
libbitcoin_wallet.a(libbitcoin_wallet_a-wallet.o): In function `CWalletTx::RelayWalletTransaction(CConnman*)':
wallet.cpp:(.text+0x5cea): undefined reference to `CConnman::NodeFullyConnected(CNode const*)'
collect2: error: ld returned 1 exit status
make[2]: *** [bench/bench_bitcoin] Error 1

@practicalswift
Copy link
Contributor

Concept ACK

@laanwj
Copy link
Member

laanwj commented May 15, 2018

I entertained the idea of creating a shutdown.(cpp|h) a few times as well. It seems we have too much non-initialization-related things in init. Concept ACK.

@Empact Empact force-pushed the init-circ-init branch 3 times, most recently from 58bc7bf to 624d44a Compare May 15, 2018 20:01
@Empact
Copy link
Contributor Author

Empact commented May 15, 2018

Based this on #13239, which fixes the linker issues.

@Empact Empact force-pushed the init-circ-init branch 2 times, most recently from a5710f1 to f7033bf Compare May 15, 2018 20:49
@jonasschnelli
Copy link
Contributor

utACK f7033bf5767e674abfee2bd53cd6b9f5c3831482

1 similar comment
@practicalswift
Copy link
Contributor

utACK f7033bf5767e674abfee2bd53cd6b9f5c3831482

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.

Concept ACK.

The PR suggests that the following dependencies wouldn't exist:

Circular dependency: init -> net_processing -> init
Circular dependency: init -> validationinterface -> init

Also, I've removed the first 3 commits locally and it still compiles and reports the same dependencies as above. I wonder why are those commits included here.

Edit: oh this is rebased on #13239.

src/shutdown.cpp Outdated

#include <atomic>

std::atomic<bool> fRequestShutdown(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

static std::atomic<bool> fRequestShutdown{false};

src/shutdown.h Outdated
@@ -0,0 +1,13 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2017 The Bitcoin Core developers
Copy link
Contributor

Choose a reason for hiding this comment

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

src/txdb.cpp Outdated
@@ -12,7 +12,7 @@
#include <uint256.h>
#include <util.h>
#include <ui_interface.h>
#include <init.h>
#include <shutdown.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Keep sorted.

Copy link
Member

Choose a reason for hiding this comment

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

Note that you can install clang-format and run the https://github.com/bitcoin/bitcoin/tree/master/contrib/devtools#clang-format-diffpy script which fixes all white space and sorting issues

src/shutdown.cpp Outdated
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <atomic>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, also #include <shutdown.h>?

@Empact Empact force-pushed the init-circ-init branch 2 times, most recently from 4f4cae6 to e52d0bf Compare May 16, 2018 19:26
@Empact
Copy link
Contributor Author

Empact commented May 16, 2018

  • Declared fRequestShutdown static
  • Included shutdown.h in shutdown.cpp
  • Updated copyright years
  • Ran clang-format to sort includes

Thanks @promag / @MarcoFalke

@promag
Copy link
Contributor

promag commented May 16, 2018

Still has the following circular dependencies:

Circular dependency: init -> net_processing -> init
Circular dependency: init -> validationinterface -> init

Should these be removed in this PR?

@Empact
Copy link
Contributor Author

Empact commented May 16, 2018

@promag Added a commit to remove unused includes of init from 4 files. I'd looked into those before but left them out to narrow this PR.

@promag
Copy link
Contributor

promag commented May 16, 2018

@Empact needs rebase.

@Empact
Copy link
Contributor Author

Empact commented May 16, 2018

Rebased

@Empact
Copy link
Contributor Author

Empact commented May 18, 2018

@jonasschnelli @practicalswift would you take a look at #13239? It's the necessary precondition for this.

@Empact Empact force-pushed the init-circ-init branch 2 times, most recently from 5ab1f4c to 2e73ca5 Compare May 24, 2018 00:07
@Empact Empact force-pushed the init-circ-init branch 2 times, most recently from a4e0fdf to 9b583bd Compare June 1, 2018 23:19
Most includers just wanted to react to pending shutdown.

This isolates access to `fRequestShutdown` and limits access to the shutdown
api functions, including the new `AbortShutdown` for setting it to `false`.

Note I originally called `AbortShutdown` `CancelShutdown` but that name was
already taken by winuser.h
https://travis-ci.org/bitcoin/bitcoin/jobs/386913329

This change also triggered a build error in bench. Fixing it required moving LIBBITCOIN_SERVER after LIBBITCOIN_WALLET in bench_bench_bitcoin_LDADD To make
server definitions in src/net.cpp available to wallet methods in
src/wallet/wallet.cpp. Specifically, solving:

  libbitcoin_wallet.a(libbitcoin_wallet_a-wallet.o): In function `CWalletTx::RelayWalletTransaction(CConnman*)':
  wallet.cpp:(.text+0x3f0e): undefined reference to `CConnman::NodeFullyConnected(CNode const*)'
  collect2: error: ld returned 1 exit status

https://travis-ci.org/bitcoin/bitcoin/jobs/392133581

Need for remaining init.h includes confirmed via a thorough search with a more
specific regex:
  \bInterrupt\(\)|\bShutdown\(\)|\bInitLogging\(\)|\bInitParameterInteraction\(\)|\bAppInitBasicSetup\(\)|\bAppInitParameterInteraction\(\)|\bAppInitSanityChecks\(\)|\bAppInitLockDataDirectory\(\)|\bAppInitMain\(\)|\bSetupServerArgs\(\)|\bLicenseInfo\(\)|g_wallet_init_interface|init.h
@Empact
Copy link
Contributor Author

Empact commented Jun 25, 2018

Rebased for #13458

@ken2812221
Copy link
Contributor

utACK 1fabd59

@sipa
Copy link
Member

sipa commented Jun 27, 2018

@Empact In your first commit you write "These were entirely unused, as based on successful compilation". That's not a sufficient argument - init.h could still be included indirectly through another header, while exported symbols from init.h are still used.

This doesn't mean it wrong to remove them, just that "it compiles without them" isn't a sufficient reason. Tools like iwyu can help with this.

@Empact
Copy link
Contributor Author

Empact commented Jun 27, 2018

@sipa thanks I’ll check that out

@Empact
Copy link
Contributor Author

Empact commented Jun 27, 2018

Oh btw I did manually check using this grep:

  \bStartShutdown\(\)|\bShutdownRequested\(\)|\bInterrupt\(\)|\bShutdown\(\)|\bInitLogging\(\)|\bInitParameterInteraction\(\)|\bAppInitBasicSetup\(\)|\bAppInitParameterInteraction\(\)|\bAppInitSanityChecks\(\)|\bAppInitLockDataDirectory\(\)|\bAppInitMain\(\)|\bSetupServerArgs\(\)|\bLicenseInfo\(\)|g_wallet_init_interface|init.h

But I'll check again with the above and using iwyu, which is probably more robust.

@sipa
Copy link
Member

sipa commented Jun 27, 2018

@Empact Oh, ignore my comment in that case. I just wanted to make sure you're not relying on indirect inclusions.

@sipa
Copy link
Member

sipa commented Jun 27, 2018

utACK 1fabd59

@Empact
Copy link
Contributor Author

Empact commented Jul 1, 2018

@practicalswift @jonasschnelli @promag could I get another look?

Alternatively I could split this into 2 PRS, the removal of the unnecessary includes and the shutdown.h extraction, if that would make review easier.

@laanwj
Copy link
Member

laanwj commented Jul 4, 2018

utACK 1fabd59

@laanwj laanwj merged commit 1fabd59 into bitcoin:master Jul 4, 2018
laanwj added a commit that referenced this pull request Jul 4, 2018
…ing shutdown.h

1fabd59 Break circular dependency: init -> * -> init by extracting shutdown.h (Ben Woosley)
e62fdfe Drop unused init.h includes (Ben Woosley)

Pull request description:

  Most includers just wanted to react to pending shutdown.

  This isolates access to `fRequestShutdown` and limits access to the shutdown api functions, including the new `CancelShutdown` for setting it to `false`.

Tree-SHA512: df42f75dfbba163576710e9a67cf1228531fd99d70a2f187bfba0bcc476d6749cf88180a97e66a81bb5b6c3c7f0917de7402d26039ba7b644cb7509b02f7e267
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jun 20, 2021
…extracting shutdown.h

1fabd59 Break circular dependency: init -> * -> init by extracting shutdown.h (Ben Woosley)
e62fdfe Drop unused init.h includes (Ben Woosley)

Pull request description:

  Most includers just wanted to react to pending shutdown.

  This isolates access to `fRequestShutdown` and limits access to the shutdown api functions, including the new `CancelShutdown` for setting it to `false`.

Tree-SHA512: df42f75dfbba163576710e9a67cf1228531fd99d70a2f187bfba0bcc476d6749cf88180a97e66a81bb5b6c3c7f0917de7402d26039ba7b644cb7509b02f7e267
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jun 20, 2021
…extracting shutdown.h

1fabd59 Break circular dependency: init -> * -> init by extracting shutdown.h (Ben Woosley)
e62fdfe Drop unused init.h includes (Ben Woosley)

Pull request description:

  Most includers just wanted to react to pending shutdown.

  This isolates access to `fRequestShutdown` and limits access to the shutdown api functions, including the new `CancelShutdown` for setting it to `false`.

Tree-SHA512: df42f75dfbba163576710e9a67cf1228531fd99d70a2f187bfba0bcc476d6749cf88180a97e66a81bb5b6c3c7f0917de7402d26039ba7b644cb7509b02f7e267
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jun 20, 2021
…extracting shutdown.h

1fabd59 Break circular dependency: init -> * -> init by extracting shutdown.h (Ben Woosley)
e62fdfe Drop unused init.h includes (Ben Woosley)

Pull request description:

  Most includers just wanted to react to pending shutdown.

  This isolates access to `fRequestShutdown` and limits access to the shutdown api functions, including the new `CancelShutdown` for setting it to `false`.

Tree-SHA512: df42f75dfbba163576710e9a67cf1228531fd99d70a2f187bfba0bcc476d6749cf88180a97e66a81bb5b6c3c7f0917de7402d26039ba7b644cb7509b02f7e267
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jun 20, 2021
…extracting shutdown.h

1fabd59 Break circular dependency: init -> * -> init by extracting shutdown.h (Ben Woosley)
e62fdfe Drop unused init.h includes (Ben Woosley)

Pull request description:

  Most includers just wanted to react to pending shutdown.

  This isolates access to `fRequestShutdown` and limits access to the shutdown api functions, including the new `CancelShutdown` for setting it to `false`.

Tree-SHA512: df42f75dfbba163576710e9a67cf1228531fd99d70a2f187bfba0bcc476d6749cf88180a97e66a81bb5b6c3c7f0917de7402d26039ba7b644cb7509b02f7e267
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jun 20, 2021
…extracting shutdown.h

1fabd59 Break circular dependency: init -> * -> init by extracting shutdown.h (Ben Woosley)
e62fdfe Drop unused init.h includes (Ben Woosley)

Pull request description:

  Most includers just wanted to react to pending shutdown.

  This isolates access to `fRequestShutdown` and limits access to the shutdown api functions, including the new `CancelShutdown` for setting it to `false`.

Tree-SHA512: df42f75dfbba163576710e9a67cf1228531fd99d70a2f187bfba0bcc476d6749cf88180a97e66a81bb5b6c3c7f0917de7402d26039ba7b644cb7509b02f7e267
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jun 24, 2021
…extracting shutdown.h

1fabd59 Break circular dependency: init -> * -> init by extracting shutdown.h (Ben Woosley)
e62fdfe Drop unused init.h includes (Ben Woosley)

Pull request description:

  Most includers just wanted to react to pending shutdown.

  This isolates access to `fRequestShutdown` and limits access to the shutdown api functions, including the new `CancelShutdown` for setting it to `false`.

Tree-SHA512: df42f75dfbba163576710e9a67cf1228531fd99d70a2f187bfba0bcc476d6749cf88180a97e66a81bb5b6c3c7f0917de7402d26039ba7b644cb7509b02f7e267
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jun 26, 2021
…extracting shutdown.h

1fabd59 Break circular dependency: init -> * -> init by extracting shutdown.h (Ben Woosley)
e62fdfe Drop unused init.h includes (Ben Woosley)

Pull request description:

  Most includers just wanted to react to pending shutdown.

  This isolates access to `fRequestShutdown` and limits access to the shutdown api functions, including the new `CancelShutdown` for setting it to `false`.

Tree-SHA512: df42f75dfbba163576710e9a67cf1228531fd99d70a2f187bfba0bcc476d6749cf88180a97e66a81bb5b6c3c7f0917de7402d26039ba7b644cb7509b02f7e267
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jun 29, 2021
…extracting shutdown.h

1fabd59 Break circular dependency: init -> * -> init by extracting shutdown.h (Ben Woosley)
e62fdfe Drop unused init.h includes (Ben Woosley)

Pull request description:

  Most includers just wanted to react to pending shutdown.

  This isolates access to `fRequestShutdown` and limits access to the shutdown api functions, including the new `CancelShutdown` for setting it to `false`.

Tree-SHA512: df42f75dfbba163576710e9a67cf1228531fd99d70a2f187bfba0bcc476d6749cf88180a97e66a81bb5b6c3c7f0917de7402d26039ba7b644cb7509b02f7e267
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jun 29, 2021
…extracting shutdown.h

1fabd59 Break circular dependency: init -> * -> init by extracting shutdown.h (Ben Woosley)
e62fdfe Drop unused init.h includes (Ben Woosley)

Pull request description:

  Most includers just wanted to react to pending shutdown.

  This isolates access to `fRequestShutdown` and limits access to the shutdown api functions, including the new `CancelShutdown` for setting it to `false`.

Tree-SHA512: df42f75dfbba163576710e9a67cf1228531fd99d70a2f187bfba0bcc476d6749cf88180a97e66a81bb5b6c3c7f0917de7402d26039ba7b644cb7509b02f7e267
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jul 1, 2021
…extracting shutdown.h

1fabd59 Break circular dependency: init -> * -> init by extracting shutdown.h (Ben Woosley)
e62fdfe Drop unused init.h includes (Ben Woosley)

Pull request description:

  Most includers just wanted to react to pending shutdown.

  This isolates access to `fRequestShutdown` and limits access to the shutdown api functions, including the new `CancelShutdown` for setting it to `false`.

Tree-SHA512: df42f75dfbba163576710e9a67cf1228531fd99d70a2f187bfba0bcc476d6749cf88180a97e66a81bb5b6c3c7f0917de7402d26039ba7b644cb7509b02f7e267
@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.

10 participants