Bitcoin Core  0.21.1
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules
Variables
net_processing.cpp File Reference
#include <net_processing.h>
#include <addrman.h>
#include <banman.h>
#include <blockencodings.h>
#include <blockfilter.h>
#include <chainparams.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 <streams.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>
Include dependency graph for net_processing.cpp:

Go to the source code of this file.

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 = std::chrono::minutes{15}
 How long to cache transactions in mapRelay for normal relay. More...
 
static constexpr
std::chrono::seconds 
UNCONDITIONAL_RELAY_DELAY = std::chrono::minutes{2}
 How long a transaction has to be in the mempool before it can unconditionally be relayed (even when not in mapRelay). More...
 
static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_BASE = 15 * 60 * 1000000
 Headers download timeout expressed in microseconds Timeout = base + per_header * (expected number of headers) 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
std::chrono::minutes 
PING_INTERVAL {2}
 Time between pings automatically sent out for latency probing and keepalive. More...
 
static const unsigned int MAX_LOCATOR_SZ = 101
 The maximum number of entries in a locator. More...
 
static const unsigned int MAX_INV_SZ = 50000
 The maximum number of entries in an 'inv' protocol message. More...
 
static constexpr int32_t MAX_PEER_TX_REQUEST_IN_FLIGHT = 100
 Maximum number of in-flight transaction requests from a peer. More...
 
static constexpr int32_t MAX_PEER_TX_ANNOUNCEMENTS = 5000
 Maximum number of transactions to consider for requesting, per peer. More...
 
static constexpr auto TXID_RELAY_DELAY = std::chrono::seconds{2}
 How long to delay requesting transactions via txids, if we have wtxid-relaying peers. More...
 
static constexpr auto NONPREF_PEER_TX_DELAY = std::chrono::seconds{2}
 How long to delay requesting transactions from non-preferred peers. More...
 
static constexpr auto OVERLOADED_PEER_TX_DELAY = std::chrono::seconds{2}
 How long to delay requesting transactions from overloaded peers (see MAX_PEER_TX_REQUEST_IN_FLIGHT). More...
 
static constexpr
std::chrono::microseconds 
GETDATA_TX_INTERVAL {std::chrono::seconds{60}}
 How long to wait (in microseconds) before downloading a transaction from an additional peer. More...
 
static const unsigned int MAX_GETDATA_SZ = 1000
 Limit to avoid sending big packets. More...
 
static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16
 Number of blocks that can be requested at any given time from a single peer. More...
 
static const unsigned int BLOCK_STALLING_TIMEOUT = 2
 Timeout in seconds during which a peer must stall block download progress before being disconnected. More...
 
static const unsigned int MAX_HEADERS_RESULTS = 2000
 Number of headers sent in one getheaders result. More...
 
static const int MAX_CMPCTBLOCK_DEPTH = 5
 Maximum depth of blocks we're willing to serve as compact blocks to peers when requested. More...
 
static const int MAX_BLOCKTXN_DEPTH = 10
 Maximum depth of blocks we're willing to respond to GETBLOCKTXN requests for. More...
 
