![]() |
Bitcoin ABC
0.22.12
P2P Digital Currency
|
#include <net_processing.h>
#include <addrman.h>
#include <avalanche/processor.h>
#include <avalanche/proof.h>
#include <avalanche/validation.h>
#include <banman.h>
#include <blockdb.h>
#include <blockencodings.h>
#include <blockfilter.h>
#include <blockvalidity.h>
#include <chain.h>
#include <chainparams.h>
#include <config.h>
#include <consensus/validation.h>
#include <hash.h>
#include <index/blockfilterindex.h>
#include <merkleblock.h>
#include <netbase.h>
#include <netmessagemaker.h>
#include <policy/fees.h>
#include <policy/policy.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <random.h>
#include <reverse_iterator.h>
#include <scheduler.h>
#include <tinyformat.h>
#include <txmempool.h>
#include <util/check.h>
#include <util/strencodings.h>
#include <util/system.h>
#include <validation.h>
#include <memory>
#include <typeinfo>
Go to the source code of this file.
Classes | |
struct | COrphanTx |
class | CNetProcessingCleanup |
Functions | |
std::map< TxId, COrphanTx > mapOrphanTransactions | GUARDED_BY (g_cs_orphans) |
void | EraseOrphansFor (NodeId peer) |
void | UpdateLastBlockAnnounceTime (NodeId node, int64_t time_in_seconds) |
bool | GetNodeStateStats (NodeId nodeid, CNodeStateStats &stats) |
Get statistics from node state. More... | |
static void | AddToCompactExtraTransactions (const CTransactionRef &tx) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans) |
bool | AddOrphanTx (const CTransactionRef &tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans) |
static int | EraseOrphanTx (const TxId id) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans) |
unsigned int | LimitOrphanTxSize (unsigned int nMaxOrphans) |
void | Misbehaving (const NodeId pnode, const int howmuch, const std::string &message) |
Increment peer's misbehavior score. More... | |
static void | Misbehaving (const CNode &node, int howmuch, const std::string &message) |
static bool | TxRelayMayResultInDisconnect (const TxValidationState &state) |
Returns true if the given validation state result may result in a peer banning/disconnecting us. More... | |
static bool | MaybePunishNodeForBlock (NodeId nodeid, const BlockValidationState &state, bool via_compact_block, const std::string &message="") |
Potentially ban a node based on the contents of a BlockValidationState object. More... | |
static bool | MaybePunishNodeForTx (NodeId nodeid, const TxValidationState &state, const std::string &message="") |
Potentially ban a node based on the contents of a TxValidationState object. More... | |
static bool | BlockRequestAllowed (const CBlockIndex *pindex, const Consensus::Params &consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
static std::shared_ptr< const CBlock > most_recent_block | GUARDED_BY (cs_most_recent_block) |
static bool | AlreadyHave (const CInv &inv, const CTxMemPool &mempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
void | RelayTransaction (const TxId &txid, const CConnman &connman) |
Relay transaction to every node. More... | |
static void | RelayAddress (const CAddress &addr, bool fReachable, const CConnman &connman) |
static void | ProcessGetBlockData (const Config &config, CNode &pfrom, const CInv &inv, CConnman &connman, const std::atomic< bool > &interruptMsgProc) |
static void | ProcessGetData (const Config &config, CNode &pfrom, CConnman &connman, const CTxMemPool &mempool, const std::atomic< bool > &interruptMsgProc) LOCKS_EXCLUDED(cs_main) |
static void | SendBlockTransactions (const CBlock &block, const BlockTransactionsRequest &req, CNode &pfrom, CConnman &connman) |
static void | ProcessHeadersMessage (const Config &config, CNode &pfrom, CConnman &connman, CTxMemPool &mempool, ChainstateManager &chainman, const std::vector< CBlockHeader > &headers, bool via_compact_block) |
static void | ProcessOrphanTx (const Config &config, CConnman &connman, CTxMemPool &mempool, std::set< TxId > &orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(cs_main |
AssertLockHeld (g_cs_orphans) | |
while (!done &&!orphan_work_set.empty()) | |
static bool | PrepareBlockFilterRequest (CNode &peer, const CChainParams &chain_params, BlockFilterType filter_type, uint32_t start_height, const BlockHash &stop_hash, uint32_t max_height_diff, const CBlockIndex *&stop_index, BlockFilterIndex *&filter_index) |
Validation logic for compact filters request handling. More... | |
static void | ProcessGetCFilters (CNode &peer, CDataStream &vRecv, const CChainParams &chain_params, CConnman &connman) |
Handle a cfilters request. More... | |
static void | ProcessGetCFHeaders (CNode &peer, CDataStream &vRecv, const CChainParams &chain_params, CConnman &connman) |
Handle a cfheaders request. More... | |
static void | ProcessGetCFCheckPt (CNode &peer, CDataStream &vRecv, const CChainParams &chain_params, CConnman &connman) |
Handle a getcfcheckpt request. More... | |
Variables | |
static constexpr int64_t | ORPHAN_TX_EXPIRE_TIME = 20 * 60 |
Expiration time for orphan transactions in seconds. More... | |
static constexpr int64_t | ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60 |
Minimum time between orphan transactions expire time checks in seconds. More... | |
static constexpr std::chrono::seconds | RELAY_TX_CACHE_TIME {15 * 60} |
How long to cache transactions in mapRelay for normal relay. More... | |
static constexpr int64_t | HEADERS_DOWNLOAD_TIMEOUT_BASE = 15 * 60 * 1000000 |
Headers download timeout expressed in microseconds. More... | |
static constexpr int64_t | HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER = 1000 |
static constexpr int32_t | MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT = 4 |
Protect at least this many outbound peers from disconnection due to slow/behind headers chain. More... | |
static constexpr int64_t | CHAIN_SYNC_TIMEOUT = 20 * 60 |
Timeout for (unprotected) outbound peers to sync to our chainwork, in seconds. More... | |
static constexpr int64_t | STALE_CHECK_INTERVAL = 10 * 60 |
How frequently to check for stale tips, in seconds. More... | |
static constexpr int64_t | EXTRA_PEER_CHECK_INTERVAL = 45 |
How frequently to check for extra outbound peers and disconnect, in seconds. More... | |
static constexpr int64_t | MINIMUM_CONNECT_TIME = 30 |
Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict, in seconds. More... | |
static constexpr uint64_t | RANDOMIZER_ID_ADDRESS_RELAY = 0x3cac0035b5866b90ULL |
SHA256("main address relay")[0:8]. More... | |
static constexpr int | STALE_RELAY_AGE_LIMIT = 30 * 24 * 60 * 60 |
Age after which a stale block will no longer be served if requested as protection against fingerprinting. More... | |
static constexpr int | HISTORICAL_BLOCK_AGE = 7 * 24 * 60 * 60 |
Age after which a block is considered historical for purposes of rate limiting block relay. More... | |
static constexpr int32_t | MAX_PEER_TX_IN_FLIGHT = 100 |
Maximum number of in-flight transactions from a peer. More... | |
static constexpr int32_t | MAX_PEER_TX_ANNOUNCEMENTS = 2 * MAX_INV_SZ |
Maximum number of announced transactions from a peer. More... | |
static constexpr std::chrono::microseconds | INBOUND_PEER_TX_DELAY |
How many microseconds to delay requesting transactions from inbound peers. More... | |
static constexpr std::chrono::microseconds | GETDATA_TX_INTERVAL |
How long to wait (in microseconds) before downloading a transaction from an additional peer. More... | |
static constexpr std::chrono::microseconds | MAX_GETDATA_RANDOM_DELAY |
Maximum delay (in microseconds) for transaction requests to avoid biasing some peers over others. More... | |
static constexpr std::chrono::microseconds | TX_EXPIRY_INTERVAL |
How long to wait (in microseconds) before expiring an in-flight getdata request to a peer. More... | |
static const unsigned int | MAX_GETDATA_SZ = 1000 |
Limit to avoid sending big packets. More... | |
static constexpr uint32_t | MAX_NON_STANDARD_ORPHAN_PER_NODE = 5 |
How many non standard orphan do we consider from a node before ignoring it. More... | |
RecursiveMutex | g_cs_orphans |
static constexpr std::chrono::hours | AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL {24} |
Average delay between local address broadcasts. More... | |
static const std::chrono::seconds | AVG_ADDRESS_BROADCAST_INTERVAL {30} |
Average delay between peer address broadcasts. More... | |
static const unsigned int | INVENTORY_BROADCAST_INTERVAL = 5 |
Average delay between trickled inventory transmissions in seconds. More... | |
static constexpr unsigned int | INVENTORY_BROADCAST_MAX_PER_MB |
Maximum number of inventory items to send per transmission. More... | |
static constexpr unsigned int | AVG_FEEFILTER_BROADCAST_INTERVAL = 10 * 60 |
Average delay between feefilter broadcasts in seconds. More... | |
static constexpr unsigned int | MAX_FEEFILTER_CHANGE_DELAY = 5 * 60 |
Maximum feefilter broadcast delay after significant change. More... | |
static constexpr uint32_t | MAX_GETCFILTERS_SIZE = 1000 |
Maximum number of compact filters that may be requested with one getcfilters. More... | |
static constexpr uint32_t | MAX_GETCFHEADERS_SIZE = 2000 |
Maximum number of cf hashes that may be requested with one getcfheaders. More... | |
static RecursiveMutex | cs_most_recent_block |
std::unordered_map< NodeId, uint32_t > | rejectCountPerNode |
bool | done = false |
static CNetProcessingCleanup | instance_of_cnetprocessingcleanup |
bool AddOrphanTx | ( | const CTransactionRef & | tx, |
NodeId | peer | ||
) |
Definition at line 1108 of file net_processing.cpp.
|
static |
Definition at line 1091 of file net_processing.cpp.
|
static |
Definition at line 1649 of file net_processing.cpp.
AssertLockHeld | ( | g_cs_orphans | ) |
|
static |
Definition at line 1389 of file net_processing.cpp.
void EraseOrphansFor | ( | NodeId | peer | ) |
Definition at line 1177 of file net_processing.cpp.
|
static |
bool GetNodeStateStats | ( | NodeId | nodeid, |
CNodeStateStats & | stats | ||
) |
Get statistics from node state.
Definition at line 1056 of file net_processing.cpp.
std::map<TxId, COrphanTx> mapOrphanTransactions GUARDED_BY | ( | g_cs_orphans | ) |
|
static |
unsigned int LimitOrphanTxSize | ( | unsigned int | nMaxOrphans | ) |
Definition at line 1194 of file net_processing.cpp.
|
static |
Potentially ban a node based on the contents of a BlockValidationState object.
[in] | via_compact_block | this bool is passed in because net_processing should punish peers differently depending on whether the data was provided in a compact block message or not. If the compact block had a valid header, but contained invalid txs, the peer should not be punished. See BIP 152. |
Definition at line 1291 of file net_processing.cpp.
|
static |
Potentially ban a node based on the contents of a TxValidationState object.
Changes here may need to be reflected in TxRelayMayResultInDisconnect().
Definition at line 1356 of file net_processing.cpp.
void Misbehaving | ( | const NodeId | pnode, |
const int | howmuch, | ||
const std::string & | message | ||
) |
Increment peer's misbehavior score.
If the new value >= DISCOURAGEMENT_THRESHOLD, mark the node to be discouraged, meaning the peer might be disconnected and added to the discouragement filter.
Definition at line 1238 of file net_processing.cpp.
|
static |
|
static |
Validation logic for compact filters request handling.
May disconnect from the peer in the case of a bad request.
[in] | peer | The peer that we received the request from |
[in] | chain_params | Chain parameters |
[in] | filter_type | The filter type the request is for. Must be basic filters. |
[in] | start_height | The start height for the request |
[in] | stop_hash | The stop_hash for the request |
[in] | max_height_diff | The maximum number of items permitted to request, as specified in BIP 157 |
[out] | stop_index | The CBlockIndex for the stop_hash block, if the request can be serviced. |
[out] | filter_index | The filter index, if the request can be serviced. |
Definition at line 2354 of file net_processing.cpp.
|
static |
Definition at line 1737 of file net_processing.cpp.
|
static |
Handle a getcfcheckpt request.
May disconnect from the peer in the case of a bad request.
[in] | peer | The peer that we received the request from |
[in] | vRecv | The raw message received |
[in] | chain_params | Chain parameters |
[in] | connman | Pointer to the connection manager |
Definition at line 2532 of file net_processing.cpp.
|
static |
Handle a cfheaders request.
May disconnect from the peer in the case of a bad request.
[in] | peer | The peer that we received the request from |
[in] | vRecv | The raw message received |
[in] | chain_params | Chain parameters |
[in] | connman | Pointer to the connection manager |
Definition at line 2470 of file net_processing.cpp.
|
static |
Handle a cfilters request.
May disconnect from the peer in the case of a bad request.
[in] | peer | The peer that we received the request from |
[in] | vRecv | The raw message received |
[in] | chain_params | Chain parameters |
[in] | connman | Pointer to the connection manager |
Definition at line 2423 of file net_processing.cpp.
|
static |
Definition at line 1913 of file net_processing.cpp.
|
static |
Definition at line 2031 of file net_processing.cpp.
|
static |
|
static |
Definition at line 1694 of file net_processing.cpp.
Relay transaction to every node.
Definition at line 1689 of file net_processing.cpp.
|
inlinestatic |
Definition at line 2012 of file net_processing.cpp.
|
static |
Returns true if the given validation state result may result in a peer banning/disconnecting us.
We use this to determine which unaccepted transactions from a whitelisted peer that we can safely relay.
Definition at line 1277 of file net_processing.cpp.
void UpdateLastBlockAnnounceTime | ( | NodeId | node, |
int64_t | time_in_seconds | ||
) |
Definition at line 979 of file net_processing.cpp.
while | ( | !done &&!orphan_work_set. | empty() | ) |
|
static |
Average delay between peer address broadcasts.
Definition at line 145 of file net_processing.cpp.
|
static |
Average delay between feefilter broadcasts in seconds.
Definition at line 161 of file net_processing.cpp.
|
static |
Average delay between local address broadcasts.
Definition at line 141 of file net_processing.cpp.
|
static |
Timeout for (unprotected) outbound peers to sync to our chainwork, in seconds.
Definition at line 67 of file net_processing.cpp.
|
static |
Definition at line 1508 of file net_processing.cpp.
bool done = false |
Definition at line 2270 of file net_processing.cpp.
|
static |
How frequently to check for extra outbound peers and disconnect, in seconds.
Definition at line 74 of file net_processing.cpp.
static void g_cs_orphans |
Definition at line 133 of file net_processing.cpp.
|
static |
How long to wait (in microseconds) before downloading a transaction from an additional peer.
Definition at line 99 of file net_processing.cpp.
|
static |
Headers download timeout expressed in microseconds.
Timeout = base + per_header * (expected number of headers)
Definition at line 54 of file net_processing.cpp.
|
static |
Definition at line 56 of file net_processing.cpp.
|
static |
Age after which a block is considered historical for purposes of rate limiting block relay.
Set to one week, denominated in seconds.
Definition at line 87 of file net_processing.cpp.
|
static |
How many microseconds to delay requesting transactions from inbound peers.
Definition at line 93 of file net_processing.cpp.
|
static |
Definition at line 5451 of file net_processing.cpp.
|
static |
Average delay between trickled inventory transmissions in seconds.
Blocks and whitelisted receivers bypass this, outbound peers get half this delay.
Definition at line 151 of file net_processing.cpp.
|
static |
Maximum number of inventory items to send per transmission.
Limits the impact of low-fee transaction floods.
Definition at line 156 of file net_processing.cpp.
|
static |
Maximum feefilter broadcast delay after significant change.
Definition at line 165 of file net_processing.cpp.
|
static |
Maximum number of cf hashes that may be requested with one getcfheaders.
See BIP 157.
Definition at line 175 of file net_processing.cpp.
|
static |
Maximum number of compact filters that may be requested with one getcfilters.
See BIP 157.
Definition at line 170 of file net_processing.cpp.
|
static |
Maximum delay (in microseconds) for transaction requests to avoid biasing some peers over others.
Definition at line 105 of file net_processing.cpp.
|
static |
Limit to avoid sending big packets.
Not used in processing incoming GETDATA for compatibility.
Definition at line 120 of file net_processing.cpp.
|
static |
How many non standard orphan do we consider from a node before ignoring it.
Definition at line 123 of file net_processing.cpp.
|
static |
Protect at least this many outbound peers from disconnection due to slow/behind headers chain.
Definition at line 61 of file net_processing.cpp.
|
static |
Maximum number of announced transactions from a peer.
Definition at line 91 of file net_processing.cpp.
|
static |
Maximum number of in-flight transactions from a peer.
Definition at line 89 of file net_processing.cpp.
|
static |
Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict, in seconds.
Definition at line 79 of file net_processing.cpp.
|
static |
Minimum time between orphan transactions expire time checks in seconds.
Definition at line 46 of file net_processing.cpp.
|
static |
Expiration time for orphan transactions in seconds.
Definition at line 44 of file net_processing.cpp.
|
static |
SHA256("main address relay")[0:8].
Definition at line 81 of file net_processing.cpp.
std::unordered_map<NodeId, uint32_t> rejectCountPerNode |
Definition at line 2269 of file net_processing.cpp.
|
static |
How long to cache transactions in mapRelay for normal relay.
Definition at line 48 of file net_processing.cpp.
|
static |
How frequently to check for stale tips, in seconds.
Definition at line 70 of file net_processing.cpp.
|
static |
Age after which a stale block will no longer be served if requested as protection against fingerprinting.
Set to one month, denominated in seconds.
Definition at line 84 of file net_processing.cpp.
|
static |
How long to wait (in microseconds) before expiring an in-flight getdata request to a peer.
Definition at line 111 of file net_processing.cpp.