Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
Classes | Functions | Variables
net_processing.cpp File Reference
#include <net_processing.h>
#include <addrman.h>
#include <avalanche/compactproofs.h>
#include <avalanche/peermanager.h>
#include <avalanche/processor.h>
#include <avalanche/proof.h>
#include <avalanche/stakecontender.h>
#include <avalanche/statistics.h>
#include <avalanche/validation.h>
#include <banman.h>
#include <blockencodings.h>
#include <blockfilter.h>
#include <blockvalidity.h>
#include <chain.h>
#include <chainparams.h>
#include <config.h>
#include <consensus/amount.h>
#include <consensus/validation.h>
#include <hash.h>
#include <headerssync.h>
#include <index/blockfilterindex.h>
#include <invrequest.h>
#include <kernel/mempool_entry.h>
#include <merkleblock.h>
#include <netbase.h>
#include <netmessagemaker.h>
#include <node/blockstorage.h>
#include <policy/fees.h>
#include <policy/policy.h>
#include <policy/settings.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <random.h>
#include <reverse_iterator.h>
#include <scheduler.h>
#include <streams.h>
#include <timedata.h>
#include <tinyformat.h>
#include <txmempool.h>
#include <txorphanage.h>
#include <util/check.h>
#include <util/strencodings.h>
#include <util/trace.h>
#include <validation.h>
#include <algorithm>
#include <atomic>
#include <chrono>
#include <functional>
#include <future>
#include <memory>
#include <numeric>
#include <typeinfo>

Go to the source code of this file.

Classes

struct  DataRequestParameters
 

Functions

template<class InvId >
static bool TooManyAnnouncements (const CNode &node, const InvRequestTracker< InvId > &requestTracker, const DataRequestParameters &requestParams)
 
template<class InvId >
static std::chrono::microseconds ComputeRequestTime (const CNode &node, const InvRequestTracker< InvId > &requestTracker, const DataRequestParameters &requestParams, std::chrono::microseconds current_time, bool preferred)
 Compute the request time for this announcement, current time plus delays for:
 
bool IsAvalancheMessageType (const std::string &msg_type)
 
static uint32_t getAvalancheVoteForProof (const avalanche::Processor &avalanche, const avalanche::ProofId &id)
 Decide a response for an Avalanche poll about the given proof.
 

Variables

static constexpr auto RELAY_TX_CACHE_TIME = 15min
 How long to cache transactions in mapRelay for normal relay.
 
static constexpr auto UNCONDITIONAL_RELAY_DELAY = 2min
 How long a transaction has to be in the mempool before it can unconditionally be relayed (even when not in mapRelay).
 
static constexpr auto HEADERS_DOWNLOAD_TIMEOUT_BASE = 15min
 Headers download timeout.
 
static constexpr auto HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER = 1ms
 
static constexpr auto HEADERS_RESPONSE_TIME {2min}
 How long to wait for a peer to respond to a getheaders request.
 
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.
 
static constexpr auto CHAIN_SYNC_TIMEOUT {20min}
 Timeout for (unprotected) outbound peers to sync to our chainwork.
 
static constexpr auto STALE_CHECK_INTERVAL {10min}
 How frequently to check for stale tips.
 
static constexpr auto EXTRA_PEER_CHECK_INTERVAL {45s}
 How frequently to check for extra outbound peers and disconnect.
 
static constexpr auto MINIMUM_CONNECT_TIME {30s}
 Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict.
 
static constexpr uint64_t RANDOMIZER_ID_ADDRESS_RELAY = 0x3cac0035b5866b90ULL
 SHA256("main address relay")[0:8].
 
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.
 
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.
 
static constexpr auto PING_INTERVAL {2min}
 Time between pings automatically sent out for latency probing and keepalive.
 
static const unsigned int MAX_LOCATOR_SZ = 101
 The maximum number of entries in a locator.
 
static const unsigned int MAX_INV_SZ = 50000
 The maximum number of entries in an 'inv' protocol message.
 
static constexpr auto GETAVAADDR_INTERVAL {2min}
 Minimum time between 2 successives getavaaddr messages from the same peer.
 
static constexpr auto AVALANCHE_AVAPROOFS_TIMEOUT {2min}
 If no proof was requested from a compact proof message after this timeout expired, the proof radix tree can be cleaned up.
 
