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 <map> 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
This commit is contained in:
Konstantin Akimov 2023-09-07 21:07:02 +07:00 committed by GitHub
parent bc6360f6aa
commit f8befc811c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 47 additions and 22 deletions

View File

@ -7,7 +7,6 @@
#include <random.h>
#include <util/time.h>
#include <optional>
#include <vector>
/* A "source" is a source address from which we have received a bunch of other addresses. */

View File

@ -25,6 +25,7 @@
#include <functional>
#include <memory>
#include <optional>
#include <stdio.h>
#include <stacktraces.h>

View File

@ -26,7 +26,6 @@
#include <util/url.h>
#include <functional>
#include <optional>
#include <stdio.h>
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;

View File

@ -15,6 +15,7 @@
#include <util/hash_type.h>
#include <memory>
#include <optional>
#include <string>
#include <vector>

View File

@ -9,8 +9,9 @@
#include <coinjoin/coinjoin.h>
#include <util/translation.h>
#include <utility>
#include <atomic>
#include <deque>
#include <utility>
class CDeterministicMN;
using CDeterministicMNCPtr = std::shared_ptr<const CDeterministicMN>;

View File

@ -17,6 +17,8 @@
#include <util/translation.h>
#include <version.h>
#include <atomic>
#include <optional>
#include <utility>
class CCoinJoin;

View File

