2017-08-09 02:19:06 +02:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2023-04-25 13:51:26 +02:00
|
|
|
// Copyright (c) 2009-2020 The Bitcoin Core developers
|
2017-08-09 02:19:06 +02:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_NET_PROCESSING_H
|
|
|
|
#define BITCOIN_NET_PROCESSING_H
|
|
|
|
|
2022-04-17 12:52:51 +02:00
|
|
|
#include <net.h>
|
2018-09-27 17:18:12 +02:00
|
|
|
#include <sync.h>
|
2022-04-17 12:52:51 +02:00
|
|
|
#include <validationinterface.h>
|
|
|
|
|
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
2023-09-07 16:07:02 +02:00
|
|
|
#include <atomic>
|
|
|
|
|
2023-02-16 07:34:06 +01:00
|
|
|
class CAddrMan;
|
2022-04-17 12:52:51 +02:00
|
|
|
class CTxMemPool;
|
2022-05-05 20:07:00 +02:00
|
|
|
class ChainstateManager;
|
2022-11-07 19:09:44 +01:00
|
|
|
struct LLMQContext;
|
2022-09-22 13:14:48 +02:00
|
|
|
|
2023-04-25 13:51:26 +02:00
|
|
|
extern RecursiveMutex cs_main;
|
|
|
|
extern RecursiveMutex g_cs_orphans;
|
2017-08-09 02:19:06 +02:00
|
|
|
|
2019-09-30 15:34:13 +02:00
|
|
|
/** Default for -maxorphantxsize, maximum size in megabytes the orphan map can grow before entries are removed */
|
|
|
|
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS_SIZE = 10; // this allows around 100 TXs of max size (and many more of normal size)
|
2019-09-25 13:03:45 +02:00
|
|
|
/** Default number of orphan+recently-replaced txn to keep around for block reconstruction */
|
|
|
|
static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
|
2021-07-18 06:20:16 +02:00
|
|
|
static const bool DEFAULT_PEERBLOOMFILTERS = true;
|
2021-09-19 06:31:43 +02:00
|
|
|
static const bool DEFAULT_PEERBLOCKFILTERS = false;
|
2020-04-19 13:04:31 +02:00
|
|
|
|
2023-04-27 09:46:47 +02:00
|
|
|
struct CNodeStateStats {
|
|
|
|
int m_misbehavior_score = 0;
|
|
|
|
int nSyncHeight = -1;
|
|
|
|
int nCommonHeight = -1;
|
|
|
|
std::vector<int> vHeightInFlight;
|
|
|
|
};
|
|
|
|
|
2023-04-28 07:23:04 +02:00
|
|
|
class PeerManager : public CValidationInterface, public NetEventsInterface
|
|
|
|
{
|
2017-08-09 02:19:06 +02:00
|
|
|
public:
|
2023-04-28 07:23:04 +02:00
|
|
|
static std::unique_ptr<PeerManager> make(const CChainParams& chainparams, CConnman& connman, CAddrMan& addrman,
|
|
|
|
BanMan* banman, CScheduler &scheduler, ChainstateManager& chainman,
|
2023-06-04 22:26:23 +02:00
|
|
|
CTxMemPool& pool, const std::unique_ptr<LLMQContext>& llmq_ctx, bool ignore_incoming_txs);
|
2023-04-28 07:23:04 +02:00
|
|
|
virtual ~PeerManager() { }
|
2017-11-02 20:13:17 +01:00
|
|
|
|
2023-04-27 09:46:47 +02:00
|
|
|
/** Get statistics from node state */
|
2023-04-28 07:23:04 +02:00
|
|
|
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) = 0;
|
2023-04-28 08:36:19 +02:00
|
|
|
|
2023-04-27 09:21:41 +02:00
|
|
|
/** Whether this node ignores txs received over p2p. */
|
2023-04-28 07:23:04 +02:00
|
|
|
virtual bool IgnoresIncomingTxs() = 0;
|
2023-04-27 09:46:47 +02:00
|
|
|
|
2023-04-28 07:23:04 +02:00
|
|
|
/** Set the best height */
|
|
|
|
virtual void SetBestHeight(int height) = 0;
|
2023-04-27 09:46:47 +02:00
|
|
|
|
2023-04-28 07:17:42 +02:00
|
|
|
/**
|
2023-04-28 07:23:04 +02:00
|
|
|
* Increment peer's misbehavior score. If the new value surpasses banscore (specified on startup or by default), mark node to be discouraged, meaning the peer might be disconnected & added to the discouragement filter.
|
2023-04-28 07:17:42 +02:00
|
|
|
*/
|
2023-04-28 07:23:04 +02:00
|
|
|
virtual void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message = "") = 0;
|
2023-04-28 07:17:42 +02:00
|
|
|
|
|
|
|
/**
|
2023-04-28 07:23:04 +02:00
|
|
|
* Evict extra outbound peers. If we think our tip may be stale, connect to an extra outbound.
|
|
|
|
* Public for unit testing.
|
2023-04-28 07:17:42 +02:00
|
|
|
*/
|
2023-04-28 07:23:04 +02:00
|
|
|
virtual void CheckForStaleTipAndEvictPeers(const Consensus::Params &consensusParams) = 0;
|
2023-04-28 07:17:42 +02:00
|
|
|
|
2023-04-28 07:23:04 +02:00
|
|
|
/** Process a single message from a peer. Public for fuzz testing */
|
|
|
|
virtual void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
|
|
|
|
int64_t nTimeReceived, const std::atomic<bool>& interruptMsgProc) = 0;
|
2023-04-27 09:21:41 +02:00
|
|
|
|
2023-04-28 07:23:04 +02:00
|
|
|
virtual bool IsBanned(NodeId pnode) = 0;
|
2017-08-09 02:19:06 +02:00
|
|
|
};
|
|
|
|
|
2021-07-10 16:46:33 +02:00
|
|
|
void EraseObjectRequest(NodeId nodeId, const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
|
|
|
void RequestObject(NodeId nodeId, const CInv& inv, std::chrono::microseconds current_time, bool fForce=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
|
|
|
size_t GetRequestedObjectCount(NodeId nodeId) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
2020-04-06 13:25:38 +02:00
|
|
|
|
2021-12-12 13:27:10 +01:00
|
|
|
/** Relay transaction to every node */
|
|
|
|
void RelayTransaction(const uint256&, const CConnman& connman);
|
|
|
|
|
2017-08-09 02:19:06 +02:00
|
|
|
#endif // BITCOIN_NET_PROCESSING_H
|