From f8befc811cb6e5dcd7bf1dc81e6452e93aec8079 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Thu, 7 Sep 2023 21:07:02 +0700 Subject: [PATCH] fix: add missing includes and remove obsolete includes (#5562) ## Issue being fixed or feature implemented Some headers or modules are used objects from STL without including it directly, it cause compilation failures on some platforms for some specific compilers such as #5554 ## What was done? Added missing includes and removed obsolete includes for `optional`, `deque`, `tuple`, `unordered_set`, `unordered_map`, `set` and `atomic`. Please, note, that this PR doesn't cover all cases, only cases when it is obviously missing or obviously obsolete. Also most of changes belongs to to dash specific code; but for cases of original bitcoin code I keep it untouched, such as missing in `src/psbt.h` I used this script to get a list of files/headers which looks suspicious `./headers-scanner.sh std::optional optional`: ```bash #!/bin/bash set -e function check_includes() { obj=$1 header=$2 file=$3 used=0 included=0 grep "$obj" "$file" >/dev/null 2>/dev/null && used=1 grep "include <$header>" $file >/dev/null 2>/dev/null && included=1 if [ $used == 1 ] && [ $included == 0 ] then echo "missing <$header> in $file" fi if [ $used == 0 ] && [ $included == 1 ] then echo "obsolete <$header> in $file" fi } export -f check_includes obj=$1 header=$2 find src \( -name '*.h' -or -name '*.cpp' -or -name '*.hpp' \) -exec bash -c 'check_includes "$0" "$1" "$2"' "$obj" "$header" {} \; ``` ## How Has This Been Tested? Built code locally ## Breaking Changes n/a ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone --- src/bench/addrman.cpp | 1 - src/bitcoin-tx.cpp | 1 + src/bitcoind.cpp | 1 - src/chainparams.h | 1 + src/coinjoin/client.h | 3 ++- src/coinjoin/coinjoin.h | 2 ++ src/consensus/params.h | 1 - src/dbwrapper.cpp | 1 + src/evo/cbtx.h | 2 ++ src/evo/deterministicmns.h | 1 + src/evo/mnauth.cpp | 2 -- src/index/base.h | 2 ++ src/init.cpp | 1 + src/llmq/chainlocks.h | 2 ++ src/llmq/dkgsession.cpp | 1 + src/llmq/dkgsessionhandler.h | 2 ++ src/llmq/dkgsessionmgr.h | 3 +++ src/llmq/instantsend.h | 1 + src/llmq/quorums.h | 3 +++ src/llmq/signing_shares.h | 1 + src/llmq/utils.cpp | 1 + src/net.h | 1 - src/net_processing.cpp | 1 + src/net_processing.h | 2 ++ src/node/blockstorage.h | 1 - src/node/coinstats.h | 1 + src/node/interfaces.cpp | 1 + src/protocol.cpp | 2 ++ src/rpc/blockchain.cpp | 1 + src/rpc/misc.cpp | 1 - src/rpc/net.cpp | 2 -- src/rpc/quorums.cpp | 1 + src/rpc/server.cpp | 1 + src/rpc/util.cpp | 2 -- src/test/addrman_tests.cpp | 1 - src/test/checkqueue_tests.cpp | 1 - src/test/descriptor_tests.cpp | 1 + src/test/evo_assetlocks_tests.cpp | 1 - src/test/fuzz/autofile.cpp | 1 - src/test/fuzz/integer.cpp | 1 + src/test/fuzz/rolling_bloom_filter.cpp | 1 - src/test/fuzz/script_descriptor_cache.cpp | 1 - src/util/enumerate.h | 1 - src/util/overflow.h | 1 + src/util/system.cpp | 1 + src/validation.cpp | 1 + src/wallet/bdb.h | 1 - src/wallet/rpcwallet.cpp | 1 + src/wallet/scriptpubkeyman.h | 2 ++ src/wallet/wallet.h | 3 ++- 50 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/bench/addrman.cpp b/src/bench/addrman.cpp index b7bd8a3261..d8e341a945 100644 --- a/src/bench/addrman.cpp +++ b/src/bench/addrman.cpp @@ -7,7 +7,6 @@ #include #include -#include #include /* A "source" is a source address from which we have received a bunch of other addresses. */ diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index d99b12ee77..3f794aa1a4 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 426b47ca3f..fcc1485920 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -26,7 +26,6 @@ #include #include -#include #include const std::function G_TRANSLATION_FUN = nullptr; diff --git a/src/chainparams.h b/src/chainparams.h index bcdcf664dc..59404c9d03 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -15,6 +15,7 @@ #include #include +#include #include #include diff --git a/src/coinjoin/client.h b/src/coinjoin/client.h index f629df3b74..e336475bc2 100644 --- a/src/coinjoin/client.h +++ b/src/coinjoin/client.h @@ -9,8 +9,9 @@ #include #include -#include #include +#include +#include class CDeterministicMN; using CDeterministicMNCPtr = std::shared_ptr; diff --git a/src/coinjoin/coinjoin.h b/src/coinjoin/coinjoin.h index 22f541303e..efe19c724e 100644 --- a/src/coinjoin/coinjoin.h +++ b/src/coinjoin/coinjoin.h @@ -17,6 +17,8 @@ #include #include +#include +#include #include class CCoinJoin; diff --git a/src/consensus/params.h b/src/consensus/params.h index 4e3442cb0e..208d2afba6 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -10,7 +10,6 @@ #include #include -#include namespace Consensus { diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index c3cec13356..dbe4db5d5b 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -13,6 +13,7 @@ #include #include #include +#include class CBitcoinLevelDBLogger : public leveldb::Logger { public: diff --git a/src/evo/cbtx.h b/src/evo/cbtx.h index 825c795772..c88a04b30f 100644 --- a/src/evo/cbtx.h +++ b/src/evo/cbtx.h @@ -9,6 +9,8 @@ #include #include +#include + class BlockValidationState; class CBlock; class CBlockIndex; diff --git a/src/evo/deterministicmns.h b/src/evo/deterministicmns.h index 1a37910b16..1e74c82cdd 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -19,6 +19,7 @@ #include +#include #include #include #include diff --git a/src/evo/mnauth.cpp b/src/evo/mnauth.cpp index 70cccc47f9..107eecd005 100644 --- a/src/evo/mnauth.cpp +++ b/src/evo/mnauth.cpp @@ -17,8 +17,6 @@ #include #include -#include - void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CBlockIndex* tip) { LOCK(activeMasternodeInfoCs); diff --git a/src/index/base.h b/src/index/base.h index 9f909de6d0..1813e2d7f4 100644 --- a/src/index/base.h +++ b/src/index/base.h @@ -11,6 +11,8 @@ #include #include +#include + class CBlockIndex; class CChainState; diff --git a/src/init.cpp b/src/init.cpp index 7073a5c030..d108cfe630 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -102,6 +102,7 @@ #include #include #include +#include #include #include #include diff --git a/src/llmq/chainlocks.h b/src/llmq/chainlocks.h index 66234a77b3..97454aa769 100644 --- a/src/llmq/chainlocks.h +++ b/src/llmq/chainlocks.h @@ -17,6 +17,8 @@ #include #include +#include +#include #include class CChainState; diff --git a/src/llmq/dkgsession.cpp b/src/llmq/dkgsession.cpp index 105ba7f75a..e79e6596ec 100644 --- a/src/llmq/dkgsession.cpp +++ b/src/llmq/dkgsession.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include diff --git a/src/llmq/dkgsessionhandler.h b/src/llmq/dkgsessionhandler.h index 901086f521..39c5f0e67c 100644 --- a/src/llmq/dkgsessionhandler.h +++ b/src/llmq/dkgsessionhandler.h @@ -9,6 +9,8 @@ #include #include +#include +#include #include class CBlockIndex; diff --git a/src/llmq/dkgsessionmgr.h b/src/llmq/dkgsessionmgr.h index df56d9a286..9b8c45b424 100644 --- a/src/llmq/dkgsessionmgr.h +++ b/src/llmq/dkgsessionmgr.h @@ -10,6 +10,9 @@ #include #include +#include +#include + class CBlockIndex; class CChainState; class CDKGDebugManager; diff --git a/src/llmq/instantsend.h b/src/llmq/instantsend.h index 5764daff32..cf4c88d0a3 100644 --- a/src/llmq/instantsend.h +++ b/src/llmq/instantsend.h @@ -15,6 +15,7 @@ #include #include +#include #include #include diff --git a/src/llmq/quorums.h b/src/llmq/quorums.h index 7f64e59853..65a8f723b9 100644 --- a/src/llmq/quorums.h +++ b/src/llmq/quorums.h @@ -16,6 +16,9 @@ #include +#include +#include + class CBlockIndex; class CChainState; class CConnman; diff --git a/src/llmq/signing_shares.h b/src/llmq/signing_shares.h index 0ff9abac43..e04f1e9248 100644 --- a/src/llmq/signing_shares.h +++ b/src/llmq/signing_shares.h @@ -14,6 +14,7 @@ #include #include +#include #include #include #include diff --git a/src/llmq/utils.cpp b/src/llmq/utils.cpp index d1ebad745a..b21b4ed031 100644 --- a/src/llmq/utils.cpp +++ b/src/llmq/utils.cpp @@ -22,6 +22,7 @@ #include #include +#include #include static constexpr int TESTNET_LLMQ_25_67_ACTIVATION_HEIGHT = 847000; diff --git a/src/net.h b/src/net.h index 08716e5a4a..ebb6a74d96 100644 --- a/src/net.h +++ b/src/net.h @@ -36,7 +36,6 @@ #include #include #include -#include #include #include diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 865c75ad7b..6c0234265b 100755 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include diff --git a/src/net_processing.h b/src/net_processing.h index 0f9bde911e..132d04f902 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -10,6 +10,8 @@ #include #include +#include + class CAddrMan; class CTxMemPool; class ChainstateManager; diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h index 19b75d9c3f..c2df606b18 100644 --- a/src/node/blockstorage.h +++ b/src/node/blockstorage.h @@ -8,7 +8,6 @@ #include #include // For CMessageHeader::MessageStartChars -#include #include #include diff --git a/src/node/coinstats.h b/src/node/coinstats.h index dc4d062154..10e8cf1c8e 100644 --- a/src/node/coinstats.h +++ b/src/node/coinstats.h @@ -14,6 +14,7 @@ #include #include +#include class BlockManager; class CCoinsView; diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 036187e538..09a69afc03 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -60,6 +60,7 @@ #include #include +#include #include using interfaces::BlockTip; diff --git a/src/protocol.cpp b/src/protocol.cpp index 66ee7d9995..3e3fd28cb4 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -7,6 +7,8 @@ #include +#include + static std::atomic g_initial_block_download_completed(false); #define MAKE_MSG(var_name, p2p_name_str) \ diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index e9020fcfae..f0a0bbede1 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -51,6 +51,7 @@ #include +#include #include #include diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 1716aa1cb6..56eb970fab 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -33,7 +33,6 @@ #include #include -#include #ifdef HAVE_MALLOC_INFO #include #endif diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index fe3db628d2..eb9b0af4d2 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -27,8 +27,6 @@ #include #include -#include - #include static UniValue getconnectioncount(const JSONRPCRequest& request) diff --git a/src/rpc/quorums.cpp b/src/rpc/quorums.cpp index fa620da92e..09635e5047 100644 --- a/src/rpc/quorums.cpp +++ b/src/rpc/quorums.cpp @@ -25,6 +25,7 @@ #include #include +#include namespace llmq { extern const std::string CLSIG_REQUESTID_PREFIX; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 8f3c778ae9..a87c7e2263 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -17,6 +17,7 @@ #include #include +#include #include // for unique_ptr #include diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index d6d9d2a12b..ad0894954c 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -15,8 +15,6 @@ #include #include -#include - const std::string UNIX_EPOCH_TIME = "UNIX epoch time"; const std::string EXAMPLE_ADDRESS[2] = {"XunLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPw0", "XwQQkwA4FYkq2XERzMY2CiAZhJTEDAbtc0"}; diff --git a/src/test/addrman_tests.cpp b/src/test/addrman_tests.cpp index ad18bf04c8..fbde09ee8f 100644 --- a/src/test/addrman_tests.cpp +++ b/src/test/addrman_tests.cpp @@ -13,7 +13,6 @@ #include -#include #include class CAddrManTest : public CAddrMan diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index b2db2882a5..93038c10f1 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include diff --git a/src/test/descriptor_tests.cpp b/src/test/descriptor_tests.cpp index abc5292b82..9f23dea8c3 100644 --- a/src/test/descriptor_tests.cpp +++ b/src/test/descriptor_tests.cpp @@ -10,6 +10,7 @@ #include +#include #include #include diff --git a/src/test/evo_assetlocks_tests.cpp b/src/test/evo_assetlocks_tests.cpp index f4e999b21a..d4138863ac 100644 --- a/src/test/evo_assetlocks_tests.cpp +++ b/src/test/evo_assetlocks_tests.cpp @@ -16,7 +16,6 @@ #include -#include // // Helper: create two dummy transactions, each with // two outputs. The first has 11 and 50 CENT outputs diff --git a/src/test/fuzz/autofile.cpp b/src/test/fuzz/autofile.cpp index e3f1a8572a..c43e5b90e8 100644 --- a/src/test/fuzz/autofile.cpp +++ b/src/test/fuzz/autofile.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include diff --git a/src/test/fuzz/integer.cpp b/src/test/fuzz/integer.cpp index 30351c398a..7669ca06d5 100644 --- a/src/test/fuzz/integer.cpp +++ b/src/test/fuzz/integer.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include diff --git a/src/test/fuzz/rolling_bloom_filter.cpp b/src/test/fuzz/rolling_bloom_filter.cpp index 7e7c4cf428..6a52bcc69c 100644 --- a/src/test/fuzz/rolling_bloom_filter.cpp +++ b/src/test/fuzz/rolling_bloom_filter.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include diff --git a/src/test/fuzz/script_descriptor_cache.cpp b/src/test/fuzz/script_descriptor_cache.cpp index 6ce13d5679..455063ab83 100644 --- a/src/test/fuzz/script_descriptor_cache.cpp +++ b/src/test/fuzz/script_descriptor_cache.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include diff --git a/src/util/enumerate.h b/src/util/enumerate.h index 8bec72dc58..ef23ed965e 100644 --- a/src/util/enumerate.h +++ b/src/util/enumerate.h @@ -5,7 +5,6 @@ #ifndef BITCOIN_UTIL_ENUMERATE_H #define BITCOIN_UTIL_ENUMERATE_H -#include #include /** diff --git a/src/util/overflow.h b/src/util/overflow.h index 5982af8d04..c70a8b663e 100644 --- a/src/util/overflow.h +++ b/src/util/overflow.h @@ -6,6 +6,7 @@ #define BITCOIN_UTIL_OVERFLOW_H #include +#include #include template diff --git a/src/util/system.cpp b/src/util/system.cpp index c6c151f210..8e87835f42 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -35,6 +35,7 @@ #endif // __linux__ #include +#include #include #include #include diff --git a/src/validation.cpp b/src/validation.cpp index 7c0d0a53cc..845e9ba229 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -62,6 +62,7 @@ #include +#include #include #include diff --git a/src/wallet/bdb.h b/src/wallet/bdb.h index b6ca5d4e29..2fc131d3ee 100644 --- a/src/wallet/bdb.h +++ b/src/wallet/bdb.h @@ -13,7 +13,6 @@ #include #include -#include #include #include #include diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 827b412e7f..a30824c370 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -46,6 +46,7 @@ #include +#include using interfaces::FoundBlock; diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h index 1259f8c4a9..07e0d806a8 100644 --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -18,6 +18,8 @@ #include +#include + // Wallet storage things that ScriptPubKeyMans need in order to be able to store things to the wallet database. // It provides access to things that are part of the entire wallet and not specific to a ScriptPubKeyMan such as // wallet flags, wallet version, encryption keys, encryption status, and the database itself. This allows a diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 83eaff9fbb..b816a2d183 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -31,13 +31,14 @@ #include #include -#include #include #include +#include #include #include #include #include +#include #include #include