static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024
 Size of the "block download window": how far ahead of our current height do we fetch? Larger windows tolerate larger download speed differences between peer, but increase the potential degree of disordering of blocks on disk (which make reindexing and pruning harder). More...
 
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 1000000
 Block download timeout base, expressed in millionths of the block interval (i.e. More...
 
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 500000
 Additional block download timeout per parallel downloading peer (i.e. More...
 
static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8
 Maximum number of headers to announce when relaying blocks with headers message. More...
 
static const int MAX_UNCONNECTING_HEADERS = 10
 Maximum number of unconnecting headers announcements before DoS score. More...
 
static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288
 Minimum blocks required to signal NODE_NETWORK_LIMITED. More...
 
static constexpr std::chrono::hours AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL {24}
 Average delay between local address broadcasts. More...
 
static constexpr
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_PER_SECOND = 7
 Maximum rate of inventory items to send per second. More...
 
static constexpr unsigned int INVENTORY_BROADCAST_MAX = INVENTORY_BROADCAST_PER_SECOND * INVENTORY_BROADCAST_INTERVAL
 Maximum number of inventory items to send per transmission. More...
 
static constexpr unsigned int INVENTORY_MAX_RECENT_RELAY = 3500
 The number of most recently announced transactions a peer can request. More...
 

Variable Documentation

constexpr std::chrono::seconds AVG_ADDRESS_BROADCAST_INTERVAL {30}
static

Average delay between peer address broadcasts.

Definition at line 123 of file net_processing.cpp.

constexpr std::chrono::hours AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL {24}
static

Average delay between local address broadcasts.

Definition at line 121 of file net_processing.cpp.

const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 1000000
static

Block download timeout base, expressed in millionths of the block interval (i.e.

10 min)

Definition at line 111 of file net_processing.cpp.

const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 500000
static

Additional block download timeout per parallel downloading peer (i.e.

5 min)

Definition at line 113 of file net_processing.cpp.

const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024
static

Size of the "block download window": how far ahead of our current height do we fetch? Larger windows tolerate larger download speed differences between peer, but increase the potential degree of disordering of blocks on disk (which make reindexing and pruning harder).

We'll probably want to make this a per-peer adaptive value at some point.

Definition at line 109 of file net_processing.cpp.

const unsigned int BLOCK_STALLING_TIMEOUT = 2
static

Timeout in seconds during which a peer must stall block download progress before being disconnected.

Definition at line 96 of file net_processing.cpp.

constexpr int64_t CHAIN_SYNC_TIMEOUT = 20 * 60
static

Timeout for (unprotected) outbound peers to sync to our chainwork, in seconds.

Definition at line 54 of file net_processing.cpp.

constexpr int64_t EXTRA_PEER_CHECK_INTERVAL = 45
static

How frequently to check for extra outbound peers and disconnect, in seconds.

Definition at line 58 of file net_processing.cpp.

constexpr std::chrono::microseconds GETDATA_TX_INTERVAL {std::chrono::seconds{60}}
static

How long to wait (in microseconds) before downloading a transaction from an additional peer.

Definition at line 90 of file net_processing.cpp.

constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_BASE = 15 * 60 * 1000000
static

Headers download timeout expressed in microseconds Timeout = base + per_header * (expected number of headers)

Definition at line 47 of file net_processing.cpp.

constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER = 1000
static

Definition at line 48 of file net_processing.cpp.

constexpr int HISTORICAL_BLOCK_AGE = 7 * 24 * 60 * 60
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 68 of file net_processing.cpp.

const unsigned int INVENTORY_BROADCAST_INTERVAL = 5
static

Average delay between trickled inventory transmissions in seconds.

Blocks and peers with noban permission bypass this, outbound peers get half this delay.

Definition at line 126 of file net_processing.cpp.

constexpr unsigned int INVENTORY_BROADCAST_MAX = INVENTORY_BROADCAST_PER_SECOND * INVENTORY_BROADCAST_INTERVAL
static

Maximum number of inventory items to send per transmission.

Definition at line 131 of file net_processing.cpp.

constexpr unsigned int INVENTORY_BROADCAST_PER_SECOND = 7
static

Maximum rate of inventory items to send per second.

Limits the impact of low-fee transaction floods.

Definition at line 129 of file net_processing.cpp.

constexpr unsigned int INVENTORY_MAX_RECENT_RELAY = 3500
static

The number of most recently announced transactions a peer can request.

Definition at line 133 of file net_processing.cpp.

const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16
static

Number of blocks that can be requested at any given time from a single peer.

Definition at line 94 of file net_processing.cpp.

const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8
static

Maximum number of headers to announce when relaying blocks with headers message.

Definition at line 115 of file net_processing.cpp.

const int MAX_BLOCKTXN_DEPTH = 10
static

Maximum depth of blocks we're willing to respond to GETBLOCKTXN requests for.

Definition at line 104 of file net_processing.cpp.

const int MAX_CMPCTBLOCK_DEPTH = 5
static

Maximum depth of blocks we're willing to serve as compact blocks to peers when requested.

For older blocks, a regular BLOCK response will be sent.

Definition at line 102 of file net_processing.cpp.

const unsigned int MAX_GETDATA_SZ = 1000
static

Limit to avoid sending big packets.

Not used in processing incoming GETDATA for compatibility

Definition at line 92 of file net_processing.cpp.

const unsigned int MAX_HEADERS_RESULTS = 2000
static

Number of headers sent in one getheaders result.

We rely on the assumption that if a peer sends less than this number, we reached its tip. Changing this value is a protocol upgrade.

Definition at line 99 of file net_processing.cpp.

const unsigned int MAX_INV_SZ = 50000
static

The maximum number of entries in an 'inv' protocol message.

Definition at line 74 of file net_processing.cpp.

const unsigned int MAX_LOCATOR_SZ = 101
static

The maximum number of entries in a locator.

Definition at line 72 of file net_processing.cpp.

constexpr int32_t MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT = 4
static

Protect at least this many outbound peers from disconnection due to slow/ behind headers chain.

Definition at line 52 of file net_processing.cpp.

constexpr int32_t MAX_PEER_TX_ANNOUNCEMENTS = 5000
static

Maximum number of transactions to consider for requesting, per peer.

It provides a reasonable DoS limit to per-peer memory usage spent on announcements, while covering peers continuously sending INVs at the maximum rate (by our own policy, see INVENTORY_BROADCAST_PER_SECOND) for several minutes, while not receiving the actual transaction (from any peer) in response to requests for them.

Definition at line 82 of file net_processing.cpp.

constexpr int32_t MAX_PEER_TX_REQUEST_IN_FLIGHT = 100
static

Maximum number of in-flight transaction requests from a peer.

It is not a hard limit, but the threshold at which point the OVERLOADED_PEER_TX_DELAY kicks in.

Definition at line 77 of file net_processing.cpp.

const int MAX_UNCONNECTING_HEADERS = 10
static

Maximum number of unconnecting headers announcements before DoS score.

Definition at line 117 of file net_processing.cpp.

constexpr int64_t MINIMUM_CONNECT_TIME = 30
static

Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict, in seconds.

Definition at line 60 of file net_processing.cpp.

const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288
static

Minimum blocks required to signal NODE_NETWORK_LIMITED.

Definition at line 119 of file net_processing.cpp.

constexpr auto NONPREF_PEER_TX_DELAY = std::chrono::seconds{2}
static

How long to delay requesting transactions from non-preferred peers.

Definition at line 86 of file net_processing.cpp.

constexpr int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60
static

Minimum time between orphan transactions expire time checks in seconds.

Definition at line 40 of file net_processing.cpp.

constexpr int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60
static

Expiration time for orphan transactions in seconds.

Definition at line 38 of file net_processing.cpp.

constexpr auto OVERLOADED_PEER_TX_DELAY = std::chrono::seconds{2}
static

How long to delay requesting transactions from overloaded peers (see MAX_PEER_TX_REQUEST_IN_FLIGHT).

Definition at line 88 of file net_processing.cpp.

constexpr std::chrono::minutes PING_INTERVAL {2}
static

Time between pings automatically sent out for latency probing and keepalive.

Definition at line 70 of file net_processing.cpp.

constexpr uint64_t RANDOMIZER_ID_ADDRESS_RELAY = 0x3cac0035b5866b90ULL
static

SHA256("main address relay")[0:8].

Definition at line 62 of file net_processing.cpp.

constexpr std::chrono::seconds RELAY_TX_CACHE_TIME = std::chrono::minutes{15}
static

How long to cache transactions in mapRelay for normal relay.

Definition at line 42 of file net_processing.cpp.

constexpr int64_t STALE_CHECK_INTERVAL = 10 * 60
static

How frequently to check for stale tips, in seconds.

Definition at line 56 of file net_processing.cpp.

constexpr int STALE_RELAY_AGE_LIMIT = 30 * 24 * 60 * 60
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 65 of file net_processing.cpp.

constexpr auto TXID_RELAY_DELAY = std::chrono::seconds{2}
static

How long to delay requesting transactions via txids, if we have wtxid-relaying peers.

Definition at line 84 of file net_processing.cpp.

constexpr std::chrono::seconds UNCONDITIONAL_RELAY_DELAY = std::chrono::minutes{2}
static

How long a transaction has to be in the mempool before it can unconditionally be relayed (even when not in mapRelay).

Definition at line 44 of file net_processing.cpp.