static constexpr DataRequestParameters TX_REQUEST_PARAMS
 
static constexpr DataRequestParameters PROOF_REQUEST_PARAMS
 
static const unsigned int MAX_GETDATA_SZ = 1000
 Limit to avoid sending big packets.
 
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.
 
static constexpr auto BLOCK_STALLING_TIMEOUT_DEFAULT {2s}
 Default time during which a peer must stall block download progress before being disconnected.
 
static constexpr auto BLOCK_STALLING_TIMEOUT_MAX {64s}
 Maximum timeout for stalling block download.
 
static const int MAX_CMPCTBLOCK_DEPTH = 5
 Maximum depth of blocks we're willing to serve as compact blocks to peers when requested.
 
static const int MAX_BLOCKTXN_DEPTH = 10
 Maximum depth of blocks we're willing to respond to GETBLOCKTXN requests for.
 
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).
 
static constexpr double BLOCK_DOWNLOAD_TIMEOUT_BASE = 1
 Block download timeout base, expressed in multiples of the block interval (i.e.
 
static constexpr double BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 0.5
 Additional block download timeout per parallel downloading peer (i.e.
 
static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8
 Maximum number of headers to announce when relaying blocks with headers message.
 
static const int MAX_NUM_UNCONNECTING_HEADERS_MSGS = 10
 Maximum number of unconnecting headers announcements before DoS score.
 
static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288
 Minimum blocks required to signal NODE_NETWORK_LIMITED.
 
static constexpr auto AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL {24h}
 Average delay between local address broadcasts.
 
static constexpr auto AVG_ADDRESS_BROADCAST_INTERVAL {30s}
 Average delay between peer address broadcasts.
 
static constexpr auto ROTATE_ADDR_RELAY_DEST_INTERVAL {24h}
 Delay between rotating the peers we relay a particular address to.
 
static constexpr auto INBOUND_INVENTORY_BROADCAST_INTERVAL {5s}
 Average delay between trickled inventory transmissions for inbound peers.
 
static constexpr unsigned int INVENTORY_BROADCAST_PER_SECOND = 7
 Maximum rate of inventory items to send per second.
 
static constexpr unsigned int INVENTORY_BROADCAST_MAX_PER_MB
 Maximum number of inventory items to send per transmission.
 
static constexpr unsigned int INVENTORY_MAX_RECENT_RELAY = 3500
 The number of most recently announced transactions a peer can request.
 
static constexpr auto AVG_FEEFILTER_BROADCAST_INTERVAL {10min}
 Verify that INVENTORY_MAX_RECENT_RELAY is enough to cache everything typically relayed before unconditional relay from the mempool kicks in.
 
static constexpr auto MAX_FEEFILTER_CHANGE_DELAY {5min}
 Maximum feefilter broadcast delay after significant change.
 
static constexpr uint32_t MAX_GETCFILTERS_SIZE = 1000
 Maximum number of compact filters that may be requested with one getcfilters.
 
static constexpr uint32_t MAX_GETCFHEADERS_SIZE = 2000
 Maximum number of cf hashes that may be requested with one getcfheaders.
 
static constexpr size_t MAX_PCT_ADDR_TO_SEND = 23
 the maximum percentage of addresses from our addrman to return in response to a getaddr message.
 
static constexpr double MAX_ADDR_RATE_PER_SECOND {0.1}
 The maximum rate of address records we're willing to process on average.
 
static constexpr size_t MAX_ADDR_PROCESSING_TOKEN_BUCKET {MAX_ADDR_TO_SEND}
 The soft limit of the address processing token bucket (the regular MAX_ADDR_RATE_PER_SECOND based increments won't go above this, but the MAX_ADDR_TO_SEND increment following GETADDR is exempt from this limit).
 
static constexpr uint64_t CMPCTBLOCKS_VERSION {1}
 The compactblocks version we support.
 

Function Documentation

◆ ComputeRequestTime()

template<class InvId >
static std::chrono::microseconds ComputeRequestTime ( const CNode node,
const InvRequestTracker< InvId > &  requestTracker,
const DataRequestParameters requestParams,
std::chrono::microseconds  current_time,
bool  preferred 
)
static

Compute the request time for this announcement, current time plus delays for:

  • nonpref_peer_delay for announcements from non-preferred connections
  • overloaded_peer_delay for announcements from peers which have at least max_peer_request_in_flight requests in flight (and don't have NetPermissionFlags::Relay).

Definition at line 2088 of file net_processing.cpp.

Here is the call graph for this function:

◆ getAvalancheVoteForProof()

static uint32_t getAvalancheVoteForProof ( const avalanche::Processor avalanche,
const avalanche::ProofId id 
)
static

Decide a response for an Avalanche poll about the given proof.

Parameters
[in]idThe id of the proof being polled for
Returns
Our current vote for the proof

Definition at line 4691 of file net_processing.cpp.

Here is the call graph for this function:

◆ IsAvalancheMessageType()

bool IsAvalancheMessageType ( const std::string &  msg_type)

Definition at line 4599 of file net_processing.cpp.

Here is the call graph for this function:

◆ TooManyAnnouncements()

template<class InvId >
static bool TooManyAnnouncements ( const CNode node,
const InvRequestTracker< InvId > &  requestTracker,
const DataRequestParameters requestParams 
)
static

Definition at line 2070 of file net_processing.cpp.

Here is the call graph for this function:

Variable Documentation

◆ AVALANCHE_AVAPROOFS_TIMEOUT

constexpr auto AVALANCHE_AVAPROOFS_TIMEOUT {2min}
staticconstexpr

If no proof was requested from a compact proof message after this timeout expired, the proof radix tree can be cleaned up.

Definition at line 119 of file net_processing.cpp.

◆ AVG_ADDRESS_BROADCAST_INTERVAL

constexpr auto AVG_ADDRESS_BROADCAST_INTERVAL {30s}
staticconstexpr

Average delay between peer address broadcasts.

Definition at line 240 of file net_processing.cpp.

◆ AVG_FEEFILTER_BROADCAST_INTERVAL

constexpr auto AVG_FEEFILTER_BROADCAST_INTERVAL {10min}
staticconstexpr

Verify that INVENTORY_MAX_RECENT_RELAY is enough to cache everything typically relayed before unconditional relay from the mempool kicks in.

This is only a lower bound, and it should be larger to account for higher inv rate to outbound peers, and random variations in the broadcast mechanism. Average delay between feefilter broadcasts

Definition at line 273 of file net_processing.cpp.

◆ AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL

constexpr auto AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL {24h}
staticconstexpr

Average delay between local address broadcasts.

Definition at line 236 of file net_processing.cpp.

◆ BLOCK_DOWNLOAD_TIMEOUT_BASE

constexpr double BLOCK_DOWNLOAD_TIMEOUT_BASE = 1
staticconstexpr

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

10 min)

Definition at line 219 of file net_processing.cpp.

◆ BLOCK_DOWNLOAD_TIMEOUT_PER_PEER

constexpr double BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 0.5
staticconstexpr

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

5 min)

Definition at line 223 of file net_processing.cpp.

◆ BLOCK_DOWNLOAD_WINDOW

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 214 of file net_processing.cpp.

◆ BLOCK_STALLING_TIMEOUT_DEFAULT

constexpr auto BLOCK_STALLING_TIMEOUT_DEFAULT {2s}
staticconstexpr

Default time during which a peer must stall block download progress before being disconnected.

The actual timeout is increased temporarily if peers are disconnected for hitting the timeout

Definition at line 194 of file net_processing.cpp.

◆ BLOCK_STALLING_TIMEOUT_MAX

constexpr auto BLOCK_STALLING_TIMEOUT_MAX {64s}
staticconstexpr

Maximum timeout for stalling block download.

Definition at line 196 of file net_processing.cpp.

◆ CHAIN_SYNC_TIMEOUT

constexpr auto CHAIN_SYNC_TIMEOUT {20min}
staticconstexpr

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

Definition at line 82 of file net_processing.cpp.

◆ CMPCTBLOCKS_VERSION

constexpr uint64_t CMPCTBLOCKS_VERSION {1}
staticconstexpr

The compactblocks version we support.

See BIP 152.

Definition at line 305 of file net_processing.cpp.

◆ EXTRA_PEER_CHECK_INTERVAL

constexpr auto EXTRA_PEER_CHECK_INTERVAL {45s}
staticconstexpr

How frequently to check for extra outbound peers and disconnect.

Definition at line 86 of file net_processing.cpp.

◆ GETAVAADDR_INTERVAL

constexpr auto GETAVAADDR_INTERVAL {2min}
staticconstexpr

Minimum time between 2 successives getavaaddr messages from the same peer.

Definition at line 113 of file net_processing.cpp.

◆ HEADERS_DOWNLOAD_TIMEOUT_BASE

constexpr auto HEADERS_DOWNLOAD_TIMEOUT_BASE = 15min
staticconstexpr

Headers download timeout.

Timeout = base + per_header * (expected number of headers)

Definition at line 72 of file net_processing.cpp.

◆ HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER

constexpr auto HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER = 1ms
staticconstexpr

Definition at line 73 of file net_processing.cpp.

◆ HEADERS_RESPONSE_TIME

constexpr auto HEADERS_RESPONSE_TIME {2min}
staticconstexpr

How long to wait for a peer to respond to a getheaders request.

Definition at line 75 of file net_processing.cpp.

◆ HISTORICAL_BLOCK_AGE

constexpr int HISTORICAL_BLOCK_AGE = 7 * 24 * 60 * 60
staticconstexpr

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 99 of file net_processing.cpp.

◆ INBOUND_INVENTORY_BROADCAST_INTERVAL

constexpr auto INBOUND_INVENTORY_BROADCAST_INTERVAL {5s}
staticconstexpr

Average delay between trickled inventory transmissions for inbound peers.

Blocks and peers with NetPermissionFlags::NoBan permission bypass this.

Definition at line 247 of file net_processing.cpp.

◆ INVENTORY_BROADCAST_MAX_PER_MB

constexpr unsigned int INVENTORY_BROADCAST_MAX_PER_MB
staticconstexpr
Initial value:
=
static constexpr auto INBOUND_INVENTORY_BROADCAST_INTERVAL
Average delay between trickled inventory transmissions for inbound peers.
static constexpr unsigned int INVENTORY_BROADCAST_PER_SECOND
Maximum rate of inventory items to send per second.
constexpr int64_t count_seconds(std::chrono::seconds t)
Definition time.h:55

Maximum number of inventory items to send per transmission.

Definition at line 254 of file net_processing.cpp.

◆ INVENTORY_BROADCAST_PER_SECOND

constexpr unsigned int INVENTORY_BROADCAST_PER_SECOND = 7
staticconstexpr

Maximum rate of inventory items to send per second.

Limits the impact of low-fee transaction floods.

Definition at line 252 of file net_processing.cpp.

◆ INVENTORY_MAX_RECENT_RELAY

constexpr unsigned int INVENTORY_MAX_RECENT_RELAY = 3500
staticconstexpr

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

Definition at line 258 of file net_processing.cpp.

◆ MAX_ADDR_PROCESSING_TOKEN_BUCKET

constexpr size_t MAX_ADDR_PROCESSING_TOKEN_BUCKET {MAX_ADDR_TO_SEND}
staticconstexpr

The soft limit of the address processing token bucket (the regular MAX_ADDR_RATE_PER_SECOND based increments won't go above this, but the MAX_ADDR_TO_SEND increment following GETADDR is exempt from this limit).

Definition at line 303 of file net_processing.cpp.

◆ MAX_ADDR_RATE_PER_SECOND

constexpr double MAX_ADDR_RATE_PER_SECOND {0.1}
staticconstexpr

The maximum rate of address records we're willing to process on average.

Can be bypassed using the NetPermissionFlags::Addr permission.

Definition at line 297 of file net_processing.cpp.

◆ MAX_BLOCKS_IN_TRANSIT_PER_PEER

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 188 of file net_processing.cpp.

◆ MAX_BLOCKS_TO_ANNOUNCE

const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8
static

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

Definition at line 228 of file net_processing.cpp.

◆ MAX_BLOCKTXN_DEPTH

const int MAX_BLOCKTXN_DEPTH = 10
static

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

Definition at line 206 of file net_processing.cpp.

◆ MAX_CMPCTBLOCK_DEPTH

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 201 of file net_processing.cpp.

◆ MAX_FEEFILTER_CHANGE_DELAY

constexpr auto MAX_FEEFILTER_CHANGE_DELAY {5min}
staticconstexpr

Maximum feefilter broadcast delay after significant change.

Definition at line 277 of file net_processing.cpp.

◆ MAX_GETCFHEADERS_SIZE

constexpr uint32_t MAX_GETCFHEADERS_SIZE = 2000
staticconstexpr

Maximum number of cf hashes that may be requested with one getcfheaders.

See BIP 157.

Definition at line 287 of file net_processing.cpp.

◆ MAX_GETCFILTERS_SIZE

constexpr uint32_t MAX_GETCFILTERS_SIZE = 1000
staticconstexpr

Maximum number of compact filters that may be requested with one getcfilters.

See BIP 157.

Definition at line 282 of file net_processing.cpp.

◆ MAX_GETDATA_SZ

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 184 of file net_processing.cpp.

◆ MAX_INV_SZ

const unsigned int MAX_INV_SZ = 50000
static

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

Definition at line 107 of file net_processing.cpp.

◆ MAX_LOCATOR_SZ

const unsigned int MAX_LOCATOR_SZ = 101
static

The maximum number of entries in a locator.

Definition at line 105 of file net_processing.cpp.

◆ MAX_NUM_UNCONNECTING_HEADERS_MSGS

const int MAX_NUM_UNCONNECTING_HEADERS_MSGS = 10
static

Maximum number of unconnecting headers announcements before DoS score.

Definition at line 230 of file net_processing.cpp.

◆ MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT

constexpr int32_t MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT = 4
staticconstexpr

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

Definition at line 80 of file net_processing.cpp.

◆ MAX_PCT_ADDR_TO_SEND

constexpr size_t MAX_PCT_ADDR_TO_SEND = 23
staticconstexpr

the maximum percentage of addresses from our addrman to return in response to a getaddr message.

Definition at line 292 of file net_processing.cpp.

◆ MINIMUM_CONNECT_TIME

constexpr auto MINIMUM_CONNECT_TIME {30s}
staticconstexpr

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

Definition at line 91 of file net_processing.cpp.

◆ NODE_NETWORK_LIMITED_MIN_BLOCKS

const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288
static

Minimum blocks required to signal NODE_NETWORK_LIMITED.

Definition at line 232 of file net_processing.cpp.

◆ PING_INTERVAL

constexpr auto PING_INTERVAL {2min}
staticconstexpr

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

Definition at line 103 of file net_processing.cpp.

◆ PROOF_REQUEST_PARAMS

constexpr DataRequestParameters PROOF_REQUEST_PARAMS
staticconstexpr
Initial value:
{
100,
5000,
std::chrono::seconds(2),
std::chrono::seconds(2),
std::chrono::seconds(60),
}

Definition at line 170 of file net_processing.cpp.

◆ RANDOMIZER_ID_ADDRESS_RELAY

constexpr uint64_t RANDOMIZER_ID_ADDRESS_RELAY = 0x3cac0035b5866b90ULL
staticconstexpr

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

Definition at line 93 of file net_processing.cpp.

◆ RELAY_TX_CACHE_TIME

constexpr auto RELAY_TX_CACHE_TIME = 15min
staticconstexpr

How long to cache transactions in mapRelay for normal relay.

Definition at line 62 of file net_processing.cpp.

◆ ROTATE_ADDR_RELAY_DEST_INTERVAL

constexpr auto ROTATE_ADDR_RELAY_DEST_INTERVAL {24h}
staticconstexpr

Delay between rotating the peers we relay a particular address to.

Definition at line 242 of file net_processing.cpp.

◆ STALE_CHECK_INTERVAL

constexpr auto STALE_CHECK_INTERVAL {10min}
staticconstexpr

How frequently to check for stale tips.

Definition at line 84 of file net_processing.cpp.

◆ STALE_RELAY_AGE_LIMIT

constexpr int STALE_RELAY_AGE_LIMIT = 30 * 24 * 60 * 60
staticconstexpr

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 96 of file net_processing.cpp.

◆ TX_REQUEST_PARAMS

constexpr DataRequestParameters TX_REQUEST_PARAMS
staticconstexpr
Initial value:
{
100,
5000,
std::chrono::seconds(2),
std::chrono::seconds(2),
std::chrono::seconds(60),
}

Definition at line 161 of file net_processing.cpp.

◆ UNCONDITIONAL_RELAY_DELAY

constexpr auto UNCONDITIONAL_RELAY_DELAY = 2min
staticconstexpr

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

Definition at line 67 of file net_processing.cpp.