Skip to content

Commit

Permalink
net_processing: Move comments to declarations
Browse files Browse the repository at this point in the history
Summary:
This is a backport of [[bitcoin/bitcoin#21525 | core#21525]]
bitcoin/bitcoin@1dd8ed7

Test Plan: NA. Only comments moved and blank lines deleted

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11506
  • Loading branch information
PiRK committed May 23, 2022
1 parent eb05628 commit a75ac0b
Showing 1 changed file with 65 additions and 60 deletions.
125 changes: 65 additions & 60 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,12 +826,25 @@ class PeerManagerImpl final : public PeerManager {
/** Offset into vExtraTxnForCompact to insert the next tx */
size_t vExtraTxnForCompactIt GUARDED_BY(g_cs_orphans) = 0;

/**
* Check whether the last unknown block a peer advertised is not yet known.
*/
void ProcessBlockAvailability(NodeId nodeid)
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
/**
* Update tracking information about which blocks a peer is assumed to have.
*/
void UpdateBlockAvailability(NodeId nodeid, const BlockHash &hash)
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
bool CanDirectFetch(const Consensus::Params &consensusParams)
EXCLUSIVE_LOCKS_REQUIRED(cs_main);

/**
* To prevent fingerprinting attacks, only send blocks/headers outside of
* the active chain if they are no more than a month older (both in time,
* and in best equivalent proof of work) than the best header chain we know
* about and we fully-validated them at some point.
*/
bool BlockRequestAllowed(const CBlockIndex *pindex,
const Consensus::Params &consensusParams)
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
Expand All @@ -840,17 +853,69 @@ class PeerManagerImpl final : public PeerManager {
bool AlreadyHaveProof(const avalanche::ProofId &proofid);
void ProcessGetBlockData(const Config &config, CNode &pfrom, Peer &peer,
const CInv &inv, CConnman &connman);

/**
* Validation logic for compact filters request handling.
*
* May disconnect from the peer in the case of a bad request.
*
* @param[in] peer The peer that we received the request from
* @param[in] chain_params Chain parameters
* @param[in] filter_type The filter type the request is for. Must be
* basic filters.
* @param[in] start_height The start height for the request
* @param[in] stop_hash The stop_hash for the request
* @param[in] max_height_diff The maximum number of items permitted to
* request, as specified in BIP 157
* @param[out] stop_index The CBlockIndex for the stop_hash block, if
* the request can be serviced.
* @param[out] filter_index The filter index, if the request can be
* serviced.
* @return True if the request can be serviced.
*/
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);

/**
* Handle a cfilters request.
*
* May disconnect from the peer in the case of a bad request.
*
* @param[in] peer The peer that we received the request from
* @param[in] vRecv The raw message received
* @param[in] chain_params Chain parameters
* @param[in] connman Pointer to the connection manager
*/
void ProcessGetCFilters(CNode &peer, CDataStream &vRecv,
const CChainParams &chain_params,
CConnman &connman);
/**
* Handle a cfheaders request.
*
* May disconnect from the peer in the case of a bad request.
*
* @param[in] peer The peer that we received the request from
* @param[in] vRecv The raw message received
* @param[in] chain_params Chain parameters
* @param[in] connman Pointer to the connection manager
*/
void ProcessGetCFHeaders(CNode &peer, CDataStream &vRecv,
const CChainParams &chain_params,
CConnman &connman);

/**
* Handle a getcfcheckpt request.
*
* May disconnect from the peer in the case of a bad request.
*
* @param[in] peer The peer that we received the request from
* @param[in] vRecv The raw message received
* @param[in] chain_params Chain parameters
* @param[in] connman Pointer to the connection manager
*/
void ProcessGetCFCheckPt(CNode &peer, CDataStream &vRecv,
const CChainParams &chain_params,
CConnman &connman);
Expand Down Expand Up @@ -1254,7 +1319,6 @@ static bool PeerHasHeader(CNodeState *state, const CBlockIndex *pindex)
return false;
}

/** Check whether the last unknown block a peer advertised is not yet known. */
void PeerManagerImpl::ProcessBlockAvailability(NodeId nodeid) {
CNodeState *state = State(nodeid);
assert(state != nullptr);
Expand All @@ -1272,7 +1336,6 @@ void PeerManagerImpl::ProcessBlockAvailability(NodeId nodeid) {
}
}

/** Update tracking information about which blocks a peer is assumed to have. */
void PeerManagerImpl::UpdateBlockAvailability(NodeId nodeid,
const BlockHash &hash) {
CNodeState *state = State(nodeid);
Expand Down Expand Up @@ -1905,15 +1968,6 @@ bool PeerManagerImpl::MaybePunishNodeForTx(NodeId nodeid,
return false;
}

//////////////////////////////////////////////////////////////////////////////
//
// blockchain -> download logic notification
//

// To prevent fingerprinting attacks, only send blocks/headers outside of the
// active chain if they are no more than a month older (both in time, and in
// best equivalent proof of work) than the best header chain we know about and
// we fully-validated them at some point.
bool PeerManagerImpl::BlockRequestAllowed(
const CBlockIndex *pindex, const Consensus::Params &consensusParams) {
AssertLockHeld(cs_main);
Expand Down Expand Up @@ -3001,25 +3055,6 @@ void PeerManagerImpl::ProcessOrphanTx(const Config &config,
m_mempool.check(m_chainman.ActiveChainstate());
}

/**
* Validation logic for compact filters request handling.
*
* May disconnect from the peer in the case of a bad request.
*
* @param[in] peer The peer that we received the request from
* @param[in] chain_params Chain parameters
* @param[in] filter_type The filter type the request is for. Must be
* basic filters.
* @param[in] start_height The start height for the request
* @param[in] stop_hash The stop_hash for the request
* @param[in] max_height_diff The maximum number of items permitted to
* request, as specified in BIP 157
* @param[out] stop_index The CBlockIndex for the stop_hash block, if the
* request can be serviced.
* @param[out] filter_index The filter index, if the request can be
* serviced.
* @return True if the request can be serviced.
*/
bool PeerManagerImpl::PrepareBlockFilterRequest(
CNode &peer, const CChainParams &chain_params, BlockFilterType filter_type,
uint32_t start_height, const BlockHash &stop_hash, uint32_t max_height_diff,
Expand Down Expand Up @@ -3079,16 +3114,6 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(
return true;
}

/**
* Handle a cfilters request.
*
* May disconnect from the peer in the case of a bad request.
*
* @param[in] peer The peer that we received the request from
* @param[in] vRecv The raw message received
* @param[in] chain_params Chain parameters
* @param[in] connman Pointer to the connection manager
*/
void PeerManagerImpl::ProcessGetCFilters(CNode &peer, CDataStream &vRecv,
const CChainParams &chain_params,
CConnman &connman) {
Expand Down Expand Up @@ -3126,16 +3151,6 @@ void PeerManagerImpl::ProcessGetCFilters(CNode &peer, CDataStream &vRecv,
}
}

/**
* Handle a cfheaders request.
*
* May disconnect from the peer in the case of a bad request.
*
* @param[in] peer The peer that we received the request from
* @param[in] vRecv The raw message received
* @param[in] chain_params Chain parameters
* @param[in] connman Pointer to the connection manager
*/
void PeerManagerImpl::ProcessGetCFHeaders(CNode &peer, CDataStream &vRecv,
const CChainParams &chain_params,
CConnman &connman) {
Expand Down Expand Up @@ -3188,16 +3203,6 @@ void PeerManagerImpl::ProcessGetCFHeaders(CNode &peer, CDataStream &vRecv,
connman.PushMessage(&peer, std::move(msg));
}

/**
* Handle a getcfcheckpt request.
*
* May disconnect from the peer in the case of a bad request.
*
* @param[in] peer The peer that we received the request from
* @param[in] vRecv The raw message received
* @param[in] chain_params Chain parameters
* @param[in] connman Pointer to the connection manager
*/
void PeerManagerImpl::ProcessGetCFCheckPt(CNode &peer, CDataStream &vRecv,
const CChainParams &chain_params,
CConnman &connman) {
Expand Down

0 comments on commit a75ac0b

Please sign in to comment.