@ -10,7 +10,6 @@
#include <llmq/params.h>
#include <limits>
#include <map>
namespace Consensus {

View File

@ -13,6 +13,7 @@
#include <memenv.h>
#include <stdint.h>
#include <algorithm>
#include <optional>
class CBitcoinLevelDBLogger : public leveldb::Logger {
public:

View File

@ -9,6 +9,8 @@
#include <primitives/transaction.h>
#include <univalue.h>
#include <optional>
class BlockValidationState;
class CBlock;
class CBlockIndex;

View File

@ -19,6 +19,7 @@
#include <immer/map.hpp>
#include <atomic>
#include <limits>
#include <numeric>
#include <unordered_map>

View File

@ -17,8 +17,6 @@
#include <netmessagemaker.h>
#include <validation.h>
#include <unordered_set>
void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CBlockIndex* tip)
{
LOCK(activeMasternodeInfoCs);

View File

@ -11,6 +11,8 @@
#include <threadinterrupt.h>
#include <validationinterface.h>
#include <atomic>
class CBlockIndex;
class CChainState;

View File

@ -102,6 +102,7 @@
#include <stdint.h>
#include <stdio.h>
#include <memory>
#include <optional>
#include <set>
#include <thread>
#include <vector>

View File

@ -17,6 +17,8 @@
#include <sync.h>
#include <atomic>
#include <map>
#include <unordered_map>
#include <unordered_set>
class CChainState;

View File

@ -19,6 +19,7 @@
#include <validation.h>
#include <cxxtimer.hpp>
#include <atomic>
#include <memory>
#include <util/irange.h>
#include <util/underlying.h>

View File

@ -9,6 +9,8 @@
#include <ctpl_stl.h>
#include <net.h>
#include <atomic>
#include <map>
#include <optional>
class CBlockIndex;

View File

@ -10,6 +10,9 @@
#include <bls/bls.h>
#include <bls/bls_worker.h>
#include <map>
#include <memory>
class CBlockIndex;
class CChainState;
class CDKGDebugManager;

View File

@ -15,6 +15,7 @@
#include <threadinterrupt.h>
#include <txmempool.h>
#include <atomic>
#include <unordered_map>
#include <unordered_set>

View File

@ -16,6 +16,9 @@
#include <evo/evodb.h>
#include <atomic>
#include <map>
class CBlockIndex;
class CChainState;
class CConnman;

View File

@ -14,6 +14,7 @@
#include <sync.h>
#include <uint256.h>
#include <atomic>
#include <optional>
#include <thread>
#include <unordered_map>

View File

@ -22,6 +22,7 @@
#include <validation.h>
#include <versionbits.h>
#include <atomic>
#include <optional>
static constexpr int TESTNET_LLMQ_25_67_ACTIVATION_HEIGHT = 847000;

View File

@ -36,7 +36,6 @@
#include <thread>
#include <memory>
#include <condition_variable>
#include <unordered_set>
#include <optional>
#include <queue>

View File

@ -34,6 +34,7 @@
#include <list>
#include <memory>
#include <optional>
#include <typeinfo>
#include <spork.h>

View File

@ -10,6 +10,8 @@
#include <sync.h>
#include <validationinterface.h>
#include <atomic>
class CAddrMan;
class CTxMemPool;
class ChainstateManager;

View File

@ -8,7 +8,6 @@
#include <fs.h>
#include <protocol.h> // For CMessageHeader::MessageStartChars
#include <atomic>
#include <cstdint>
#include <vector>

View File

@ -14,6 +14,7 @@
#include <cstdint>
#include <functional>
#include <optional>
class BlockManager;
class CCoinsView;

View File

@ -60,6 +60,7 @@
#include <boost/signals2/signal.hpp>
#include <memory>
#include <optional>
#include <utility>
using interfaces::BlockTip;

View File

@ -7,6 +7,8 @@
#include <util/system.h>
#include <atomic>
static std::atomic<bool> g_initial_block_download_completed(false);
#define MAKE_MSG(var_name, p2p_name_str) \

View File

@ -51,6 +51,7 @@
#include <merkleblock.h>
#include <atomic>
#include <condition_variable>
#include <mutex>

View File

@ -33,7 +33,6 @@
#include <spork.h>
#include <stdint.h>
#include <tuple>
#ifdef HAVE_MALLOC_INFO
#include <malloc.h>
#endif

View File

@ -27,8 +27,6 @@
#include <version.h>
#include <warnings.h>
#include <optional>
#include <univalue.h>
static UniValue getconnectioncount(const JSONRPCRequest& request)

View File

@ -25,6 +25,7 @@
#include <llmq/snapshot.h>
#include <iomanip>
#include <optional>
namespace llmq {
extern const std::string CLSIG_REQUESTID_PREFIX;

View File

@ -17,6 +17,7 @@
#include <boost/signals2/signal.hpp>
#include <algorithm>
#include <atomic>
#include <memory> // for unique_ptr
#include <unordered_map>

View File

@ -15,8 +15,6 @@
#include <util/string.h>
#include <util/translation.h>
#include <tuple>
const std::string UNIX_EPOCH_TIME = "UNIX epoch time";
const std::string EXAMPLE_ADDRESS[2] = {"XunLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPw0", "XwQQkwA4FYkq2XERzMY2CiAZhJTEDAbtc0"};

View File

@ -13,7 +13,6 @@
#include <boost/test/unit_test.hpp>
#include <optional>
#include <string>
class CAddrManTest : public CAddrMan

View File

@ -14,7 +14,6 @@
#include <condition_variable>
#include <mutex>
#include <thread>
#include <unordered_set>
#include <utility>
#include <vector>

View File

@ -10,6 +10,7 @@
#include <boost/test/unit_test.hpp>
#include <optional>
#include <string>
#include <vector>

View File

@ -16,7 +16,6 @@
#include <boost/test/unit_test.hpp>
#include <optional>
//
// Helper: create two dummy transactions, each with
// two outputs. The first has 11 and 50 CENT outputs

View File

@ -10,7 +10,6 @@
#include <array>
#include <cstdint>
#include <iostream>
#include <optional>
#include <string>
#include <vector>

View File

@ -38,6 +38,7 @@
#include <chrono>
#include <ctime>
#include <limits>
#include <optional>
#include <set>
#include <vector>

View File

@ -10,7 +10,6 @@
#include <cassert>
#include <cstdint>
#include <optional>
#include <string>
#include <vector>

View File

@ -9,7 +9,6 @@
#include <test/fuzz/util.h>
#include <cstdint>
#include <optional>
#include <string>
#include <vector>

View File

@ -5,7 +5,6 @@
#ifndef BITCOIN_UTIL_ENUMERATE_H
#define BITCOIN_UTIL_ENUMERATE_H
#include <tuple>
#include <iterator>
/**

View File

@ -6,6 +6,7 @@
#define BITCOIN_UTIL_OVERFLOW_H
#include <limits>
#include <optional>
#include <type_traits>
template <class T>

View File

@ -35,6 +35,7 @@
#endif // __linux__
#include <algorithm>
#include <atomic>
#include <cassert>
#include <fcntl.h>
#include <sched.h>

View File

@ -62,6 +62,7 @@
#include <statsd_client.h>
#include <deque>
#include <optional>
#include <string>

View File

@ -13,7 +13,6 @@
#include <util/system.h>
#include <wallet/db.h>
#include <atomic>
#include <map>
#include <memory>
#include <string>

View File

@ -46,6 +46,7 @@
#include <univalue.h>
#include <optional>
using interfaces::FoundBlock;

View File

@ -18,6 +18,8 @@
#include <boost/signals2/signal.hpp>
#include <optional>
// 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

View File

@ -31,13 +31,14 @@
#include <algorithm>
#include <atomic>
#include <deque>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <stdexcept>
#include <stdint.h>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>